I'm using Drupal Commerce along with Search API and Facet API to create a search for my product dispays. Is there a way to create a facet that sorts products by price? I've tried using the exposed sort in views, but it doesn't work in unison with the facets. Any ideas? I'd prefer that the sort looks similar to the exposed sort criteria in views.

I'm using views to override a search provided by Search API. The view type is "Product display". I've added a "Search: Fulltext search" contextual filter to the view to override the search form. I'm also using Facet API to provide a faceted search to users made available using blocks on the search page. I've tried using the "SORT CRITERIA", which are available in views, to provide an option of sorting the search results by price and relevance. The problem I'm having with this is that the facets, which are provided by Facet API, don't work together with the sort criteria provided by the view.

Additional Information

If I select a sort criteria first, then apply a facet, the search results are narrowed down based on the applied facet and everything seems to work well.

If I apply the facet first, then select a sort criteria, the applied facet is reset and the search results that are shown revert back to how many there were before the facet was applied. For example, let's say that I sell 4 cars on my website, 2 red cars and 2 black cars. I search for "cars" and 4 items are shown in the results. I then apply a facet based on taxonomy terms for the color "red". There are only 2 red cars, so the search results are now only displaying 2 results. If I sort the results by "Price" the facet for the color "red" is removed. This causes the search results to revert back to the 4 items that were originally displayed for the search term "cars".

I want to be able to sort the results after a facet is applied and have the applied facet not reset itself.

1 Answer 1


Indexing the Price:

  • Go to Administration -> Configuration -> Search and metadata
  • Edit your Search Index and click on Fields tab.
  • Select Product->Price from the Add related fields drop down in bottom of form and click on Add fields button. It will add fields for Product -> price in index.
  • Enable check-box for the field Product » Price » Amount (decimal) and save the form.
  • Now, you will find Product » Price » Amount (decimal) (Min) and Product » Price » Amount (decimal) (Max) field in your list. Enable these fields and save the form.
  • Reindex your search.

    Adding sorting in views:

  • Go to Administration -> Structure -> Views
  • Edit your view.
  • Add field Indexed Node: Product » Price » Amount (decimal) (Max) or Indexed Node: Product » Price » Amount (decimal) (Min) to sort view and save the view.
  • This method doesn't really work with facets. If I select a facet option on the search results page and then select a sort option the facet option I selected is reset.
    – user22939
    Nov 25, 2013 at 21:02
  • I have tried this method and it was working for me. Nov 26, 2013 at 1:34
  • Nope. I just tried it again and it isn't working. This is just an assumption but maybe the facets are working with the results provided by the view, not the view itself.
    – user22939
    Nov 26, 2013 at 17:00
  • This is not assumption. Which type of views you have created? What do you mean that facet is working with result provided by view, not the view itself. Nov 27, 2013 at 3:01
  • Check my original post. I've added additional information that will hopefully explain the problem a little better.
    – user22939
    Nov 27, 2013 at 19:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.