#community-help

Discussing Filter Operators in Typesense

TLDR Roshan asked about the functionality of the 'contains' operator in Typesense filters. Kishore Nallan explained how to use the operator and suggested using a curl query for better insight into the issue. However, the thread ends without a resolution.

Powered by Struct AI
Feb 17, 2022 (21 months ago)
Roshan
Photo of md5-34813b759bbed85074c3a458c4a2a053
Roshan
11:13 AM
Kishore Nallan Kishore I checked filter operators in filter operators page. link: https://typesense.org/docs/0.22.2/api/documents.html#search-parameters
I don't see contains, doesn't contains filter operators there. Does typesense support that?
I also couldn't find all the supported operators in filter by in docs. can you share the link?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
11:14 AM
Can you elaborate what you mean by contains with an example?
11:17
Kishore Nallan
11:17 AM
All the filter operators are explained in the description of the filter_by parameter here: https://typesense.org/docs/0.22.2/api/documents.html#search-parameters
Roshan
Photo of md5-34813b759bbed85074c3a458c4a2a053
Roshan
11:19 AM
eg: I need to find a book of Chetan Bhagat.
filter_by:author_name:=chetan bhagat
above filter by query works for exact match
But for following query
filter_by:author_name:=chet
it doesn't work because the operator (:=) exact match but i want operator contains/like
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
11:19 AM
filter_by=author_name:chetan

Will work, just don't add the =
11:20
Kishore Nallan
11:20 AM
The documentation mentions this, maybe we should make it clearer:

> To match a string field exactly, you can use the := operator. For eg: category:= Shoe will match documents from the category shoes and not from a category like shoe rack.
11:21
Kishore Nallan
11:21 AM
Oh wait, actually you want a fuzzy match in filtering?
Roshan
Photo of md5-34813b759bbed85074c3a458c4a2a053
Roshan
11:22 AM
yes
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
11:22 AM
filter_by=author_name:chetan will do a contains of the field so "Chetan Bhagat" will match. It's not possible to do fuzzy filtering. For that you need to use the q parameter.
11:22
Kishore Nallan
11:22 AM
Filtering is meant to precisely apply a set of conditions on your primary search query.
Roshan
Photo of md5-34813b759bbed85074c3a458c4a2a053
Roshan
11:27 AM
ilter_by=author_name:chetan will do a contains of the field so "Chetan Bhagat" will match. no it doesn't work in my case
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
11:32 AM
Can you please post a reproduceable example that I can try with?
Roshan
Photo of md5-34813b759bbed85074c3a458c4a2a053
Roshan
11:41 AM
https://books-search.typesense.org/
in this book search example. can you try filter_by=author_name:Dale and can you check you check in your result whehter books with author name name Dale carnegie appears or not ?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
11:41 AM
In the UI?
Roshan
Photo of md5-34813b759bbed85074c3a458c4a2a053
Roshan
11:42 AM
sorry not in UI
11:42
Roshan
11:42 AM
can you try from postman
11:42
Roshan
11:42 AM
i'm not sure about that
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
11:43 AM
Please post a curl query for me to try with. That's the best and precise way for us to see the same problem.
Roshan
Photo of md5-34813b759bbed85074c3a458c4a2a053
Roshan
11:43 AM
ok