Ranking or position of a solr document in search r

2019-07-16 04:13发布

问题:

I need to list the ranking (or position, as you might prefer) or each document after a query in solr. the thing i wanna see is something like this:

<doc>
    <int name="field1">1</int>
    <str name="someotherfield">blabla</str>
    <int name="position">1</int>
</doc>
<doc>
    <int name="field1">2</int>
    <str name="someotherfield">blabla</str>
    <int name="position">2</int>
</doc>
<doc>
    <int name="field1">3</int>
    <str name="someotherfield">blabla</str>
    <int name="position">3</int>
</doc>

is this possible? or i need to implement or find a plugin?

回答1:

well after digging the source code, I am now able to see dynamic positions for each different search.. I have simply added a position function to DocIterator and implemented in in subclasses. Then I have added a control block in ReturnFields for checking if fl has position in it. It is working in a similar way with score. and the last thing to do was adding a custom augmenter class like PositionAugmenter - similar to ScoreAugmenter. Then I am done :)

thank you for David Faber for giving me idea of dealing with the results of raw XML



回答2:

List a field position (among other things) in results:

...&fl=field1,field2,position

Sort by position

...&sort=position desc 

Refer them here : http://wiki.apache.org/solr/CommonQueryParameters#sort