使用solr从pdf、office文档中建立索引和从数据库中建立相似,只不过这里需要tika来解析这些文档。8.1 配置一个handler
这个handler首先要在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>
这里和7.1几乎一样,只不过修改了配置文件名(当然也可以不修改)。
8.2 文档配置tika-data-config.xml
<dataConfig>
<dataSource type="BinFileDataSource" />
<document>
<entity name="files" dataSource="binary" rootEntity="false"
processor="FileListEntityProcessor"
baseDir="D:/temp" fileName=".*.(doc)|(pdf)|(xls)|(ppt)|(docx)"
recursive="true">
<field column="fileAbsolutePath" name="id" />
<field column="fileSize" name="size" />
<field column="fileLastModified" name="lastModified" />
<entity
name="documentImport"
processor="TikaEntityProcessor"
url="${files.fileAbsolutePath}"
format="text">
<field column="file" name="fileName"/>
<field column="Author" name="author" meta="true"/>
<field column="title" name="title" meta="true"/>
<field column="text" name="text"/>
</entity>
</entity>
</document>
</dataConfig>
这里只说上面(7.2)没有说过的属性。
· fileName :(必选)使用正则表达式匹配文件
· baseDir : (必选) 文件目录
· recursive : 是否递归的获取文件,默认false
· rootEntity :在这里必须是false(除非你只想索引文件名)。在默认情况下,document元素下就是根实体了,如果没有根实体的话,直接在实体下面的实体将会被看做跟实体。对于根实体对应的数据库中返回的数据的每一行,solr都将生成一个document
· dataSource :如果你是用solr1.3,那就必须设为"null",因为它没使用任何dataSourde。不需要在solr1.4中指定它,它只是意味着我们不创建一个dataSource实例。在大多数情况下,只有一个DataSource(JdbcDataSource),当使用FileListEntityProcessor 的时候DataSource不是必须的
· processor:只有当datasource不是RDBMS时才是必须的
· onError :默认是"abort","skip"表示跳过当前文档,"continue"表示对错误视而不见
更多精彩内容请关注:http://bbs.superwu.cn
相关资源:七夕情人节表白HTML源码(两款)