Hi. The problem is that although sorting by score a match with a lower score is ranked before a match with a greater score. The origin of the problem lies in a subclass of CustomScoreQuery which calculates an "only once" score for each document: on the first pass the document gets its score and, if the document contains several times the same field, on the subsequent passes it gets 0. I wonder if it is possible for Lucene to give a score that depends on a previous pass in the CustomScoreProvider customScore routine for the same document. I ran 2 searches with IndexSearcher: the first one returns a TopDocs which is sorted by default by relevance, and the second search - with the Sort array = [SortField.FIELD_SCORE, a date SortField] argument - returns a TopFieldDocs. The TopDocs results are sorted by the score with the first pass value of the only once method while the TopFieldDocs results are sorted by the score with the value (= 0) of the next pass, hence the ranking errors. I did not find why does the TopFieldDocs search not use to sort the score of the hit, as the TopDocs search? I did not find how to tell the TopFieldDocs search to use the hit score to sort.
Claude Lepère