I am using React InstantSearch with the Typesense adapater.
Our search data has two collections - emails and attachments.
- Both collections have a facet for sender's email (
from_email
) - Attachments also have a facet for file extension (
ext
)
If I configure my search for one of the collections only everything works as expected but for some reason I cannot get file type refinement list to work if I have both collections in use.
If I have both collections in use no matter what I select from file type refinement list it does not affect search results. I am clearly not using the search correctly but cannot figure out what I'm doing wrong.
Simplified version of my code:
import {
useMemo,
useState,
} from 'react';
import {
Configure,
Index,
InstantSearch,
} from 'react-instantsearch';
import TypesenseInstantSearchAdapter from 'typesense-instantsearch-adapter';
function EmailSearch() {
const searchClient = useMemo(() => {
if (userConfig) {
const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
server: {
apiKey: userConfig.search.apiKey,
nodes: [...],
},
collectionSpecificSearchParameters: {
collection_emails: {
query_by: 'subject,from_name,from_email,body',
},
collection_attachments: {
query_by: 'filename,content,ext',
},
},
});
return typesenseInstantsearchAdapter.searchClient;
}
return null;
}, [userConfig]);
return (
<InstantSearch
searchClient={searchClient}
indexName="collection_emails"
future={{
preserveSharedStateOnUnmount: true,
}}
>
<Configure hitsPerPage={5} />
<CustomSearchBox /> { /* Custom search box component */ }
<FromRefinementList attribute="from_email" /> { /* both collections have "from_email" */ }
<Index indexName="collection_attachments">
<FileTypeRefinementList attribute="ext" /> { /* only attachments have "ext" */ }
</Index>
<Index indexName="collection_emails">
<EmailHits />
</Index>
<Index indexName="collection_attachments">
<AttachmentHits />
</Index>
</InstantSearch>
);
}
When I select one email address from FromRefinementList
and one file type from FileTypeRefinementList
this is what is sent to the search engine:
"searches": [
{
"query_by": "subject,from_name,from_email,body",
"collection": "collection_emails",
"q": "*",
"facet_by": "from_email",
"filter_by": "from_email:=[`[email protected]`]",
"max_facet_values": 10,
"page": 1,
"per_page": 5
},
{
"query_by": "subject,from_name,from_email,body",
"collection": "collection_emails",
"q": "*",
"facet_by": "from_email",
"max_facet_values": 10,
"page": 1
},
{
"query_by": "filename,content,ext",
"collection": "collection_attachments",
"q": "*",
"facet_by": "ext,from_email",
"filter_by": "ext:=[`pdf`] && from_email:=[`[email protected]`]",
"max_facet_values": 10,
"page": 1,
"per_page": 5
},
{
"query_by": "filename,content,ext",
"collection": "collection_attachments",
"q": "*",
"facet_by": "ext",
"filter_by": "from_email:=[`[email protected]`]",
"max_facet_values": 10,
"page": 1
},
{
"query_by": "filename,content,ext",
"collection": "collection_attachments",
"q": "*",
"facet_by": "from_email",
"filter_by": "ext:=[`pdf`]",
"max_facet_values": 10,
"page": 1
},
{
"query_by": "subject,from_name,from_email,body",
"collection": "collection_emails",
"q": "*",
"facet_by": "from_email",
"filter_by": "from_email:=[`[email protected]`]",
"max_facet_values": 10,
"page": 1,
"per_page": 5
},
{
"query_by": "subject,from_name,from_email,body",
"collection": "collection_emails",
"q": "*",
"facet_by": "from_email",
"max_facet_values": 10,
"page": 1
},
{
"query_by": "filename,content,ext",
"collection": "collection_attachments",
"q": "*",
"facet_by": "from_email",
"filter_by": "from_email:=[`[email protected]`]",
"max_facet_values": 10,
"page": 1,
"per_page": 5
},
{
"query_by": "filename,content,ext",
"collection": "collection_attachments",
"q": "*",
"facet_by": "from_email",
"max_facet_values": 10,
"page": 1
}
]