solr太阳黑子 - 搜索belongs_to协会 [英] solr sunspot - searching belongs_to association
问题描述
class Fabric< p> ActiveRecord :: Base
validates:name,presence:true
belongs_to:design
belongs_to:composition
belongs_to:collection
belongs_to:style
belongs_to:origin
belongs_to:纹理
belongs_to:供应商
has_and_belongs_to_many:颜色
可搜索的
文本:名称,:boost => 5
文本:描述
文本:合成做
合成。名称
结束
文本:集合做
集合。名称
结束
text:style do
style.name
end
text:origin do
origin.name
end
text:texture do
texture.name
end
text:供应商do
供应商名称
结束
结束
结束
我已经设置了所有的反向关联(Has_many)等
但是我似乎无法获得全文搜索来查询所有这些关联表的名称字段。
任何帮助将不胜感激。
@search = Fabric.search do
fulltext params [:search]
end
@fabrics = @ search.results
Ross
全文来指定您的哪些字段想要搜索。
@search = Fabric.search do
fulltext params [:search]做
字段(:collection ,:style,:origin)
end
.....
end
以下是您在可搜索区块中编制索引的方法。 Solr根据文件考虑。
可搜索的
文本:集合
集合.text
end
end
然后重新索引。
查看更多详情 https://github.com/太阳黑子/太阳黑子#全文
https://github.com/sunspot/sunspot#setting-up-objects
I have a fabrics model that belongs to multiple other tables.
class Fabric < ActiveRecord::Base
validates :name, presence: true
belongs_to :design
belongs_to :composition
belongs_to :collection
belongs_to :style
belongs_to :origin
belongs_to :texture
belongs_to :supplier
has_and_belongs_to_many :colours
searchable do
text :name, :boost => 5
text :description
text :composition do
composition.name
end
text :collection do
collection.name
end
text :style do
style.name
end
text :origin do
origin.name
end
text :texture do
texture.name
end
text :supplier do
supplier.name
end
end
end
I have setup all of the reverse associations (Has_many) etc. However I do not seem to be able to get the fulltext search to query the name fields of all of these associated tables.
Any help would be greatly appreciated.
@search = Fabric.search do
fulltext params[:search]
end
@fabrics = @search.results
Ross
You need to pass block inside your fulltext to specify which fields you want to search on.
@search = Fabric.search do
fulltext params[:search] do
fields(:collection, :style, :origin)
end
.....
end
Here is how you index in your searchable block. Solr thinks in terms of document. It doesn't care it's an association or not.
searchable do
text :collection do
collection.text
end
end
Then reindex.
Check this out for more detail https://github.com/sunspot/sunspot#full-text
https://github.com/sunspot/sunspot#setting-up-objects
这篇关于solr太阳黑子 - 搜索belongs_to协会的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!