Search code examples
ruby-on-railssolrsunspotsunspot-solr

sunspot_solr stored fields


I have this line in searchable block

text :title, :stored => true

Am searching book title via sunspot solr. But do I really have to use stored field ?

:stored => true

as per documentation

Stored fields allow data to be retrieved without also hitting the underlying database (usually an SQL server). They are also required for highlighting and more like this queries.

Stored fields come at some performance cost in the Solr index, so use them wisely.

But I don't know when should I really use these stored fields. Because I have so many fields in searchable block. Should I make all of them as stored to avoid hitting db ? and what will be the performance cost ?


Solution

  • Sunspot maintainer here.

    So long as you are using Sunspot to load ActiveRecord objects, then storing field values is recommended only for use with Solr features which require them, such as highlighting.

    If you are rendering hits from a Sunspot search response, and not loading the results, then you will want to store the field values which you are rendering in your views. But for reasons I've mentioned elsewhere, you should probably have a clear reason for bypassing ActiveRecord in that way.