0

I am making a Solr request and passing id of the docs in fq parameter . Solr as expected returns the doc sorted by score of the docs . I want Solr to return docs in the same order as i sent the ids .

So is there a value to sort parameter than i can give to get the desired result .

Evan Root
  • 27
  • 1
  • 4
  • Does this answer your question? [Is it possible in solr to specify an ordering of documents](https://stackoverflow.com/questions/19813548/is-it-possible-in-solr-to-specify-an-ordering-of-documents) – Ahmad Abdelghany Oct 17 '22 at 12:03

2 Answers2

0

Instead of passing to fq. Use elevator component.

Edit elevate.xml file in your solr conf folder and

<query text="ipod">
   <doc id="S03" /> 
   <doc id="S01" />  
   <doc id="S02" /> 
 </query>

irrespective of solr score value, it returns docs in order how you given in elevate.xml file.

OR

Use bq (Boosting) parameter with edismax. example:

defType=edismax&q="ipod"&bq=id:S03^4+id:S02^3+id:S01^
Vinod
  • 1,965
  • 1
  • 9
  • 18
0

The default sort order - if no sort is provided and all scores are similar (or using just fq's - should be the internal Lucene ID - meaning you should get the documents back in the order they're added.

You can ask for this explicitly by using sort=_docid_ asc.

But if this is really important - as documents will get reordered if updated and you might want to keep the original sorting order, add a field to keep track of the time when the document was added and sort by that field.

MatsLindh
  • 49,529
  • 4
  • 53
  • 84
  • That is useful info but the ask is to preserve the order of ids specified in `fq` regardless of when the documents were added/updated. – Ahmad Abdelghany Oct 14 '22 at 10:28
  • 1
    That depends on your interpretation of "same order as I sent the ids". If you want them ordered by the order in the query, refer to https://stackoverflow.com/questions/25807256/how-to-get-solr-results-in-given-order-specified-in-query/25816214#25816214 – MatsLindh Oct 14 '22 at 13:29