DLO
DLO

Reputation: 1194

Typesense 'OR' query mode

Description

I have a case where I'd like to search for multiple query tokens in a single collection like:

let searchRequests = {
  'searches': [
    {
      'collection': 'products',
      'q': 'shoe hat dress perfume',
    }
  ]
}

each token contains results if I query them individually and also if I query two tokens like so: 'q': 'shoe hat',.

Is there a way to allow for more than two query items?

Expected Behavior

I expect to have results returned based on my query tokens 'shoe hat dress perfume', or in other words an OR query mode:

{
  "results": [
    {
      "facet_counts": [],
      "found": 100,
      "hits": [  
        ...
    } 
  ]
} 

Actual Behavior

The actual behavior is that nothing is found:

{
  "results": [
    {
      "facet_counts": [],
      "found": 0,
      "hits": [  
        ...
    } 
  ]
} 

Metadata

Typesense Version: 0.22.0

Upvotes: 1

Views: 873

Answers (2)

edrtz
edrtz

Reputation: 21

I recommend to use embedding and then sending "show hat dress perfume" in the q query.

Upvotes: 0

DLO
DLO

Reputation: 1194

Typesense doesn't support strict ORs and currently have no plan to do so.

To solve my problem I used filter_by instead like so:

let searchRequests = {
  'searches': [
    {
      'collection': 'products',
      'q': '*',
      'filter_by': "category:["shoe", "hat", "dress", "perfume"]"
    }
  ]
}

This would return all products of category shoe/hat/dress/parfume.

More details on usage of filter_by here: https://typesense.org/docs/0.19.0/api/documents.html#index-a-document

Upvotes: 0

Related Questions