开始此篇之前,我已经假定你已经学会了如何在Tomcat下部署Solr6.3啦。即启动Tomcat后你能看到Solr6.3的Web UI界面。不会的话可点击这里,此博客以此为基础展开,OK,下面直接进入正题
一、配置文件索引库
1、 新建core
我们新建一个solr的core,用于存储文件型索引,新建core的步骤请参考:
2、 准备jar
拷贝solr6.3发布包solr-6.3.0\contrib\extraction\lib下所有jar包到apache-tomcat-8.5.8\webapps\solr\WEB-INF\lib文件夹下。
3、新建tika-data-config.xml
<dataConfig> <script><![CDATA[ id = 1; function GenerateId(row) { row.put('id', (id ++).toFixed()); return row; } function WipOffHtml(row) { var file = row.get('file'); row.put('file',file.substr(0,file.indexOf('.'))); return row; } ]]> </script> <dataSource type="BinFileDataSource" /> <document> <entity name="files" dataSource="binary" rootEntity="false" processor="FileListEntityProcessor" baseDir="文件所在路径" fileName=".*.(doc)|(pdf)|(xls)|(ppt)|(docx)" recursive="true"> <field column="fileAbsolutePath" name="filePath" /> <field column="fileSize" name="size" /> <field column="fileLastModified" name="lastModified" /> <entity name="documentImport" processor="TikaEntityProcessor" url="${files.fileAbsolutePath}" format="text" transformer="HTMLStripTransformer,RegexTransformer,script:GenerateId"> <field column="file" name="fileName"/> <field column="id" name="id" /> <field column="Author" name="author" meta="true"/> <field column="title" name="title" meta="true"/> <field column="text" name="text" stripHTML="true" regex="\t|\r|\n|\s" replaceWith="" /> </entity> </entity> </document> </dataConfig>
4、配置solrconfig.xml
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler"> <lst name="defaults"> <str name="config">tika-data-config.xml</str> </lst> </requestHandler>
5、配置managed-schema
<field name="fileName" type="string" indexed="true" stored="true"/> <field name="filePath" type="string" indexed="true" stored="true"/> <field name="author" type="string" indexed="true" stored="true"/> <field name="title" type="string" indexed="true" stored="true"/> <field name="text" type="text_ik" indexed="true" stored="true"/>
注意:没有配置分词器的可参考这里
6、启动tomcat,输入localhost:8080/solr/index.html,配置索引库
7、进行索引操作
8、测试查询