This should be simple but I can’t get it to work.
I would like to retrieve all products which are published.
The following code is working, and only published products are returned:
@products = Product.search do
with(:published, true)
with(:facet_tag).all_of(facets) unless facets.nil?
fulltext q do
end
facet :facet_tag
paginate :page => 1, :per_page => 8
end
When I remove the full text part it doesn’t return any results at all.
I would like the following code to return all published products, but the code returns no results at all. @products.results becomes nil.
@products = Product.search do
with(:published, true)
with(:facet_tag).all_of(facets) unless facets.nil?
facet :facet_tag
paginate :page => 1, :per_page => 8
end
How should I get all published products from sunspot?
The presented code in the question is working. The problem arose from changes which I done to the solrconfig file. I had added a requestHandler which I called edismax. I was assuming that sunspot was using it since was set to be the default request handler and that full-text search was working.
Sunspot is instead expecting a request handler which is called dismax and becasue no such request handler was configured it failed to retrieve all document since Solr didn’t understand the : search query.
Actually this should not be a problem at all since Sunspot aims to be a complete abstraction of Solr and no changes to the solr config files should be needed. Sunspot is not there yet when it comes to a bit more advanced usage of Solr so changes is often needed. Luckly it’s possible to change the solr parameters with the adjust_solr_params function.
I solve the problem by changing the code to:
This way I’m asking solr to used the edsimax query parser instead of the dismax query parser.