Is it possible to filter a string field on multipl...
# community-help
r
Is it possible to filter a string field on multiple space-separated words and only return results that have those words in the same order? E.g.
Copy code
title:`hello world` || title:`foo bar`
When I try that now, I get back documents with title like
hello welcome to my world
But I only want documents like • hello world • introduction hello world welcome • welcome to hello world If if it's not possible, how would I achieve the above? I know I could do
q="hello world"
and
query_by:title
, but then I can't do the
||
f
Hey there, you need to use the exact operator
:=
. That way, you won't get results back that don't match the exact string. You can use this in conjunction with prefix filtering to add the star at the end of the filter string
:=hello world*
to find matches that start with that. Although, there's no postfix filtering to get results for
welcome to my world
for example. I'd also advise taking a look at the newly added Union feature for federated / multi search to concat the tuple of results into a single one, so you can send as many search requests as the OR operands in the filter_by clause you had https://github.com/typesense/typesense-website/blob/v28.0/docs-site/content/28.0/api/federated-multi-search.md#union-search
r
Thank you Fanis. I considered
:=
, but that wouldn't give me results where
hello world
is just a part of the title. The prefix filtering would give me half what I need, but I'd still be missing the postfix filtering as you suggested. Essentially I need something like
title:=*hello world
.* I came across multi-search and think it can satisfy my use case if I do something like
Copy code
searches: [
  {q: '"hello world"'}, {q: '"foo bar"'}
]
But I would have to manage pagination and offsets on the client side due to this, so I was hoping I could achieve what I wanted using the native
filter_by
functionality
This is the same thing I'm trying to do https://github.com/typesense/typesense/issues/1219
f
Yeah, that isn't currently possible in Typesense
r
The multi-search option would work in this scenario:
Copy code
title:`hello world` || title:`foo bar`
any ideas on how I'd be able to implement something like this though?
Copy code
(title:`hello world` || title:`foo bar`) && (description:`hello world` || description:`foo bar`)
Multi-search seems to be acting as an OR, but in this case we also want to AND two results. Would the only solution here to be manually union (client side) the results of the left and right?