I know the default behavior is to return all of the records if an empty string is passed when performing a search, but I want to do the opposite: return no records.
I have removeStopWords
enabled, so Algolia will remove meaningless words like "The"
, "Is"
, "As"
from the search string, but when no other words other than stop words are on the search string then Algolia will leave an empty string and perform the search with it. That’s clearly a problem because I do not want my users to get all of the existing records when doing a search like "The is as"
, that’s really dumb.
I’ve been looking for an answer all over the internet, but no one seems interested on doing what I’m doing, don’t know if I’m misunderstanding something and shouldn’t be doing this, or whatever, but I’m pretty sure how do I want my app to work, and that’s why I’m asking.
Every single communication with my Algolia index is made from the backend, so no frontend solution works for me. I’m using the "algoliasearch"
library on Node.js.
This is the code I’m using in order to retrieve my records:
const { hits, nbPages, page } = await productsIndex.search<Product>(
search ?? '',
{
hitsPerPage: limit,
filters,
page: decodedEsk ? decodedEsk.page : undefined,
}
);
The search
variable before the ??
is the search string received from the frontend, so that search may include stop words and I do not know how to remove the stop words from it, since the library does not offer a way of getting the stop words dictionary.
What I was trying to do is to find a way to remove the stop words from that string and if the remaining string is an empty string then I will not call the productsIndex.search
method and return an empty array, if after removing the stop words the string is not empty the I call productsIndex.search
.
Did you guys now how to solve this? Thank you so much!