package com.gotop.solrproj.importdata;
import java.io.File;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrRequest.METHOD;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.request.AbstractUpdateRequest;
import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest;
public class TikaDefault {
public static void main(String[] args) throws Exception {
String zkHost = "192.168.137.200:2181,192.168.137.201:2181";
SolrClient server = new CloudSolrClient(zkHost);
addDocs(server);
server.close();
}
public static void addDocs(SolrClient server) throws Exception {
ContentStreamUpdateRequest req = new ContentStreamUpdateRequest("/update/extract");
req.setMethod(METHOD.POST);
File file = new File("D:/java文档/Javaweb项目开发手册.docx");
req.addFile(file, "application/msword");
req.setParam("literal.id", "00007");
req.setParam("literal.stream_size", String.valueOf(file.length()));
req.setAction(AbstractUpdateRequest.ACTION.COMMIT, false, false);
server.request(req,"mycollection");
}
}