2011-12-22 23 views
0

我正在使用solr通過黑道寶石在rails項目中。我想找到「Radiohead」,但不是「Radiohead的」與太陽黑子/ Solr

我正在索引刮取的數據。

我的索引目前正在做像這樣:

searchable do 
    text :title, :boost => 3.0 do 
    title.gsub(/\'s\b/, "") 
    end 
    text :mentions do 
    mentions.map do |mention| 
     mention.title.gsub(/\'s\b/, "") 
    end 
    end 
end 

目前,如果我做的:

Video.solr_search { fulltext '"Radiohead"' } 

Solr的話,將返回的結果:

Radiohead's 

Radiohead 

我想只有找到:

Radiohead 

有沒有辦法通過太陽黑子做到這一點?

回答

1

檢查您在字段類型的分析器部分爲schema.xml(in .../solr/conf目錄)。這裏有一個例子:

<fieldType name="text" class="solr.TextField" positionIncrementGap="100"> 
     <analyzer type="index"> 
      ... 
      <filter class="solr.SnowballPorterFilterFactory" language="English" /> 
     </analyzer> 
    </fieldType> 

你看到的行爲被稱爲「詞幹」 - 這是哪裏的索引值是單詞的,而不是這個詞本身。例如「飛行」,「蒼蠅」,「飛行」和「飛行」都將被索引爲「飛行」。如果有像雪球這樣的過濾器(apache的stemmer),那麼你會看到你所看到的行爲。嘗試刪除過濾器,重新啓動solr然後重新索引您的文檔。

+0

非常好,謝謝你的信息。我明天會試一試並回報。 – lightyrs 2011-12-24 20:06:36

0

你應該做一個短語查詢(使用雙引號):

Video.solr_search { fulltext '"Radiohead"' }. 

或修改您的Solr schema.xml中,這樣你就不會分裂「Radiohead的」。我不知道您的現場配置,因此我無法提供更多詳細信息...

+0

我的錯誤,這實際上是我在做什麼,這就是爲什麼我感到驚訝,它不工作。謝謝你的迴應。我將編輯該問題。 – lightyrs 2011-12-23 18:50:40