【问题标题】:Sphinx searcing related has_many with thinkingsphinx狮身人面像搜索相关 has_many 与 thinkingsphinx
【发布时间】:2009-07-14 19:23:22
【问题描述】:

假设,我有一个属于建筑模型的房间模型。建筑物与类别具有 has_many 关系。

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

谢谢!

【问题讨论】:

    标签: ruby-on-rails ruby sphinx thinking-sphinx


    【解决方案1】:

    首先,您需要在 Post 模型中设置如下索引:

    define_index do
      # fields go here
    
      # the important attribute for your filter:
      has building.categories(:id), :as => :category_ids
    end
    

    关于搜索:

    Room.search 'query', :with => {:category_ids => 1}
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多