Hi Everyone ! We’re trying to implement multi sea...
# community-help
a
Hi Everyone ! We’re trying to implement multi search using the Typesense InstantSearch adapter with React InstantSearch, where we want to run two different queries on the same collection (
supplierinventories_rpn
)
: • Query 1
group_by: supplierInfo
for rendering supplier cards • Query 2
facet_by: supplierInfo
for post-processing like filtering We initially checked the
collectionSpecificSearchParameters
approach, but it seems suited only for federated search across different collections. So, we wrote a custom
search
function
inside the
searchClient
like this:
Copy code
const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
  server: {
    nodes: [
      {
        host: "<>",
        port: 443,
        protocol: "https",
      },
    ],
    apiKey:"<>",
  },
  flattenGroupedHits: false,
  additionalSearchParameters: {
    query_by: "",
  },
});

const customSearchClient = {
  ...typesenseInstantsearchAdapter.searchClient,
  async search(requests: any[]) {
    const orderQtyMap = Object.fromEntries(
      orderParts.map((p: any) => [p.rootPartNumber, p.quantity])
    );
    const rootPartNumbers = orderParts.map((p: any) => p.rootPartNumber);

    const filter1 = `rootPartNumber:=[${rootPartNumbers.join(",")}] && familyQuantity:>0`;

    const filter2 = rootPartNumbers
      .map(
        (pn: any) =>
          `(rootPartNumber:=${pn} && familyQuantity:>=${orderQtyMap[pn]})`
      )
      .join(" || ");

    return await typesenseInstantsearchAdapter.typesenseClient.multiSearch.perform({
      searches: [
        {
          collection: "supplierinventories_rpn",
          q: "*",
          query_by: "rootPartNumber",
          group_by: "supplierInfo",
          filter_by: filter1,
        },
        {
          collection: "supplierinventories_rpn",
          q: "*",
          query_by: "rootPartNumber",
          facet_by: "supplierInfo",
          filter_by: filter2,
        },
      ],
    });
  },
};
we checked results from the multiSearch.perform method is perfectly fine ! Problem: When we use
useInfiniteHits
, the results are empty (
hits: []
). We want to: 1. Access raw results of both queries in the frontend. 2. Use hits from the grouped query to render UI. 3. Use the second query result for post-processing. 👉 Are we missing something in this setup? 👉 Or is there a recommended way to support multi-search on the same collection in InstantSearch with custom rendering? Appreciate any help 🙏 CC : @Sahil Rally @Ashutosh