首页 > 技术文章 > 搜索引擎Solr6.2.1 索引富文本(word/pdf/txt/html)

sunyj 2017-04-19 14:45 原文

一:首先建立Core

在core下面新建lib文件夹,存放相关的jar包,如图所示:

lib文件夹打开所示,这些类库在solr6.2.1解压之后都能找到:

修改solrconfig.xml,把刚刚建的lib文件夹下的jar包引入

增加配置,如果有则不用添加:

配置managed-schema文件:

 

 

二:Java代码solrj操作(6.2.1版本) 

 

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 class Test {

    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);  
    }  
       
}

 

推荐阅读