Does range filtering require faceting enabled?
# community-help
p
Does range filtering require faceting enabled?
j
No. Except when you need to filter by exact values or if you use the instantsearch adapter
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.
but if you make calls to Typesense directly, you can filter on fields that are not facets
p
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
j
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.
Could the facets be declared on all fields by default somehow?
p
it looks like the range component turns it into a numericFilter, which doesn't have the same requirement of being faceted
j
I see, interesting. Do you see min and max values in the widget when it is rendered?
p
I haven't looked at the underlying libraries and mechanisms (instantsearch and the search clients) so I don't know if this helps
no, I do not get min and max values
that was something that I was curious about actually, and it would make sense that those are gotten from facets
j
Yup!
p
currently I just leave min and max blank until a user fills them in. would you consider an update to allow similar functionality?
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
j
I believe it automatically sets it to blank, but just shows the min and max values as a placeholder (the input field's attribute)
For eg see the filters at the bottom on this: https://linux-commits-search.typesense.org/
The numbers in the input fields are just placeholder, but the actual value is blank
p
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
I just ignored that and have no placeholders
j
Ah I see
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...
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
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?
p
no concrete reason just the fear that faceting on prices will be a performance hit
because all the prices can be unique
do you think that'd be an issue?
j
Facets are generally expensive, but the performance difference is only material at 10s of millions of records from what I've seen
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
I haven't done this in the past, so just guessing that it's possible based on some examples I've seen
p
I'm a little confused what that means, not setting the field as a facet in the query
trying to work around it though, I was hoping to use the instantsearch "Configure" and directly add the range filter
but does the typesense adapter not take it into account?
btw thanks so much for your time in looking into this so far
👍 1
j
Yeah the configure widget works in general... but thinking how it would work in this use case
I'm a little confused what that means, not setting the field as a facet in the query
Trying to find you an example
p
so for the configure widget, what happens if I add filters="price:>100"?
j
It will apply it as the default filter on page load
p
I actually tried putting a couple things in the filter option for the configure widget but it didn't change the request to typesense
j
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
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
p
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']
j
I see interesting! Good to know
p
thanks for the help!
👍 1