In my last blog, I discussed Solr’s new RankQuery capability, which allows developers to take full control of the ranking process. The new ReRankingQParserPlugin leverages the RankQuery framework to hook in Lucene’s new QueryRescorer.
Query Re-Ranking Explained:
Solr offers a wide range of very powerful relevance features. But often as relevance strategies become more complex and powerful, they also tend to be more costly to execute at query time. This is particularly true when dealing with large result sets because each document in the result set must be scored.
Query re-Ranking allows you to run a query with a less costly relevance algorithm and then re-rank the top N documents by a more costly algorithm. Since the more costly ranking algorithm only needs to be applied to the top N documents it will have less impact on performance.
Here is how the new ReRankQParserPlugin works:
q=hello+world&rq={!rerank reRankQuery=$rqq reRankDocs=1000 reRankWeight=3}
If you’ve read my blog on RankQueries then this syntax will be somewhat familiar to you. The “rq” parameter is the syntax for using RankQueries. In this case the “rq” parameter is pointing to the ReRankingQParserPlugin.
This plugin takes three parameters:
reRankQuery: This can be any valid Solr query that will be used to re-rank the top N documents.
reRankDocs: This is the number of documents to re-rank.
reRankWeight: This is the weight to be applied to the re-rank score for each document.
The ReRankingQParserPlugin works well with other Solr features. For example it can be used in conjunction with the CollapsingQParserPlugin, to re-rank the group heads after they’ve been collapsed. It also preserves the order of documents elevated by the QueryElevationComponent. And it even has it’s own custom explain so you can see how the re-ranking scores were derived if you use debugQuery.