Solr search results and retrieving position of document

痴心易碎 提交于 2019-12-05 04:39:52

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/4594218/solr-search-results-and-retrieving-position-of-document

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!