typesense / typesense-instantsearch-adapter

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

Could not parse the filter query when query contains parentheses #165

Closed dziugas-liaudinskas closed 1 year ago

dziugas-liaudinskas commented 1 year ago

Description

Hello, I'm using instantsearch Configure widget to define category pages. It is used as this:

const filters = 'hierarchicalCategories.lvl2:"Audio > Home Audio > Speakers"';
...
<Configure filters={filters} />

(you can see working example here. In /app/routes/category/$slug.tsx line 14 I define filters and in /app/components/Search.tsx line 92 I use it).

In this case, everything works as expected but if the category contains parentheses (eg hierarchicalCategories.lvl2:"Audio > Home Audio > Speakers (100DB)") then I get 400 - Could not parse the filter query. Sorry that I don't have a reproducible case with a typesense adapter.

    at TypesenseInstantsearchAdapter._validateTypesenseResult (/node_modules/typesense-instantsearch-adapter/src/TypesenseInstantsearchAdapter.js:86:13)
    at map (/node_modules/typesense-instantsearch-adapter/src/TypesenseInstantsearchAdapter.js:26:14)
    at Array.map (<anonymous>)
    at TypesenseInstantsearchAdapter._callee$ (/node_modules/typesense-instantsearch-adapter/src/TypesenseInstantsearchAdapter.js:25:58)
    at tryCatch (/node_modules/@babel/runtime/helpers/regeneratorRuntime.js:44:17)
    at Generator.<anonymous> (/node_modules/@babel/runtime/helpers/regeneratorRuntime.js:125:22)
    at Generator.next (/node_modules/@babel/runtime/helpers/regeneratorRuntime.js:69:21)
    at asyncGeneratorStep (/node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
    at _next (/node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:9)
    at runMicrotasks (<anonymous>)

Typesense Version:

"typesense": "^1.5.3",
"typesense-instantsearch-adapter": "^2.6.0-1"
jasonbosco commented 1 year ago

filters should be in the Typesense format for filter_by described here.

So this line of code should be:

const filters = 'hierarchicalCategories.lvl2:=`Audio > Home Audio > Speakers  (100DB)`';

(Backticks are used to escape strings in Typesense)

dziugas-liaudinskas commented 1 year ago

That solved the issue. Thanks!