typesense / typesense-instantsearch-adapter

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

How to use different presets with single index/collection? #224

Open dharmabumzee opened 1 week ago

dharmabumzee commented 1 week ago

Description

Hi 👋

I'm having some trouble figuring out how to use one index/collection and two presets. Multiple indices work great, and collectionSpecificSearchParameters is really handy for config override per collection, but I can't figure out how to map indexId to use different presets per Index widget.

Is this even possible?

Thanks for any help in advance 🤞

additionalSearchParameters: {
        preset,
        facet_by,
      },
collectionSpecificSearchParameters: {
        // This works
        [index]: {
          preset: 'Some preset',
        },
        // This doesn't, but is there a way to connect `indexId` with specific preset?
        "id-1": {
          preset: 'Preset for 1',
        },
        "id-2": {
          preset: 'Preset for 2',
        },
      },
<InstantSearch
      searchClient={client.searchClient}
      indexName={index}
      initialUiState={initialUiState}
      onStateChange={onStateChange}
    >
     <Index indexName={index} indexId="id-1">
       <Hits />
     </Index>

     <Index indexName={index} indexId="id-2">
       <Hits />
     </Index>
</InstantSearch>

Metadata

Typesense Version:

"react-instantsearch": "7.2.0"
"typesense-instantsearch-adapter": "2.7.1",
jasonbosco commented 1 week ago

There's no way to link the indexId inside collectionSpecificSearchParameters, we only rely on the indexName.

dharmabumzee commented 1 week ago

Thanks @jasonbosco! Is there any other way to use different presets on the same index with a single client?

jasonbosco commented 4 days ago

The method you outlined here is the only way I'm aware of:

Screenshot 2024-11-25 at 2 17 44 PM