Rails 3: Predictive filtering (faceted navigation)

Users can currently apply filters to the database query by checking the boxes, for example.

Colour
[] Red
[] Green
[] Blue    

Shape
[] Round
[] Square

Size
[] Small
[] Medium
[] Large

When you click on the flag, an AJAX request is launched, which adds a condition whereto the request, for example.

@mymodel = MyModel.scoped
@mymodel = @mymodel.where(:colour => params[:colour]) if params[:colour]
...

Now I need to add a counter after each checkbox to indicate how many results will be displayed if this checkbox is selected. eg.

Colour
[] Red (148)
[] Green (121)
[] Blue (136)
...

When you click on the checkbox, the checkboxes next to all the checkboxes should be updated, and the parameters related to the zero result will not be displayed. This should work in all categories of filters, therefore, for example, if there is nothing small and red in the database, the Small option should disappear when Red is selected, and will appear again when it is canceled.

?

.


, : Rails?
( @Pasta )

+3
4

, . Thinking Sphinx . , Rails 3, . :

:

# This will return any search results for 'pancakes'
Article.search 'pancakes'

# This will return any facets for 'pancakes'
Article.facets 'pancakes'

Solr Ferret - , , .

+6

.

;

+4

, "" ajax. railscast 43, , , , jquery rails3.

0

Source: https://habr.com/ru/post/1787464/


All Articles