#community-help

Understanding Facet Query and Filter By on Typesense

TLDR Ricardo needed clarification on using facet_query. Kishore Nallan explained its use alongside filter_by, helping Ricardo understand the concepts. The discussion also touched upon how facet_query works with sets of fields and the difference between facet_query and filter_by.

Powered by Struct AI
May 08, 2021 (33 months ago)
Ricardo
Photo of md5-914a8b39b82fd99b8ecd985427660deb
Ricardo
09:19 AM
or am I even using facet_query properly?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
09:20 AM
Can you try setting per_page and page explicitly?
Ricardo
Photo of md5-914a8b39b82fd99b8ecd985427660deb
Ricardo
09:21 AM
ya that works
09:21
Ricardo
09:21 AM
thanks
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
09:21 AM
Generally for facet query you don't care about results because it is a query on the facets of the query.
09:22
Kishore Nallan
09:22 AM
So keeping that in view, Typesense does not return results.
Ricardo
Photo of md5-914a8b39b82fd99b8ecd985427660deb
Ricardo
09:22 AM
I see
09:22
Ricardo
09:22 AM
so I am trying to get all the records that are in the category chair
09:22
Ricardo
09:22 AM
is this the best way to go about it?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
09:23
Kishore Nallan
09:23 AM
?filter_by=category: foo
Ricardo
Photo of md5-914a8b39b82fd99b8ecd985427660deb
Ricardo
09:23 AM
so can you explain the difference between filter_by and facet_query
09:24
Ricardo
09:24 AM
I don't think I'm understanding what facet_query does
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
09:24 AM
filter_by filters the actual results. It is equivalent to the WHERE clause in SQL.
09:25
Kishore Nallan
09:25 AM
Let's say you have an ecommerce shop and you have products from different brands. Lets say you search for shoes, and then facet on brands. This will return all shoe brands available with their corresponding counts. Now if you want to search within those facet brands, you will use facet query.
09:26
Kishore Nallan
09:26 AM
In the song search demo, facet query is used here to filter the genres here if the user types into the textbox.
Ricardo
Photo of md5-914a8b39b82fd99b8ecd985427660deb
Ricardo
12:14 PM
ok I think I understand
12:14
Ricardo
12:14 PM
so facet_query is like a search in the facet itself
12:15
Ricardo
12:15 PM
but then if I do a filter by with a query: '*'
wouldn't that be equivalent to a facet_query?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
12:17 PM
> so facet_query is like a search in the facet itself
Correct.

As for your second question, you can search on one set of fields and facet on another set of fields. They don't have to overlap.
Ricardo
Photo of md5-914a8b39b82fd99b8ecd985427660deb
Ricardo
12:18 PM
I see. ok cool. Thanks Kishore Nallan I'll play around with this a bit. appreciate your patience and time 🙂
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
12:18 PM
Welcome.

Typesense

Lightning-fast, open source search engine for everyone | Knowledge Base powered by Struct.AI

Indexed 3015 threads (79% resolved)

Join Our Community