PS: 本文假設你已經成功的搭建了一個Solr服務器
步驟如下:
(1)准備好一份Solr的源碼,假設現在保存在c:\apache-solr-1.4.1\目錄下
(2)從https://issues.apache.org/jira/browse/SOLR-284 上下載最新的rich.patch, libs.zip和test-files.zip三個文件
(3)解壓libs.zip到c:\apache-solr-1.4.1\lib目錄下,里面的jar就是負責分析Pdf、word和excel的
(4)新建一個文件patch-build.xml,內容如下:
- <?xml version="1.0" encoding="UTF-8"?>
- <project name="solr-patch" default="apply-patch" basedir=".">
- <target name="apply-patch" description="Apply a patch file. Set - Dpatch.file">
- <patch patchfile="${patch.file}" strip="0" />
- </target>
- </project>
(5) 將rich.patch復制到c:\apache-solr-1.4.1\目錄下,運行ant -Dpatch.file=rich.patch -f patch-build.xml 給solr打補丁,注意這里需要ant和Cygwin兩個運行環境!
(6)執行ant dist 重新編譯Solr包,編譯好的文件在dist目錄下將它復制到tomcat里面
(7)打開solrconfig.xml,添加如下內容:
- <requestHandler name="/update/rich" class="solr.RichDocumentRequestHandler" startup="lazy">
- </requestHandler>
然后將
- <requestParsers enableRemoteStreaming="false" multipartUploadLimitInKB="2048" />
的enableRemoteStreaming屬性設為true
(8)解壓test-files.zip 到任意目錄,假設現在是在c:\apache-solr-1.4.1\test\ 目錄下
(9)啟動SOLR,在瀏覽器輸入:
http://localhost:8983/solr/update/rich?stream.type=doc&stream.file=c:/apache-solr-1.4.1/test/test-files/complex.doc&fieldnames=id&id=101&stream.fieldname=name&commit=true
為complex.doc 文件建立索引
(10) 打開http://localhost:8983/solr/admin/form.jsp 頁輸入關鍵字測試索引,完成!

