Rubai Mandal
08/30/2024, 7:24 AMdocsearch({
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
}
});
Fanis Tharropoulos
08/30/2024, 8:01 AMmulti-search
endpoint for the search
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
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.Fanis Tharropoulos
08/30/2024, 8:04 AM