Query Re-Ranking
Query Re-Ranking allows you to run a simple query (A) for matching documents and then re-rank the top N documents using the scores from a more complex query (B).
Since the more costly ranking from query B is only applied to the top N documents, it will have less impact on performance then just using the complex query B by itself. The trade off is that documents which score very low using the simple query A may not be considered during the re-ranking phase, even if they would score very highly using query B.
Specifying a Ranking Query
A Ranking query can be specified using the rq
request parameter.
The rq
parameter must specify a query string that when parsed, produces a RankQuery.
Three rank queries are currently included in the Solr distribution. You can also configure a custom QParserPlugin you have written, but most users can just use a parser provided with Solr.
Parser | QParserPlugin class |
---|---|
rerank |
|
xport |
|
ltr |
LTRQParserPlugin |
ReRank Query Parser
The rerank
parser wraps a query specified by an local parameter, along with additional parameters indicating how many documents should be re-ranked, and how the final scores should be computed:
reRankQuery
-
Required
Default: none
The query string for your complex ranking query - in most cases a variable will be used to refer to another request parameter.
reRankDocs
-
Optional
Default:
200
The number of top N documents from the original query that should be re-ranked. This number will be treated as a minimum, and may be increased internally automatically in order to rank enough documents to satisfy the query (i.e., start+rows).
reRankWeight
-
Optional
Default:
2.0
A multiplicative factor that will be applied to the score from the reRankQuery for each of the top matching documents, before that score is added to the original score.
In the example below, the top 1000 documents matching the query "greetings" will be re-ranked using the query "(hi hello hey hiya)". The resulting scores for each of those 1000 documents will be 3 times their score from the "(hi hello hey hiya)", plus the score from the original "greetings" query:
q=greetings&rq={!rerank reRankQuery=$rqq reRankDocs=1000 reRankWeight=3}&rqq=(hi+hello+hey+hiya)
If a document matches the original query, but does not match the re-ranking query, the document’s original score will remain.
LTR Query Parser
The ltr
stands for Learning To Rank, please see Learning To Rank for more detailed information.
Combining Ranking Queries with Other Solr Features
The rq
parameter and the re-ranking feature in general works well with other Solr features.
For example, it can be used in conjunction with Collapse and Expand Results to re-rank the group heads after they’ve been collapsed.
It also preserves the order of documents elevated by the Query Elevation Component.
And it even has its own custom explain so you can see how the re-ranking scores were derived when looking at debug information.