最新项目中有个需求,需要检索上传的word文档,并给出提示,本博客使用solr+tika完成,之前solr的搭建已经详细的写过,有不清楚的参考上篇博客,在上篇的基础上需要改动如下配置文件 修改solrconfig.xml
5.5.0 ${solr.data.dir:} ${solr.hdfs.home:} ${solr.hdfs.confdir:} ${solr.hdfs.blockcache.enabled:true} ${solr.hdfs.blockcache.global:true} true managed-schema ${solr.lock.type:native} true ${solr.autoCommit.maxTime:15000} false ${solr.autoSoftCommit.maxTime:-1} 1024 true 20 200 static firstSearcher warming in solrconfig.xml false 2 tika-data-config.xml explicit 10 text explicit json true text explicit velocity browse layout edismax *:* 10 *,score on 1 text true ignored_ true links ignored_ explicit true text_general default text solr.DirectSolrSpellChecker internal 0.5 2 1 5 4 0.01 wordbreak solr.WordBreakSolrSpellChecker name true true 10 text default wordbreak on true 10 5 5 true true 10 5 spellcheck mySuggester FuzzyLookupFactory DocumentDictionaryFactory cat price string true 10 suggest text true tvComponent true false terms 100 70 0.5 [-\w ,/\n\"']{20,200} ]]> ]]> ,, ,, ,, ,, ,]]> ]]> 10 .,!? WORD en US text/plain; charset=UTF-8 ${velocity.template.base.dir:} 5 *:*
修改tika-data-config.xml如下
修改managed-schema配置
配置文件中主要用到BinFiledataSource 数据源,BinFiledataSource 用来获取文件的一些基础属性,包括文件大小 名称等,它的文档实例叫做“files”,因为不是给它做索引,所以需要设置rootEntity=”false”,实例中用到的几个属性如下:
1.fileAbsolutePath: 文档的唯一索引2.fileSize: 文档的大小3.fileLastModified: 文档的最后修改时间
接下来使用TikaEntityProcessor处理器来分析文档中的内容,并做索引,用到的几个属性如下:
1.file:文件名称,与上面写的fileAbsolutePath不同2.Autor、Title:都是文档的meta属性3.text:文档的文本内容