#community-help

Filtering Arrays Using Non-Exact Match with Filter_by

TLDR gab asked about using filter_by for non-exact matches. Kishore Nallan explained the difference between filter_by and query_by, leading to a solution for gab.

Powered by Struct AI
13
9mo
Solved
Join the chat
Mar 22, 2023 (9 months ago)
gab
Photo of md5-8be2a24edf7a95c9c74abce4b1130c3e
gab
11:59 AM
Hi,
Can we use filter_by to filter array using non-exact match ?
it seems genres:=[Rock] will filter with exact match
Thanks
Harpreet
Photo of md5-745d880d794220d9f0fb9ade17c6b861
Harpreet
12:04 PM
genres:!=[Rock] should work
gab
Photo of md5-8be2a24edf7a95c9c74abce4b1130c3e
gab
12:05 PM
My bad, I meant filtering using contain clause
12:05
gab
12:05 PM
It seems this not working genres:[Rock]
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
12:21 PM
Without = it should do contains
gab
Photo of md5-8be2a24edf7a95c9c74abce4b1130c3e
gab
12:21 PM
I didn't get it working without the =. I used instead of filter_by, query_by with q that seems to performs what I need
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
12:33 PM
Can you post a small example data and query just so I see could be going wrong?
gab
Photo of md5-8be2a24edf7a95c9c74abce4b1130c3e
gab
12:40 PM
data:
[
{paths:["beverage/beer","food/cake"]},
{paths:["beverage/beer/brown","food/cake"]},
]

query: filter_by paths:[beverage]
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
12:47 PM
That's because of the / character. String will be indexed as beveragebeer so word won't match with filter.
gab
Photo of md5-8be2a24edf7a95c9c74abce4b1130c3e
gab
12:51 PM
Ok I see. Could you please just clarify why it works using query_by and q?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
12:51 PM
Because query by supports prefix search
gab
Photo of md5-8be2a24edf7a95c9c74abce4b1130c3e
gab
12:52 PM
Ok :) now I got something working and clear
12:52
gab
12:52 PM
Thanks

Typesense

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

Indexed 3005 threads (79% resolved)

Join Our Community

Similar Threads