hello team , I have implemented Typesense DocSearc...
# community-help
r
hello team , I have implemented Typesense DocSearch. However, I now need to update it to a global DocSearch. Is it possible to pass multiple collections at once so that we can retrieve all data in search hits based on the specified collections? or else how can I able to get the data of multiple collection in docsearch
Copy code
docsearch({
          container: '#searchbar',
          typesenseCollectionName: `Developer_Docs_${product}`,
          typesenseServerConfig: {
            nodes: [
              {
                host: typesenseHost,
                port: typesensePort,
                protocol: typesenseProtocol,
                path: typesensePath
              }
            ],
            apiKey: searchOnlyApiKey
          },

          typesenseSearchParameters: {
            filter_by: `product_tag:=${product}_${platform}`,
            snippet_threshold: 5,
            highlight_affix_num_tokens: 3,
            page: 1,
            per_page: 20
          }
        });
f
So, the actual docsearch library uses the
multi-search
endpoint for the search
Copy code
const client = {
      search: async ([request]) => {
        const response = await typesense.multiSearch.perform({
          searches: [request],
        });
        const typesenseSearchResponseAdapter =
          new TypesenseSearchResponseAdapter(
            response.results[0],
            {
              params: {
                ...request.params,
                highlightPreTag: '<mark>',
                highlightPostTag: '</mark>',
              },
            },
            {
              geoLocationField: '',
            }
          );
        return {
          results: [typesenseSearchResponseAdapter.adapt()],
        };
      },
    };
But, the results are passed as a singular request to the server
Copy code
return searchClient
            .search<DocSearchHit>([
              {
                collection: typesenseCollectionName,
                // @ts-expect-error
                q: query,
                // @ts-expect-error
                query_by:
                  'hierarchy.lvl0,hierarchy.lvl1,hierarchy.lvl2,hierarchy.lvl3,hierarchy.lvl4,hierarchy.lvl5,hierarchy.lvl6,content',
                include_fields:
                  'hierarchy.lvl0,hierarchy.lvl1,hierarchy.lvl2,hierarchy.lvl3,hierarchy.lvl4,hierarchy.lvl5,hierarchy.lvl6,content,anchor,url,type,id',
                highlight_full_fields:
                  'hierarchy.lvl0,hierarchy.lvl1,hierarchy.lvl2,hierarchy.lvl3,hierarchy.lvl4,hierarchy.lvl5,hierarchy.lvl6,content',
                group_by: 'url',
                group_limit: 3,
                sort_by: 'item_priority:desc',
                snippet_threshold: 8,
                highlight_affix_num_tokens: 4,
                ...typesenseSearchParameters,
              },
            ])
So querying multiple collections isn't supported out of the box. We'd have to tweak the library to support multiple input points (maybe spread out the requests and just do a
.map()
over the collection names, but then again, we'd have to refactor to ensure it returns the responses as expected.
I would advise to concatenate all your docs into a single collection for the time being