Solr search results and retrieving position of document
I have a solr index accessed using SolrNet, and I would like to retrieve the index (position) of a particular document in the results, without returning the whole result set.
In more detail... the query returns ~30,000 documents and is ordered by an integer field. The unique key field contains a 开发者_如何学运维Guid, and I would like to find where in the results a particular document is, based on the unique key, while only returning the first 10 results.
This index was originally implemented in plain old Lucene, and this task was achieved with two queries, one to get the lucene doc id of the document I want to know about, then a second that returns the whole result set. I can then use the doc id to find where the document appears in the full result set, but then only enumerate the documents for the first 10.
Is there a way to achieve what I'm after with Solr, without returning all 30000 results (even limiting this to the Guid only seems too slow)?
Thanks
I think you can do with a range query, including your user point's as lower level you can get the number of users above. You can do an explicit query or get that info using the facet range approach.
so, if you know that you user point is 10.000, you could do a query: game:tetris points[MaxInt TO 10000], and if the result is 375 you would know that your user is in rank 375.
The only reliable way I can think of is building the ranking at index-time, i.e. have a "rank" integer field and populate it when you build the index. The downside of this is that every update requires rebuilding the whole index.
Lucene doc ids are not stable, I wouldn't recommend using them for this (see this, this, this), and Solr does not expose them anyway.
精彩评论