typesense / typesense-instantsearch-adapter

A JS adapter library to build rich search interfaces with Typesense and InstantSearch.js
MIT License
414 stars 64 forks source link

Filter with strict OR #95

Closed dav1d992 closed 2 years ago

dav1d992 commented 2 years ago

Description

I have a React application displaying products. I'd like to filter by multiple categories like "shoe", "hat". In typesense the request would look like this.

  'searches': [
    {
      'collection': 'products',
      'q': '*',
      'filter_by': "category:["shoe", "hat"]"
    }
  ]

But I can't seem to make it work with the instantsearch adapter. Did I miss something in my approach shown below?

Steps to reproduce

I have configured Instantsearch like so:

<Configure facetFilters=["category:shoe", "category:hat"] />

the request to typesense is then translated to filter_by: "category:=["shoe"] && category:=["hat"]" so I'll get no results since there's no product that's both a shoe AND a hat.

I retrieve the expected result by doing one filter at a time like so: <Configure facetFilters=["category:shoe"]/>

Expected Behavior

Was expecting that I could get results that's either shoe or hat referring to algolia docs that states that

[["category:Book", "category:Movie"], "author:John Doe"] translates as (category:Book OR category:Movie) AND author:"John Doe"

Actual Behavior

No results found.

Metadata

Typesense Version: 0.22.0

OS:

jasonbosco commented 2 years ago

@dav1d992 Could you try this:

<Configure facetFilters=[["category:shoe", "category:hat"]] />

(Notice the two square brackets).

dav1d992 commented 2 years ago

@jasonbosco Amazing... That did the job 😅 Thank you!