2011-12-22 47 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