mayya-sharipova commented on a change in pull request #2063: URL: https://github.com/apache/lucene-solr/pull/2063#discussion_r518813515
########## File path: lucene/core/src/test/org/apache/lucene/search/TestFieldSortOptimizationSkipping.java ########## @@ -485,4 +491,249 @@ public void testDocSort() throws IOException { dir.close(); } + public void testNumericSortOptimizationIndexSort() throws IOException { + final Directory dir = newDirectory(); + IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random())); + boolean reverseSort = randomBoolean(); + final SortField sortField = new SortField("field1", SortField.Type.LONG, reverseSort); + Sort indexSort = new Sort(sortField); + iwc.setIndexSort(indexSort); + final IndexWriter writer = new IndexWriter(dir, iwc); + + final int numDocs = atLeast(50); + int[] sortedValues = initializeNumericValues(numDocs, reverseSort, 0); + int[] randomIdxs = randomIdxs(numDocs); + + for (int i = 0; i < numDocs; i++) { + final Document doc = new Document(); + if (sortedValues[randomIdxs[i]] > 0) { + doc.add(new NumericDocValuesField("field1", sortedValues[randomIdxs[i]])); + } + writer.addDocument(doc); + if (i == 30) { + writer.flush(); + } + } + final IndexReader reader = DirectoryReader.open(writer); + writer.close(); + + IndexSearcher searcher = newSearcher(reader); + final int numHits = randomIntBetween(1, numDocs - 10); + final int totalHitsThreshold = randomIntBetween(1, numDocs - 10); + { + // test that optimization is run when search sort is equal to the index sort + TopFieldCollector collector = TopFieldCollector.create(indexSort, numHits, null, totalHitsThreshold); + searcher.search(new MatchAllDocsQuery(), collector); + TopDocs topDocs = collector.topDocs(); + assertTrue(collector.isEarlyTerminated()); Review comment: You are right, they don't distinguish this. The idea that if we remove early termination in TopFieldCollector, these tests should still work. If all this confusing, I can also upgrade this PR to remove early termination in TopFieldCollector. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org