0

I have framed query to submit to solr which is of following format.

id:95154 OR id:68209 OR id:89482 OR id:94233 OR id:112481 OR id:93843

i want to get records according to order from starting. say i need to get document with id 95154 document first then id 68209 next and so on. but its not happening right now its giving last id 93843 first and some times random.i am using solr in grails 2.1 and my solr version is 1.4.0. here is sample way i am getting documents from solr

def server = solrService.getServer('provider')
            SolrQuery sponsorSolrQuery = new SolrQuery(solarQuery)
            def queryResponse = server.query(sponsorSolrQuery);
            documentsList = queryResponse.getResults()
kiran reddy
  • 128
  • 2
  • 14
  • 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:06

2 Answers2

1

As @injecteer mentions, there is nothing built-in to Lucene to consider the sequence of clauses in a boolean query, but:

You are able to apply boosts to each term, and as long as the field is a basic field (meaning, not a TextField), the boosts will apply cleanly to give you a decent sort by score.

id:95154^6 OR id:68209^5 OR id:89482^4 OR id:94233^3 OR id:112481^2 OR id:93843
MatsLindh
  • 49,529
  • 4
  • 53
  • 84
0

there's no such thing in Lucene (I strongly assume, that in Solr as well). In Lucene you can sort the results based on contents of documents' fields, but not on the order of clauses in a query.

that means, that you have to sort the results yourself:

documentsList = queryResponse.getResults()
def sordedByIdOrder = solarQueryAsList.collect{ id -> documentList.find{ it.id == id } }
injecteer
  • 20,038
  • 4
  • 45
  • 89