狮身人面像的搜索与thinkingsphinx有关

0 ruby sphinx ruby-on-rails thinking-sphinx

假设我有一个属于建筑模型的房间模型.建筑与类别有很多关系.

我正在试图找出如何索引Room模型,以便搜索category_id = 1将返回任何房间,在任何恰好分配了该类别的建筑物中.同样,建筑物可以有多个类别.

谢谢!

pat*_*pat 6

首先,您需要在Post模型中设置类似以下内容的索引:

define_index do
  # fields go here

  # the important attribute for your filter:
  has building.categories(:id), :as => :category_ids
end
Run Code Online (Sandbox Code Playgroud)

至于搜索:

Room.search 'query', :with => {:category_ids => 1}
Run Code Online (Sandbox Code Playgroud)

如果这不是你想要的,请告诉我.