Sunspot Solr Pattern with Multiple Filters

In sunspot solr, we could group records with similar attributes across faces. But is it possible to make a faceted filter of two attributes?

I tried to do this in my search:

facet_search = User.search do facet :attribute1, :attribute2 end facet_search.facet(:attribute1, :attribute2) 

With this, I keep getting null values, and I'm sure there are records with similar values ​​in attributes1 and attribute2.

Let's say that there are two entries that have values ​​in attribute1 as "orange". And these two entries have values ​​in attribute2 as "eagles."

Is there a function in the sunspot that I could use to group records based on two columns and how to do it?

Thanks for the help in advance.

+4
source share
1 answer

Are you sure you want to filter? The attribute simply returns the first number of unique values ​​for this attribute. Therefore, if attribute1 contains colors, you will get orange, red, blue, etc. Any unique color matching your current search. Only one-sided copying does not filter the search results.

From your question, I think you want to filter some value in attribute1 and some value in attribute2. For this, your search will be more like:

 facet_search = User.search do # Filter my results... with(:attribute1).equal_to("orange") with(:attribute2).equal_to("eagle") end 

You can still include facet :attribute1 if you want to get unique values ​​for attribute1 to display in the user interface or something like that. Just note that the declaration: attribute1 as a facet does not filter the search.

+6
source

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


All Articles