10,606
社区成员
发帖
与我相关
我的任务
分享
package com.hoo.test;
import java.io.File;
import java.io.IOException;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.request.AbstractUpdateRequest;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest;
public class SolrExampleTests {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
String fileName = "E://我的下载区//solr4.1.doc";
String solrId = "solr.doc";
indexFilesSolrCell(fileName,solrId);
} catch(SolrServerException e){
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Method to index all types of files into Solr.
* @param fileName
* @param solrId s
* @throws IOException
* @throws SolrServerException
*/
public static void indexFilesSolrCell(String fileName, String solrId)
throws IOException, SolrServerException {
String urlString = "http://localhost:8080/solr/core1/";
SolrServer solr = new HttpSolrServer(urlString);
ContentStreamUpdateRequest up
= new ContentStreamUpdateRequest("/update/extract");
up.addFile(new File(fileName),"application/msword");//报错
up.setParam("literal.id", solrId);
up.setParam("fmap.content", "attr_content");
up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
solr.request(up);
QueryResponse rsp = solr.query(new SolrQuery("*:*"));
System.out.println(rsp);
}
}