Okay, I think I've figured it out. The issue here is that the facets
method was called upon @products
in the above example. Facet calls don't like the :page
and :per_page
options, as facet calls only have one page. Hence, viewing page two or more of the search results would throw an error.
A workaround (which I tested locally) is to put most of those search options in a shared method:
def common_search_options
{
order: ordering,
ranker: :bm25,
with: {
price_type_for_search => min_price_conditions..max_price_conditions,
kind_cd: @params[:kind_cd],
brand_id: [*@params[:brand_ids]],
category_ids: categories_for_search,
property_value_ids: [*params[:property_value_ids]],
}
}
end
And then create separate objects for the search results and the facet results:
@products = Product.search(query_string, common_search_options.merge({
sql: { include: :images },
page: @params[:page],
per_page: @params[:per]
}))
@product_facets = Product.facets(query_string, common_search_options)
And of course, you'll want to change any references of @products.facets to @product_facets. This will ensure that facet searches don't have the pagination options, and everything should now work smoothly.