- The relative importance of each attribute
- Whether the position of the match in the attribute matters
Attribute order
While setting searchable attributes, you can order them, making some more relevant than others. Knowing how to order your searchable attributes can be challenging, especially when you have several. One method is to compare them in pairs, each attribute with the previous one, and move them around accordingly. This is similar to insertion sorting. For example, suppose you have the following attributes in the records of a “movies” index:director
cast
title
genres
plot_summary
- Compare the first two:
director
andcast
. If you thinkcast
should come beforedirector
(for example, you want to see movies with Clint Eastwood before movies directed by Clint Eastwood), movecast
to the first place. - Compare
director
andtitle
and decide that the movie’s name is more important than the director’s. That means you’d movetitle
to the second place and compare it with the previous one (cast
). - Prioritize a match on an actor’s name or a movie title. If all records in your index represent movies, it may make sense to prioritize
title
, so you’d move it first. Then, because you don’t have any more attributes to comparetitle
to, you’d move on togenres
.
Searchable attributes with different priorities
The order of searchable attributes directly affects search relevance. Attributes higher in the list are more relevant than attributes further down. Therefore, you should set attributes higher in the searchable attributes list when their content is more relevant to your users. Consider a movie database website where users can search movies by title, actors, and director. You may be tempted to prioritize actors before directors Yet, consider the following dataset:JSON
title
as the first searchable attribute makes sense. But what if someone searched for “Clint Eastwood”? Would they primarily be looking for movies with Clint Eastwood, by Clint Eastwood, or both? In other words, how should you rank the director
and actors
attributes?
By putting director
first, movies that Clint Eastwood directed would come before those where he appeared as an actor. This may or may not be desirable. For example, if a user types “jane”, do you want to first display movies with director Jane Campion or actress Jane Fonda?
There’s no one-size-fits-all approach, and the strategy depends on your use case. Defining a priority order in your searchable attributes isn’t trivial. It can vary depending on your data, how it’s structured, what your users search for, and what they expect as results.
Searchable attributes with the same priority
Sometimes, setting an attribute before or after another doesn’t make sense because you want them to be equally considered. Here’s another dataset, this time with records representing movies, actors, and directors:JSON
John
, it wouldn’t necessarily make more sense to show movies with John in the title than actors or directors named John. Instead, you may want to rely on other criteria, like popularity, to decide what comes first.
In this case, it makes sense to set movie_title
, actor_name
, and director_name
at the same level.
This way, if someone types John
, the engine considers all three records equal in the attribute ranking criterion, and the engine would go to the next ranking criterion to try and break the tie.
Attributes with the same priority are always unordered.
Word position
Searchable attributes can be ordered or unordered:- ordered means that the engine considers matches at the beginning of an attribute more important than matches in the middle or the end. When an attribute is ordered, the earlier a match occurs, the higher the engine ranks it.
- unordered means that the position of the match within the attribute doesn’t affect ranking.
You should usually set the attribute to be unordered since the position of the matching word in the attribute often doesn’t matter.
JSON
title
as unordered
.
Things are different with the cast
attribute.
If users type “Scarlett Johansson,” chances are they would be more interested in movies where Scarlett Johansson has a leading role than movies where she played small parts.
Assuming that the order of actors and actresses in the cast
attribute reflects role size, keeping cast
ordered makes more sense.
Set unordered or ordered with the API
You can set attributes as unordered or ordered withsearchableAttributes
when indexing.
If unordered isn’t set for an attribute, it will default to ordered when set by the API.
Set unordered or ordered from the dashboard
- Select the Search product icon on your dashboard.
- On the Index page, select your index.
- Click the Configuration tab.
- Go to the Searchable Attributes section. For each searchable attribute, consider whether it should be ordered or unordered.
- Save your changes.
When using the dashboard, the UI defaults to setting your attribute as unordered.
Successful strategies
Setting searchable attributes is more an art than a science and highly depends on your use case. There’s no magic formula that works for everyone. However, the following tips will get you started.Keep as few searchable attributes as possible
As a rule of thumb, the more searchable attributes, the noisier the search. It may be tempting to add as many searchable attributes as possible to get as many matches as you can. Yet, this reduces search relevance by creating noise (littering good results with not-so-good ones). Instead, be conservative with your searchable attributes and focus on what your users tend to search for. Some attributes, like image URLs or review scores, shouldn’t be searchable because they don’t have textual value. Some other attributes, like the plot summary of a movie, might look interesting but could be unnecessary. How often do you find a movie by searching for the synopsis? Probably far less often than with the title or lead actors. The same advice goes for the length of the attribute values. Suppose you have a “movies” index where the records have anactors
attribute.
If this attribute has the entire cast, it’s less efficient than if it only had the leading roles.
Most users would probably look at leading roles when searching for an actor.
Choose the appropriate attribute order
Knowing how to order your searchable attributes can be challenging, especially when you have several. One method is to compare them in pairs, each attribute with the previous one, and move them around accordingly. The process is like insertion sorting. For example, suppose you have the following attributes in the records of a “movies” index:director
cast
title
genres
plot_summary
- Compare the first two:
director
andcast
. If you thinkcast
should come beforedirector
(for example, you want to see movies with Clint Eastwood before movies directed by Clint Eastwood), movecast
to the first place. - Compare
director
andtitle
and decide that the movie’s name is more important than the director’s. That means you’d movetitle
to the second place and compare it with the previous one (cast
). - Prioritize a match on an actor’s name or a movie title. If all records in your index represent movies, it may make sense to prioritize
title
, so you’d move it first. Then, because you don’t have any more attributes to comparetitle
to, you’d move on togenres
.
Where to put filters?
Sometimes it’s better to prioritize filters over all other attributes. This might not seem intuitive at first, as you may think users tend to search by attributes likename
or title
.
Suppose you have a “movies” index where the records have a genre
attribute with values like “crime” and “action”.
Films fall into these categories, but there are also films whose titles and descriptions use these exact words,
for example, “Crime Doesn’t Pay”, “Last Action Hero”.
In that case, you can decide that when a user searches for words that are more like genres,
it’s best to search filter attributes before the title.
This is guaranteed to return all crime movies whenever someone types in crime
, regardless of the title.
Making this decision when setting up searchable attributes can significantly affect your results.