0

我的模型与Thinking Sphinx一起编入索引,我希望通过模型标签过滤搜索结果 - 由acts_as_taggable_on提供。我读this previous question,这使我的搜索使用:conditions => { :tags => 'Comedy' }作为过滤查询。Acts_as_taggable_on标签名称为Thinking Sphinx属性

这不是一个全面的解决方案,因为默认情况下所有文本都在Sphinx的索引字段中搜索。例如,当我搜索Model.search :conditions => { :tags => "Comedy" }时,标签Black Comedy的结果也会出现。我看到使用属性,而不是字段是一个解决方案,但我似乎无法得到有效的结果搜索Model.search :with => { :tags => "Comedy" }和我define_index块看起来像这样的时候:

define_index 
    indexes title, :sortable => true 
    has category_tags(:name), :as => :tags 
end 

注意,我在所提供的以前的答案建设上面链接的问题。回答者详细描述了上下文中的标签索引 - 因此是category_tags方法的原因。

回答

3

索引更改为:

define_index 
    indexes title, :sortable => true 
    has "CRC32(category_tags.name)", :as => :tags, :type => integer 
end 

注:category_tags.name指转换成int后your_table_name.column_name

和搜索标签:

Model.search :with => {:tags =>'Comedy'.to_crc32} 

参见常见问题更多:http://freelancing-god.github.com/ts/en/common_issues.html

相关问题