Custom Stop Words

How can I define custom stop words that should be ignored when found in product name? Defining synonyms works great but would need something similar for stop words.

Hello @vlad.stanescu,

currently Algolia doesn’t allow you to specify your custom set of query words. But we have predefined sets of stop words for each language. You can set it with query parameter removeStopWords.

If you really need a custom set, you can use a workaround with optionalWords parameter which allows you to define a list of words which should be considered as optional in current query. It’s not a “stop words”, but it can help.

If you use Magento extension you will have to modify front end JS files in order to send this parameter(s) with your query. The code you’ll need to modify you can find in autocomplete.js and instantsearch.js files depending on what feature(s) you use.

Would that work for you?

Algolia really should allow you to perhaps, add or remove certain stop words.

For example, people might search for “pre health” but aloglia sees “pre” as a stop word.

I know we can override it at query time, but I assume algolia keeps a pretty comprehensive list of stop words.

1 Like

That’s a good idea, we’ll make sure our PM team adds it to our icebox for future improvement on the stopWords feature.

In the meantime the best solutions is the one you suggested: remove the stopwords on your side before sending the query.

const stopwordsList = ["a", "about", "above", "after", "again", "against", "all", "am", "an", "and", "any", "are", "aren't", "as", "at", "be", "because", "been", "before", "being", "below", "between", "both", "but", "by", "can't", "cannot", "could", "couldn't", "did", "didn't", "do", "does", "doesn't", "doing", "don't", "down", "during", "each", "few", "for", "from", "further", "had", "hadn't", "has", "hasn't", "have", "haven't", "having", "he", "he'd", "he'll", "he's", "her", "here", "here's", "hers", "herself", "him", "himself", "his", "how", "how's", "i", "i'd", "i'll", "i'm", "i've", "if", "in", "into", "is", "isn't", "it", "it's", "its", "itself", "let's", "me", "more", "most", "mustn't", "my", "myself", "no", "nor", "not", "of", "off", "on", "once", "only", "or", "other", "ought", "our", "ours  ourselves", "out", "over", "own", "same", "shan't", "she", "she'd", "she'll", "she's", "should", "shouldn't", "so", "some", "such", "than", "that", "that's", "the", "their", "theirs", "them", "themselves", "then", "there", "there's", "these", "they", "they'd", "they'll", "they're", "they've", "this", "those", "through", "to", "too", "under", "until", "up", "very", "was", "wasn't", "we", "we'd", "we'll", "we're", "we've", "were", "weren't", "what", "what's", "when", "when's", "where", "where's", "which", "while", "who", "who's", "whom", "why", "why's", "with", "won't", "would", "wouldn't", "you", "you'd", "you'll", "you're", "you've", "your", "yours", "yourself", "yourselves"]; // from http://www.ranks.nl/stopwords

function removeStopWords(string) {
	let queryWords = string.toLowerCase().split(' ');
	let finalString = [];

	for (let i=0; i<queryWords.length-1; ++i) {
		if (stopwordsList.indexOf(queryWords[i]) !== -1)
			continue;

		finalString.push(queryWords[i]);
	}
	
	finalString.push(queryWords[queryWords.length-1]);
	return finalString.join(' ');
}

let query = removeStopWords('I want to play a song from madonna');
console.log(query); // Output: "want play song madonna"
2 Likes

Is there an update here? We really need custom stop words.

Agreed. Custom stop words is kind of a necessity.