solr sunspot - searching belongs_to association

你离开我真会死。 提交于 2019-11-28 12:35:31

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

In case some association can be nil, do not forget to test for that otherwise you will get error while rebuilding index

text :collection do 
  collection.name if collection
end

It looks like you haven't reindexed data after model update.

Run this command to reindex:

bundle exec rake sunspot:solr:reindex
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!