Ruby on rails 太阳黑子搜索属于联想
我有一个属于多个其他表的结构模型Ruby on rails 太阳黑子搜索属于联想,ruby-on-rails,ruby-on-rails-3,solr,full-text-search,sunspot,Ruby On Rails,Ruby On Rails 3,Solr,Full Text Search,Sunspot,我有一个属于多个其他表的结构模型 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 ha
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
Ross看起来您在模型更新后没有重新编制数据索引 运行此命令以重新索引:
bundle exec rake sunspot:solr:reindex
您需要在全文中传递block,以指定要搜索的字段
@search = Fabric.search do
fulltext params[:search] do
fields(:collection, :style, :origin)
end
.....
end
以下是如何在可搜索块中建立索引。索尔从文件的角度思考。它不在乎是否有关联
searchable do
text :collection do
collection.text
end
end
然后重新编制索引
查看此项了解更多详细信息
如果某些关联可能为零,请不要忘记进行测试,否则在重建索引时会出现错误
text :collection do
collection.name if collection
end
你能显示你的搜索栏吗?您也需要重新编制索引。这就是您要查找的内容吗,非常感谢。如果每个相关联的表:collection、:style等都有一个文本列:name,那么此方法是否针对这些列进行搜索?
text :collection do
collection.name if collection
end