太阳黑子/ Solr全文搜索 - 如何索引Rails关联 [英] Sunspot / Solr full text search - how to index Rails associations

查看:120
本文介绍了太阳黑子/ Solr全文搜索 - 如何索引Rails关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有可能通过与太阳黑子的关联进行索引吗?例如,如果客户has_many联系人,我希望在我的Customer模型上有一个可搜索块,将联系人#名字和联系人姓氏列编入索引以用于搜索对客户。



acts_as_solr有一个:include选项。我只是简单地将相关的列名组合到客户的文本字段中,如下所示,但这看起来不太灵活。

  searchable do 
text:organization_name,:default_boost => 2
text:billing_address1,:default_boost => 2
text:contact_names do
contacts.map {| contact | contact.to_s}
end

有什么建议吗?

解决方案

这正是如何做到这一点。 Solr基本上是面向文档的,所以来自数据库中关联的任何数据都会平铺到文档中。答:包括选项只是温和的糖,最终做同样的事情,你在这里做。


Is it possible to index through an association with Sunspot?

For example, if a Customer has_many Contacts, I want a 'searchable' block on my Customer model that indexes the Contact#first_name and Contact#last_name columns for use in searches on Customer.

acts_as_solr has an :include option for this. I've simply been combining the associated column names into a text field on Customer like shown below, but this doesn't seem very flexible.

searchable do
text :organization_name, :default_boost => 2
text :billing_address1, :default_boost => 2
text :contact_names do
  contacts.map { |contact| contact.to_s }
end

Any suggestions?

解决方案

That's exactly how to do it. Solr is essentially document-oriented, so any data that comes from associations in your database is flattened down into your document. An :include option is just mild sugar which ends up doing the same thing that you do here.

这篇关于太阳黑子/ Solr全文搜索 - 如何索引Rails关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆