Multi-index search with different queries

Hi all!

I’m trying to implement a domain search. All the top level domains are indexed in Algolia.

What I would like to achieve is that when a user searches e.g. for my-garden-company.com, I would like to show him a list of sensible top level domains. Such as:

  • garden
  • company
  • com

To achieve this I came up with this solution:

  1. After entering my-garden-company.com, I would take the first part of the query before the dot (= my-garden-company) and search in my index domain-index. This would result in the following results: garden and company.
  2. Simultaneously I would take the query part after the dot (= com) and search in domain-index. This would obviously result in com.

It all feels a bit weird… And I did not find a way to intercept/edit the query sent to the indices.

<ais-instantsearch [config]="config">
  <ais-search-box placeholder="my-garden-company.com"></ais-search-box>

  <ais-index indexName="domain-index">
    <!-- Here i would like to send 'my-garden-company' as the query -->
    <ais-hits></ais-hits>
  </ais-index>

  <ais-index indexName="domain-index">
    <!-- Here i would like to send 'com' as the query -->
    <ais-hits></ais-hits>
  </ais-index>

</ais-instantsearch>

Thanks for your help!

So one solution I just came up with is to use multipleQueries.

    const query1: MultipleQueriesQuery = {query: 'my-garden-company', indexName: 'tld'};
    const query2: MultipleQueriesQuery = {query: 'com', indexName: 'tld'};
    searchClient.multipleQueries([query1, query2]).then((result) => {
      console.log(result);
    })

Now my question is: Can I use multipleQueries together with the Angular directives? (e.g. ais-instant-search)?

Hi @michael.hunziker !

My first thought would be to try using an ais-configure directive where you can pass any search parameter, including query which is a way to override the searched string.

If you use this directive within each ais-index, I believe it should achieve what you’re trying to do.

Let us know how it goes.

Cheers,
Julien