The right search query is a Goldilocks style effort: not too specific that you get no results, and not too broad that you get too many. Semantic search, meanwhile, is all about understanding what searchers throw into a search box. In other words, with semantic search we meet searchers where they are, instead of requiring them to meet us where we are.
Enter query relaxation and query scoping.
Through techniques like synonyms, query word removal, and query scoping, search engines get searchers to the right content right away. We avoid missing out on relevant information that wouldn’t otherwise appear, and we leave out information that isn’t relevant.
Query relaxation and scoping are tied very closely with the concept of precision and recall. Precision is the measure of whether the returned results are relevant, and recall is whether relevant results are returned. One way to increase recall specifically is through query expansion.
Query expansion is all about expanding what the query will match with the hope of having better results. The main reason a search engine might apply query expansion is due to some indication that the “base” search results without query expansion would not be satisfactory for the searcher.
In this series, we have already seen some ways to expand queries. Typo tolerance, plural ignoring, and stemming and lemmatization are all ways to increase the recall of searches.
Those methods of query expansion we’ve already seen are among the bedrocks of search, but other query expansion methods are also just as fundamental.
In fact, an article in Search Engine Journal from 2008 talks about how Google performs query expansion! The article discusses not just stemming and typo tolerance but also translations, word removals, and synonyms.
There’s a reason that George Orwell introduced Newspeak in his novel 1984 and why it resonated in a story about life utterly controlled to the point of blandness. Linguistic richness is driven by the ability to say the same thing, or nearly the same thing, with different words and phrases. “Great” can be “awesome” and “low-cost” is a near neighbor to “cheap.”
Meanwhile, these different words can help us more precisely refer to items similar in all but the smallest ways. In fact, these differences are sometimes so small that this precision instead breeds confusion and makes us less likely to find what we want. A customer wanting a rocking chair may not know whether to search for “rockers,” “rocking chairs,” or simply “chairs.”
This is where synonyms and alternatives provide value. They help us expand recall in search results.
Synonyms and alternatives are similar, but they are not the same. (You could say that they are not synonyms.) Synonyms refer to two words or phrases that mean the same thing. Alternatives instead refer to words or phrases that are similar, but have some degrees of difference.
Often, synonyms make their way into a search engine by way of synonym lists. These lists can come from predefined lists, such as general e-commerce terms. The problem with predefined lists is that synonyms that work for one company’s search engine won’t necessarily work for another. Quick: what’s a console? You may immediately think of video games, but someone else might think of a car or music.
For that reason, many synonym lists are created in-house. At the beginning of a search implementation process, internal subject matter experts think of all of the words that could be synonyms for other words and add them to the search engine configuration. (This, in reality, is often an idealized view of what happens. Often the person creating the synonym list is not a subject matter expert, but instead the person implementing the search engine.)
Generally, this initial list will provide a good starting point, but there are sure to be missing synonyms. The only real way to discover which terms your searchers will use is to let them search.
You’ll see very quickly in your analytics queries that could use new synonyms. These queries are the queries that are returning 0 results, and are a sign that searchers are looking for something that they can’t find.
Now, not all of these queries will give you a new synonym. Sometimes, searchers are looking for items that you just don’t have. Nonetheless, you’ll see queries where you think immediately, “oh, we have that one” and “I didn’t know people asked for it like that.”
There will also be times where a query returned results, but not what the searcher wanted. These queries can also give you ideas for synonyms, if you track what’s called “search refinements.” Search refinements represent when searchers search and then search again. This implies that the searchers didn’t find what they wanted the first time, and tried again to find something better. A searcher who searches for “Dell laptop” and follows it up with “Dell notebook” is saying that “laptop” and “notebook” are related, but the search results for “laptop” were insufficient.
While there’s nothing wrong with going through your analytics manually to look for these trends (it can be a good activity to slowly ease into the workweek), you’ll be a lot more productive if you have a system that proactively sources them for you. Some systems may even apply synonyms on your behalf, but this isn’t always helpful. A human can spot refinements that don’t show valid synonyms, or may see that the system is suggesting an incorrect type of synonym.
That’s right: there are different types of synonyms. This concept may seem strange at first, but it’s probably not far from how most people think of them.
“Two-way” is the first type of synonym. These synonyms are direct replacements for each other. “Small” and “mini” are two-way synonyms of each other. The words, though, don’t need to be perfect replacements, but can be close enough that people might use one for the other. For example, “rope” and “string” don’t describe the exact same thing, but they are close enough that they are worthy two-way synonyms.
It can be useful to think of the query created through the use of synonyms. If we take a query of “small cheese pizza” and expand that out, you can think of the query now as “(small OR mini) AND cheese AND pizza.”
“One-way” is the next type of synonym. This type is often used for words that refer to an object that belong to a larger category. “PlayStation” is a type of video game “console,” but a “console” is not a type of “PlayStation.” If you add a one-way synonym to the search configuration, you can have PlayStations show up whenever someone searches for “console.”
Why not a two-way synonym between these two terms? Because two-way synonyms are transitive. If term one and term two are two-way synonyms, and term two and term three are two-way synonyms, then term one and term three are two-way synonyms. In a more direct example, “PlayStation” and “console” and “Xbox” and “console” as two groups of two-way synonyms would mean that “PlayStation” and “Xbox” are synonyms, and searchers would see Playstations when searching for Xboxes, and vice versa.
“Alternative corrections” is the final type. These are used for times when the words aren’t precise replacements for each other, and you want the exact match to appear higher than the alternative. For example, you might say that “pants” are an alternative to “shorts,” but when someone searches the word “shorts” then all shorts should appear higher than pants generally.
All synonym types, by their nature, expand recall. However, the hit on precision should be minimal, because these synonyms are “pointers” to similar concepts. In total you would expect a better search experience for the end user.
Sometimes searchers will use a query that doesn’t return anything, because the query was too specific, or used a word that didn’t exist in any of the records. Remove one word, or two words, from the query and perfectly decent results would come back. This is a great time to use query word removal.
Perhaps the most common query word removal step is the removal of “stop words.” Stop words are very common words that provide meaning for communication, but don’t help with retrieval. Words such as “the” or “an” can remove otherwise good matches. This is more common in queries that are more oriented toward natural language, such as voice search queries.
An example of this would be a search for “an orange shirt” on a product search engine. If the search engine searches over the title, color, and category, there might be plenty of records that have “shirt” as a category and “orange” as a color, but none that include the word “an.” Now, really, does the word “an” provide any useful information here? No, it doesn’t, and the search engine can safely remove it without any loss of precision.
Unlike with synonyms, you generally do not want to create your own stop word lists, and most search engines have them built in per language. However, there are times when you will want to expand on the built-in list, such as if you have an industry term that is so common that it doesn’t provide any value to a query.
Then there are queries where all of the words bring value, but searched together they bring back no results. Often searchers will be happy with less precise results in exchange for increased recall. In these situations, we want to remove words so that we put results in front of the user.
There are two main ways to do this: make all of the query words optional, or remove words from the query.
If you make all of the query words optional when there are no results, you are relying on the assumption that records that match more words are more relevant, all else being equal.
An alternative is to remove query words one-by-one until you find matching records, or there are no more words left in the query. You can start by removing the first words, or by removing the last words. Last word removal tends to be more common.
Making all of the query words optional and then sorting by the number of matching words is generally the better approach, especially when paired with the removal of stop words. This is, however, a less ideal approach when precision is important, and you want to show that, indeed, there were no results that matched all of the query words. One person may be alright with seeing Uniqlo v-neck sweaters for a query of “Gucci v-neck sweaters,” while another sees those results as completely irrelevant.
Of course, another scenario is to know which words are actually providing the most value to the query and marking them as optional. This is generally not seen in keyword-based search engines, but there have been some search engines that will take a similar approach for stop words. For example, some search engines have experimented in the past with discounting common words automatically without stop words lists, using inverse document frequency.
As with synonyms, query word removal is again going to expand recall, usually without a hit on precision. Because stop words don’t provide much value to the result, you won’t lose out on good results by not including them. Similarly, removing words when there are no results has no precision to lessen, because there are no results which could be precise.
We’ve primarily looked at situations where a searcher is being overly precise, and the search engine needs to expand the query in order to improve recall. There are, likewise, times when the search engine can understand the user intent and query scoping can increase precision.
Search expert Daniel Tunkelang calls query scoping “one of the most effective ways to capture query intent.” He identifies two major steps in query scoping. The first is query tagging, followed by the scoping itself.
Query tagging identifies the parts of a query with the attributes to which they likely belong. For example, “Marcia” will most likely match to a “name” attribute, while “The Brady Bunch” maps to a “show title” attribute. Query scoping takes this mapping and then restricts attribute searching for these query parts. The search engine doesn’t search “Brady” inside of the “name” attribute, or “Marcia” in the “show title” attribute.
This kind of query scoping reduces recall, as we won’t see results that have that text in other attributes. The outcome, though, should be that we have higher precision because we aren’t searching in irrelevant attributes.
We could, in fact, increase precision even further by filtering results by known attribute values. This doesn’t even require machine learning, as the search engine can do a simple match between facet values and text in a query. This reduces recall heavily, so we can also find a nice balance where we instead boost results with matching values rather than filtering. The boosted results will tend to be the best matching ones, because the query-filter match is giving you a signal that it is what the searcher wants.
If you find, through your analytics or hands-on experience, that your search is missing user intent and requiring searches to be “just right,” then query expansion and query scoping are two ways to calibrate your precision and recall. These approaches will let in results that should be there, and leave out the ones that shouldn’t.
Dustin Coates
Product and GTM ManagerPowered by Algolia AI Recommendations