Hi I am using instantsearch with Typesense. I need...
# community-help
j
Hi I am using instantsearch with Typesense. I need to search on two indices, but
<ais-refinement-list attribute="countryofresidence" />
is not working in this situation. The reason is that I have
countryofresidence
in my index 1 (collection 1) but not in my index 2. Is there a way make it that instantsearch ignores if index 2 doesn’t have that field or any other solutions?
j
You want to use the
collectionSpecificSearchParameters
config as described under this section: https://github.com/typesense/typesense-instantsearch-adapter#index
j
@Jason Bosco thanks. I am already using that. But the issue is that I have
countryofresidence
in my index 1, but not in index 2. In this situation, the search returns error, saying
countryofresidence
is not present in index 2.
j
Could you share with me your instantsearch adapter configuration?
j
Copy code
const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
  server: {
    apiKey: import.meta.env.VITE_TYPESENSE_API_KEY, // Be sure to use an API key that only allows search operations
    nodes: [
      {
        host: "x",
        path: "", // Optional. Example: If you have your typesense mounted in localhost:8108/typesense, path should be equal to '/typesense'
        port: "443",
        protocol: "https",
      },
    ],
    cacheSearchResultsForSeconds: 2 * 60, // Cache search results from server. Defaults to 2 minutes. Set to 0 to disable caching.
  },
  // The following parameters are directly passed to Typesense's search API endpoint.
  //  So you can pass any parameters supported by the search endpoint below.
  //  query_by is required.

  // Search parameters that are common to all collections/indices go here:
  additionalSearchParameters: {},
  // Search parameters that need to be *overridden* on a per-collection-basis go here:
  collectionSpecificSearchParameters: {
    main: {
      query_by:
        "Given Name, country of birth, countryofresidence, selfidentifiedasrefugee, mainoccupation, education, email 1, gender, jobpositions, language, last name",
    },
    kobo_updated: {
      query_by: "group_un4zf56/Name, group_un4zf56/Last_Name_Family_last_Name",
    },
  },
});
const searchClient = typesenseInstantsearchAdapter.searchClient;
j
That looks fine. Could you also confirm you’re using the
index
widget? That’s the one that lets you scope refinement lists to the correct index
You would have to nest the refinement list widget inside the index widget
j
hmm, I was following this: https://www.algolia.com/doc/guides/building-search-ui/ui-and-ux-patterns/multi-index-search/vue/ As I am starting this way:
<ais-instant-search :search-client="searchClient" index-name="main">
I didn’t see a need to use
ais-index
but only when adding the next collection.
j
ais-index
is what gets Instantsearch to send the requests to multiple collections…
Even in that example in the link above, they’ve used
<ais-index>
j
They start this way: `
Copy code
<ais-instant-search
      :search-client="searchClient"
      index-name="instant_search_price_desc"
    >
and later with the second index, they are using
ais-index
.
j
right…
j
Thanks. Using this way, I get no error:
Copy code
<ais-instant-search :search-client="searchClient" index-name="main">
    <ais-index index-name="main">
👍 1