MatchScorer algorithm

Today I learned how to use the MatchScorer algorithm  in a search function.

Previously, our search results were pretty bad. If someone typed ‘zombie tower defense’ in query, it would return the latest search result that had ‘zombie’ OR ‘tower’ OR ‘defense’, and sort it based on timestamp.

This means, only newer games would appear at the top of search results. If we had a game whose title was exactly ‘zombie tower defense’, and if it was released years back, the search would be buried under newer zombie games.

With MatchScorer in default mode, it ranks in terms of keyword density. This means, the probability of the game ‘Zombie Tower Defense’ appearing as the first search result is very high, because the search query indexes everything from title, to short description and long description.

Assuming the editor-in-charge typed in enough metadata containing these 3 keywords, it would easily be more keyword-dense than all other zombie games of different genres, pushing it right to the top.


sort_options = search.SortOptions(match_scorer=search.MatchScorer())

search_query = search.Query(
query_string=querystring,
options=search.QueryOptions(
limit=10,
sort_options=sort_options,
))
search_results = index.search(search_query)