How to query results only when the search input is not empty? #5317
-
I would like to prevent from sending a query request when the search input is empty. How to configure it? Currently, the only way which I found is to not render |
Beta Was this translation helpful? Give feedback.
Answered by
francoischalifour
Jun 8, 2022
Replies: 0 comments 1 reply
-
There's no boolean configuration for this, but you can implement this at the search client level: const originalSearchClient = algoliasearch(
"latency",
"6be0576ff61c053d5f9a3225e2a90f76"
);
const searchClient = {
...originalSearchClient,
search(requests) {
if (requests.every(({ params }) => !params.query)) {
return Promise.resolve({
results: requests.map(() => ({
hits: [],
nbHits: 0,
nbPages: 0,
page: 0,
processingTimeMS: 0
}))
});
}
return originalSearchClient.search(requests);
}
}; I created a sandbox to show you. We cover this in the "Detecting empty search requests" section of our documentation (soon available for React InstantSearch Hooks). |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
jpomykala
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There's no boolean configuration for this, but you can implement this at the search client level:
I created a sandbox to show you.
We cover this in the "Detecting empty search requests" section of our doc…