【问题标题】:how to index associated models using thinkingtank and indextank如何使用thinktank和indextank索引关联模型
【发布时间】:2011-04-10 23:21:01
【问题描述】:

我们正在使用thinktank gem,在索引模型关联时遇到了麻烦,即使是简单的关联。例如,一个个人资料属于一个机构,它有一个名字——我们想做这样的事情:

class Profile < ActiveRecord::Base

#model associations

  define_index do
    indexes institution(:name), :as => :institution_name
  end

end

但这不起作用。这一定很简单——我做错了什么?

【问题讨论】:

    标签: ruby-on-rails indexing full-text-indexing


    【解决方案1】:

    此问题的一个可能解决方案是添加一个将元素返回到索引的方法。对于 profile.institution.name 案例:

    # profile.rb
    # ...
    belongs_to :institution
    # ...
    define_index do
      indexes institution_name  
    end 
    def institution_name
      self.institution.name
    end
    # ...
    

    thinktank 也不支持 ", :as => ..." 语法。

    我也建议尝试一下 Tanker:https://github.com/kidpollo/tanker

    问候。

    阿德里安

    【讨论】:

    • 感谢您的帮助。使用虚拟属性是有效的(因为thinking_tank 文档声称镜像thinking_sphinx 仅支持通过数据库列进行搜索,所以我自己没有尝试过)。最好的建议(如您所建议的)是使用油轮。我最终同意了。该 API 似乎更强大,更干净,并且有更好的文档。绝对使用 tanker 而不是 thinking_tank。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多