typesense / typesense-instantsearch-adapter

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

Multiple fields for sorting #189

Closed jsdmc closed 7 months ago

jsdmc commented 7 months ago

Hi guys. I'm using useSortBy hook from react-instantsearch-hooks-web with typesense. Is there a way to specify multiple sortings fields for search results? Thanks

jasonbosco commented 7 months ago

Here's how you configure the sortBy widget: https://github.com/typesense/typesense-instantsearch-adapter#sortby

The same format of items applies for react-instantsearch too.

jsdmc commented 7 months ago

Here's how you configure the sortBy widget: https://github.com/typesense/typesense-instantsearch-adapter#sortby

The same format of items applies for react-instantsearch too.

Yeah, documentation is clear. But it doesn't allow specify how to sort search results by multiple fields at once. Something like that won't work.

    items: [
      { label: "Default", value: "products" },
      { label: "Popularity and price (asc)", value: "products/sort/popularity:desc,price:asc" },
      { label: "Popularity and price (desc)", value: "products/sort/popularity:desc,price:desc" },
    ],
jasonbosco commented 7 months ago

how to sort search results by multiple fields at once

Ah I see.

That syntax should work in theory... Could you open the browser's network tab and look for a request to multi_search, and copy-paste the request body here?

jsdmc commented 7 months ago

how to sort search results by multiple fields at once

Ah I see.

That syntax should work in theory... Could you open the browser's network tab and look for a request to multi_search, and copy-paste the request body here?

You are right! It's working. I wasn't sure because this functionality wasn't mentioned in docs. Thanks!