mlczhg 发表于 2017-12-20 06:09:20

搜索引擎Solr6.2.1 索引富文本(word/pdf/txt/html)

import java.io.File;  

import java.io.IOException;  

  

import org.apache.solr.client.solrj.SolrClient;  

import org.apache.solr.client.solrj.SolrQuery;  

import org.apache.solr.client.solrj.SolrServerException;  

import org.apache.solr.client.solrj.impl.HttpSolrClient;  

import org.apache.solr.client.solrj.request.AbstractUpdateRequest.ACTION;  

import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest;  

import org.apache.solr.client.solrj.response.QueryResponse;  

  

public>
  

public static void main(String[] args)  
{
  

  
String fileName
= "F:/广东先导稀材股份有限公司.docx";  
String solrId
= "广东先导稀材股份有限公司.docx";  

try  
{
  
indexFilesSolrCell(fileName, solrId);
  
}
  

catch (IOException e)  
{
  
e.printStackTrace();
  
}
  

catch (SolrServerException e)  
{
  
e.printStackTrace();
  
}
  
System.out.println(
"结束");  
}
  

public static void indexFilesSolrCell(String fileName, String solrId)  

throws IOException, SolrServerException  
{
  
SolrClient client
= new HttpSolrClient("http://localhost:8080/solr/filecore");  

//QueryResponse resp = client.query(new SolrQuery("*:*"));  

//System.out.println(resp);  
         
  
ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update/extract");
  

  
String contentType="application/word";
  
up.addFile(new File(fileName), contentType);
  
up.setParam("literal.id", solrId);
  
up.setParam("uprefix", "attr_");
  
up.setParam("fmap.content", "attr_content");
  
//up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
  
up.setAction(ACTION.COMMIT, true, true);
  
client.request(up);
  
}
  

  
}
页: [1]
查看完整版本: 搜索引擎Solr6.2.1 索引富文本(word/pdf/txt/html)