#community-help

Range Filtering and Faceting Discussion

TLDR Phil asked about the requirements for range filtering, which Jason explained does not always require faceting. Discussion about different possibilities with Algolia and Typesense ensued, resulting in Phil successfully utilizing the 'Configure' widget.

Powered by Struct AI

2

48
26mo
Solved
Join the chat
Oct 04, 2021 (26 months ago)
Phil
Photo of md5-cabbd7b73bbc9bdf14391445a8d5890c
Phil
11:25 PM
Does range filtering require faceting enabled?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
11:26 PM
No. Except when you need to filter by exact values or if you use the instantsearch adapter
11:27
Jason
11:27 PM
The latter restriction exists because in Algolia only faceted fields can be filtered on, and so Instantsearch built by Algolia makes that assumption. So when you add a refinement list for eg, it automatically also sends a facet_by parameter.
11:28
Jason
11:28 PM
but if you make calls to Typesense directly, you can filter on fields that are not facets
Phil
Photo of md5-cabbd7b73bbc9bdf14391445a8d5890c
Phil
11:32 PM
in algolia right now, I don't have the field "price" specified as a faceted field but the range component from instantsearch still works with it
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
11:34 PM
Hmm, according to the docs here: https://www.algolia.com/doc/api-reference/api-parameters/filters/#how-to-use

> You must declare each attribute you use as a filter in attributesForFaceting, except for _tags, which we automatically consider as attributesForFaceting.
11:34
Jason
11:34 PM
Could the facets be declared on all fields by default somehow?
Phil
Photo of md5-cabbd7b73bbc9bdf14391445a8d5890c
Phil
11:49 PM
it looks like the range component turns it into a numericFilter, which doesn't have the same requirement of being faceted
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
11:51 PM
I see, interesting. Do you see min and max values in the widget when it is rendered?
Phil
Photo of md5-cabbd7b73bbc9bdf14391445a8d5890c
Phil
11:51 PM
I haven't looked at the underlying libraries and mechanisms (instantsearch and the search clients) so I don't know if this helps
11:51
Phil
11:51 PM
no, I do not get min and max values
11:51
Phil
11:51 PM
that was something that I was curious about actually, and it would make sense that those are gotten from facets
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
11:52 PM
Yup!
Phil
Photo of md5-cabbd7b73bbc9bdf14391445a8d5890c
Phil
11:53 PM
currently I just leave min and max blank until a user fills them in. would you consider an update to allow similar functionality?
11:54
Phil
11:54 PM
I just worry that there might be a performance hit for faceting prices, as I'm trying to create a marketplace and every item could potentially have a unique price
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
11:54 PM
I believe it automatically sets it to blank, but just shows the min and max values as a placeholder (the input field's attribute)
11:55
Jason
11:55 PM
For eg see the filters at the bottom on this: https://linux-commits-search.typesense.org/
11:56
Jason
11:56 PM
The numbers in the input fields are just placeholder, but the actual value is blank
Phil
Photo of md5-cabbd7b73bbc9bdf14391445a8d5890c
Phil
11:59 PM
I'm actually using my own components and not the widget directly, through connectRange, which should provide the min and the max for you. This is what I assume is used as the placeholder. However, the "min" and "max" are undefined when I implemented them
Oct 05, 2021 (26 months ago)
Phil
Photo of md5-cabbd7b73bbc9bdf14391445a8d5890c
Phil
12:00 AM
I just ignored that and have no placeholders
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
12:02 AM
Ah I see
12:07
Jason
12:07 AM
So the key difference seems to be that Algolia allows a field that is not configured as a facet in the index to still be specified as a facet field in the search request. It just ignores that facet request, and returns results without facets. Whereas in Typesense we are raising an error when you try to facet by a field that's not configured as a facet in the index...
12:09
Jason
12:09 AM
From Typesense Server's perspective, there's an argument to be made that if a field is mentioned in facet_by at search time, and it's not set as a facetted field in the index, then that's an error - so calling the error out is better than silently returning results without that key and letting the user figure out why the facet data wasn't in the response
12:10
Jason
12:10 AM
Any reason you're not able to set this field as a facet in the index, and just ignore the min and max values in your widget?
Phil
Photo of md5-cabbd7b73bbc9bdf14391445a8d5890c
Phil
12:11 AM
no concrete reason just the fear that faceting on prices will be a performance hit
12:11
Phil
12:11 AM
because all the prices can be unique
12:11
Phil
12:11 AM
do you think that'd be an issue?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
12:12 AM
Facets are generally expensive, but the performance difference is only material at 10s of millions of records from what I've seen
12:12
Jason
12:12 AM
Btw, since you are creating your own widget, another approach would be to not set this field as a facet in the query, when you construct it in the widget
12:13
Jason
12:13 AM
I haven't done this in the past, so just guessing that it's possible based on some examples I've seen
Phil
Photo of md5-cabbd7b73bbc9bdf14391445a8d5890c
Phil
12:49 AM
I'm a little confused what that means, not setting the field as a facet in the query
12:49
Phil
12:49 AM
trying to work around it though, I was hoping to use the instantsearch "Configure" and directly add the range filter
12:50
Phil
12:50 AM
but does the typesense adapter not take it into account?
12:50
Phil
12:50 AM
btw thanks so much for your time in looking into this so far

1

Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
12:51 AM
Yeah the configure widget works in general... but thinking how it would work in this use case
12:51
Jason
12:51 AM
> I'm a little confused what that means, not setting the field as a facet in the query
Trying to find you an example
Phil
Photo of md5-cabbd7b73bbc9bdf14391445a8d5890c
Phil
12:53 AM
so for the configure widget, what happens if I add filters="price:>100"?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
12:54 AM
It will apply it as the default filter on page load
Phil
Photo of md5-cabbd7b73bbc9bdf14391445a8d5890c
Phil
12:54 AM
I actually tried putting a couple things in the filter option for the configure widget but it didn't change the request to typesense
12:59
Jason
12:59 AM
> I'm a little confused what that means, not setting the field as a facet in the query
Can't seem to find an example for this. But for some reason I thought you could call the algolia helper functions within a custom widget... I thought these helper functions are what set what fields to set as a facet vs not in the search query
01:00
Jason
01:00 AM
Basically wherever it does this: https://community.algolia.com/algoliasearch-helper-js/gettingstarted.html#adding-facets

if you're able to override it and not set the numerical field as a facet, then it won't get sent over to the adapter / Typesense
01:02
Jason
01:02 AM
Phil
Photo of md5-cabbd7b73bbc9bdf14391445a8d5890c
Phil
05:10 PM
hi, just wanted to let you know I ended up working around it by using the Configure widget and setting the numericFilters on it, such as ['price<=100']
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
05:10 PM
I see interesting! Good to know
Phil
Photo of md5-cabbd7b73bbc9bdf14391445a8d5890c
Phil
05:10 PM
thanks for the help!

1