使用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>
</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"表示對錯誤視而不見