使用solr检索word文档
来源:互联网 发布:怎么编写java程序 编辑:程序博客网 时间:2024/06/08 18:34
环境:
1.tomcat8.5
2.jdk1.8.0_131
3.solr5.5.4
一、中文分词安装
1.下载中文分词器的jar包放入\Tomcat 8.5\webapps\solr\WEB-INF\lib中
jar包下载地址:https://pan.baidu.com/s/1mhThgSS
2.打开\solr_home\core1\conf\managed-schema.xml顺便改名为schema.xml,再在最后追加
<fieldType name="text_ik" class="solr.TextField">
<analyzer type="index" useSmart="false"
class="org.wltea.analyzer.lucene.IKAnalyzer" />
<analyzer type="query" useSmart="true"
class="org.wltea.analyzer.lucene.IKAnalyzer" />
</fieldType>
3.启动tomcat测试中文分词器是否安装成功
二、配置solr的ExtractingRequestHandler
4.将\solr-5.5.4\solr-5.5.4\contrib\extraction下的jar包复制到\solr_home\core1\lib(目录不存在就新建一个)下
5.将\solr-5.5.4\solr-5.5.4\dist下的solr-cell-5.5.4.jar复制到\solr_home\core1\lib下
6.在\solr_home\core1\conf\solrconfig.xml添加
<lib dir="./lib" regex=".*\.jar" />
<requestHandler name="/update/extract" class="org.apache.solr.handler.extraction.ExtractingRequestHandler">
<lst name="defaults">
<str name="fmap.Last-Modified">last_modified</str>
<str name="uprefix">ignored_</str>
</lst>
<lst name="date.formats">
<str>yyyy-MM-dd</str>
</lst>
</requestHandler>
三、使用solrJ
1.导入相应的jar包,jar包在\solr-5.5.4\solr-5.5.4\dist\目录下可以找到
2.创建索引文件
public static void create() throws Exception {
// 链接到本地的core1核心文件
HttpSolrClient server = new HttpSolrClient(URL);
ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update/extract");
up.addFile(new File("C:/docs/7.doc"), "application/word");
up.setParam("literal.id", "doc");
up.setParam("fmap.content", "attr_content");
up.setParam("fmap.content_type", "documentFormat");
up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
server.request(up);
List list = new ArrayList<String>();
// 创建数据
//SolrInputDocument doc = new SolrInputDocument();
//doc.addField("id", "2");
//doc.addField("title", "king");
//doc.addField("author", " asdfsdfsd asdasdsaking king king king king");
//doc.addField("",new File(""));
//server.add(doc);
server.commit();
}
3.查询
public static void query() throws Exception {
HttpSolrClient server = new HttpSolrClient(URL);
// 定义查询内容 * 代表查询所有 这个是基于结果集
SolrQuery query = new SolrQuery("*"); // 定义查询内容
query.setStart(0);// 起始页
query.setRows(4);// 每页显示数量
QueryResponse rsp = server.query(query);
SolrDocumentList results = rsp.getResults();
System.out.println(results.getNumFound());// 查询总条数
for (SolrDocument doc : results) {
System.out.println(doc);
}
}
1 0
- 使用solr检索word文档
- solr为什么检索不出中文文档
- 使用solr搭建全文检索
- 使用Solr构建企业级的全文检索(四)---------写入文档
- 使用solr搭建你的全文检索
- 使用solr搭建你的全文检索
- 使用solr搭建你的全文检索
- 使用solr搭建你的全文检索
- 使用solr搭建你的全文检索
- 使用solr搭建你的全文检索
- 使用solr搭建你的全文检索
- 使用solr搭建你的全文检索
- 使用solr搭建你的全文检索
- 使用solr搭建你的全文检索
- java中solr全文检索的使用
- Solr使用:3.Solr添加文档到索引
- POI 使用word模板生成word文档
- 使用Solr构建企业级的全文检索(一)---------开篇
- xcopy -cmd命令介绍
- Linux pid_max设置及内核源码处理分析
- IOS发布——Application loader 上传报错提示(ERROR ITMS-90168)
- Python程序猿/媛如何在母亲节表达对母亲的祝福
- xampp 多端口 虚拟主机访问
- 使用solr检索word文档
- Android 5.0新UI
- SSH 远程执行任务
- mac NSCollectionView
- c++保留有效数字,小数,格式化输出
- C++和C中自定义的头文件包含问题
- (function($) {...})(jquery);这种定义方式是什么意思?
- Ajax提交HTML报错HTTP500
- 路在前方,唯有前進。