#community-help

Filtering Issue with Partial Field Information

TLDR Facundo faced an issue filtering by a field with partial information. Kishore Nallan suggested adding ':' as a token separator and using "q" for prefix search.

Powered by Struct AI
7
4mo
Solved
Join the chat
May 01, 2023 (5 months ago)
Facundo
Photo of md5-acdab31d3dfb1b3ccd497a43ef2fe0d1
Facundo
04:35 PM
Hello to everyone! Willing to have some help with this filtering issue I'm facing:
Jason,
Thank you for the answer. Is good to know.

I need your technical help one more time:
I'm trying to filter by a field where I want that field not to contain certain info (see first image for the filter_by query I'm doing.

The problem I'm facing, is that in the collection, the real info inside that field is partial (see second image for collection info).

You can see there that the collection has the same info with a ": other" at the end.

How can I achieve this, without using the "q"?
Image 1 for Hello to everyone! Willing to have some help with this filtering issue I'm facing:<br>Jason,<br>Thank you for the answer. Is good to know.<br><br>I need your technical help one more time:<br>I'm trying to filter by a field where I want that field not to contain certain info (see first image for the filter_by query I'm doing.<br><br>The problem I'm facing, is that in the collection, the real info inside that field is partial (see second image for collection info).<br><br>You can see there that the collection has the same info with a ": other" at the end.<br><br>How can I achieve this, without using the "q"?Image 2 for Hello to everyone! Willing to have some help with this filtering issue I'm facing:<br>Jason,<br>Thank you for the answer. Is good to know.<br><br>I need your technical help one more time:<br>I'm trying to filter by a field where I want that field not to contain certain info (see first image for the filter_by query I'm doing.<br><br>The problem I'm facing, is that in the collection, the real info inside that field is partial (see second image for collection info).<br><br>You can see there that the collection has the same info with a ": other" at the end.<br><br>How can I achieve this, without using the "q"?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
04:39 PM
👋 That's not possible. Filter by cannot prefix search. It matches the string fully.

One work around is to add : as a token separator when creating the collection so a string like foo:bar gets indexed as two separate words foo and bar so your filter query can match...

e.g.

curl -k "" -X POST -H "Content-Type: application/json" \                                                                                                                        
      -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" -d '{
  "fields": [       
    {               
     
      "name": "title",
      "type": "string"
    }               
  ],                 
  "name": "products",   
  "token_separators": [':'] 
}'    
Facundo
Photo of md5-acdab31d3dfb1b3ccd497a43ef2fe0d1
Facundo
04:43 PM
Thank you Kishore Nallan. Would it be possible using the "q"?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
04:43 PM
Yes, q allows prefix search
Facundo
Photo of md5-acdab31d3dfb1b3ccd497a43ef2fe0d1
Facundo
04:45 PM
Thanks!
May 03, 2023 (4 months ago)
Facundo
Photo of md5-acdab31d3dfb1b3ccd497a43ef2fe0d1
Facundo
05:44 PM
Kishore Nallan since the space is the default token separator, why can't I filter, for example, this one in the image above?
Image 1 for <span class="s-mention s-user"> <strong>Kishore Nallan</strong></span> since the space is the default token separator, why can't I filter, for example, this one in the image above?
05:45
Facundo
05:45 PM
I removed the "other" from the filtering, and I left the colon in the string.