百度、google幫咱們找Internet的信息,但對於一個行業內部網(intranet)來講,百度、google就沒法幫忙了。而且,對一個行業來講,更多的信息都是放在行業內部網上,而且採用網頁、office文檔、圖片、視頻、音頻等格式存放。如何方便,快捷,安全地獲取行業內部的信息內容,創建一個行業內部網的搜索引擎就顯得尤其重要。html
佛山起點軟件(http://www.rivues.com)推出了起點R3軟件,是一個開箱即用的企業級搜索引擎產品,而且已開源,下載地址http://sourceforge.net/projects/rivues/files/,最新版本是5.3,安裝後,試了一下,很是不錯,很快能夠建一個桌面搜索(對本地文件建一個搜索引擎),但沒有看到對網站內容採集界面。vue
nutch是apache項目的一個開源軟件,最新版本是1.3,是一個強大的網頁、索引工具,1.3版本好像只對solr創建索引,去掉了lucene索引(bin/nutch index 命令不能使用)。solr也是apache項目的一個開源軟件,主要是基於lucene的一個索引工具,但搜索結果返回的是xml、json等格式,須要用戶開發html展現模塊。java
其實,起點R3軟件也是基於solr創建的索引,有很是完善展現界面。筆者經過對起點R3源碼進行分析後,實現了用nutch來採集網站信息,用起點R3來實現創建索引,並提供用戶搜索界面。先將其過程寫出來,供你們參考。數據庫
1、起點R3軟件的安裝與配置apache
1.從http://sourceforge.net/projects/rivues/files/下載起點R3 5.3版本qidian_r3_fulltext_search_5.3_without_jdk.zip,並展開到一個目錄,如d:\r3目錄。json
2.若是沒有沒有jdk1.6,從http://www.java.net/download/jdk6/6u10/promoted/b32/binaries/jdk-6u10-rc2-bin-b32-windows-i586-p-12_sep_2008.exe下載jdk1.6版本 ,安裝後,並在windows的path環境變量中加上jdk的bin路徑。windows
3.打開d:\r3\bin文件夾,點擊startup.bat啓動r3。在瀏覽器中鍵入http://127.0.0.1:880/,若能打開r3搜索頁面,說明R3安裝與配置成功。瀏覽器
2、在R3中添加nutch對應的索引字段緩存
要把nutch採集的網頁信息索引到起點R3的索引文件中,必須知道nutch用index對應的索引字段,而且要在起點R3的索引結構中加入對應的索引字段。安全
1.從http://www.apache.org/dist//nutch/apache-nutch-1.3-bin.zip下載nutch-1.3,展開該文件後,打開conf目錄下的schema.xml文件。其中涉及fields內容以下:
<fields> <field name="id" type="string" stored="true" indexed="true"/> <!-- core fields --> <field name="segment" type="string" stored="true" indexed="false"/> <field name="digest" type="string" stored="true" indexed="false"/> <field name="boost" type="float" stored="true" indexed="false"/> <!-- fields for index-basic plugin --> <field name="host" type="url" stored="false" indexed="true"/> <field name="site" type="string" stored="false" indexed="true"/> <field name="url" type="url" stored="true" indexed="true" required="true"/> <field name="content" type="text" stored="false" indexed="true"/> <field name="title" type="text" stored="true" indexed="true"/> <field name="cache" type="string" stored="true" indexed="false"/> <field name="tstamp" type="long" stored="true" indexed="false"/> <!-- fields for index-anchor plugin --> <field name="anchor" type="string" stored="true" indexed="true" multiValued="true"/> <!-- fields for index-more plugin --> <field name="type" type="string" stored="true" indexed="true" multiValued="true"/> <field name="contentLength" type="long" stored="true" indexed="false"/> <field name="lastModified" type="long" stored="true" indexed="false"/> <field name="date" type="string" stored="true" indexed="true"/> <!-- fields for languageidentifier plugin --> <field name="lang" type="string" stored="true" indexed="true"/> <!-- fields for subcollection plugin --> <field name="subcollection" type="string" stored="true" indexed="true"/> <!-- fields for feed plugin --> <field name="author" type="string" stored="true" indexed="true"/> <field name="tag" type="string" stored="true" indexed="true"/> <field name="feed" type="string" stored="true" indexed="true"/> <field name="publishedDate" type="string" stored="true" indexed="true"/> <field name="updatedDate" type="string" stored="true" indexed="true"/> </fields> <uniqueKey>id</uniqueKey> <defaultSearchField>content</defaultSearchField> <solrQueryParser defaultOperator="OR"/>
其中id、segment、digest、boost爲核心字段 , host、site、url、content、title、cache、tstamp爲index-basic要用到的索引字段,anchor爲index-anchor要用到的索引字段, type、contentLength、lastModified、date爲index-more要用到的索引字段。因此必須在R3中的創建對應的字段。
分析R3源碼發現,R3內置了solr,但對索引字段像solr那樣不是存放在conf的schema.xml文件中,估計是爲了用戶管理索引字段方便,將索引字段定義的結果存放在一個derby的數據庫中,derby也是apache項目的開源軟件。
進入http://127.0.0.1:880/的界面後,點擊login,用admin用戶登錄,點擊「索引字段」圖標,進入索引字段管理界面,在索引字段中加入下表中的 6-19字段。
序號 中文別稱 名稱 數據類型 存儲 索引 多值 統計字段 排序字段 複製到字段 1 標題 title text true true true true true 2 內容 text text true true true false false 3 附件數 files tint true true true false true 4 文檔類型 contentType string true true true true false 5 文件目錄 parent string false true true true false 6 內容 content text true true true true true text 7 標識 url text true true true false true parent 8 主機名 host string true true false false true 9 緩存 cache string true true true false false 10 郵戳 tstamp tdate true true false false false 11 錨 anchor text true true true false true 12 內容長 contentLength string true true false false false 13 時間 lastModified tdate true true false false true 14 站點 site string true true false false false 15 段 segment string true true false false false 16 digest digest string true true false false false 17 boost boost float true true false false true 18 類型 type string true true true true false 19 日期 date tdate true true false false false
其中將content、url分別設置複製爲text、parent字段。須要注意的是添加索引字段數據類型、多值屬性不能錯,如anchor、type的多值屬性爲true,若是定義錯了,在從nutch中索引到R3時會不成功。
(未完待續)