1. 程式人生 > >Solr IK 分詞查不到結果問題

Solr IK 分詞查不到結果問題

 前天在伺服器上搭建一主一從的solr4.6的伺服器,建core的時候,拋棄了以前從solr4.6下載包裡面的配置檔案。而是上這個資料夾拿配置檔案:F:\solr\solr-4.6.0\example\multicore\core0\conf。這個資料夾給的配置檔案是最簡單的!只需一個schema.xml和solrconfig.xml就可以迅速搭建一個core出來。

    搭建好之後,基本的CRUD操作都可以。但是搜尋卻只能全字匹配或者只能單個字元匹配出結果。這是絕對不能容忍的。定位問題接近了一天,找有經驗的同事給排查也沒排查出來問題。最後我自己一點一點比對multicore資料夾下的配置檔案跟F:\solr\solr-4.6.0\example\solr\collection1這個資料夾下的配置檔案的配置區別。

    當我把schema.xml的version屬性從1.1升到跟collection1下的相同檔案的1.5一致之後。重啟伺服器,問題解決了!

    我只想想說,提供solr4.6包的工程師坑爹。schema.xml的version屬性對搜尋的效果影響重大,4.6下的multicore提供的版本號卻是古老的1.1.

    查了下schema.xml的官方文件:http://wiki.apache.org/solr/SchemaXml

[plain]  view plain
 copy
  1. <schema name="example" version="1.5">  
  2. 49    <!-- attribute "name" is the name of this schema and is only used for display purposes.  
  3. 50         version="x.y" is Solr's version number for the schema syntax and   
  4. 51         semantics.  It should not normally be changed by applications.  
  5. 52    
  6. 53         1.0: multiValued attribute did not exist, all fields are multiValued   
  7. 54              by nature  
  8. 55         1.1: multiValued attribute introduced, false by default   
  9. 56         1.2: omitTermFreqAndPositions attribute introduced, true by default   
  10. 57              except for text fields.  
  11. 58         1.3: removed optional field compress feature  
  12. 59         1.4: autoGeneratePhraseQueries attribute introduced to drive QueryParser  
  13. 60              behavior when a single string produces multiple tokens.  Defaults   
  14. 61              to off for version >= 1.4  
  15. 62         1.5: omitNorms defaults to true for primitive field types   
  16. 63              (int, float, boolean, string...)  
  17. 64       -->  

    翻譯一下:

    1.0:多值屬性不存在,所有的域本質上是多值屬性

    1.1:多值屬性被引進,預設為false

1.2:omitTermFreqAndPositions屬性被引進,預設為true,文字域除外

1.3:刪除可選的域壓縮特性

1.4:當單個字串產生多個詞的時候,autoGeneratePhraseQueries 屬性被引進以驅動查詢分析器行為。版本大於等於1.4預設被關閉

1.5:對於原子型別,omitNorms屬性預設為true

    從官方文件上可以看出,版本號不一樣,shema.xml被解析出來的效果也是不一樣的。