javanna commented on a change in pull request #635: URL: https://github.com/apache/lucene/pull/635#discussion_r797016249
########## File path: lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestIndexSortSortedNumericDocValuesRangeQuery.java ########## @@ -450,6 +458,56 @@ public void testIndexSortOptimizationDeactivated(RandomIndexWriter writer) throw reader.close(); } + public void testCount() throws IOException { + Directory dir = newDirectory(); + IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random())); + Sort indexSort = new Sort(new SortedNumericSortField("field", SortField.Type.LONG)); + iwc.setIndexSort(indexSort); + RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc); + Document doc = new Document(); + doc.add(new SortedNumericDocValuesField("field", 10)); + writer.addDocument(doc); + IndexReader reader = writer.getReader(); + IndexSearcher searcher = newSearcher(reader); + + Query fallbackQuery = LongPoint.newRangeQuery("field", 1, 42); + Query query = new IndexSortSortedNumericDocValuesRangeQuery("field", 1, 42, fallbackQuery); + Weight weight = query.createWeight(searcher, ScoreMode.COMPLETE, 1.0f); + for (LeafReaderContext context : searcher.getLeafContexts()) { + assertNotEquals(-1, weight.count(context)); + } + + writer.close(); + reader.close(); + dir.close(); + } + + public void testFallbackCount() throws IOException { + Directory dir = newDirectory(); + IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random())); + Sort indexSort = new Sort(new SortedNumericSortField("field", SortField.Type.LONG)); + iwc.setIndexSort(indexSort); + RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc); + Document doc = new Document(); + doc.add(new SortedNumericDocValuesField("field", 10)); + writer.addDocument(doc); + IndexReader reader = writer.getReader(); + IndexSearcher searcher = newSearcher(reader); + + // we use an unrealistic query that exposes its own Weight#count + Query fallbackQuery = new MatchNoDocsQuery(); + // the index is not sorted on this field, the fallback query is used + Query query = new IndexSortSortedNumericDocValuesRangeQuery("another", 1, 42, fallbackQuery); + Weight weight = query.createWeight(searcher, ScoreMode.COMPLETE, 1.0f); + for (LeafReaderContext context : searcher.getLeafContexts()) { + assertNotEquals(-1, weight.count(context)); Review comment: you're right. I was initially hesitant on this because I was maybe planning to index more documents, then I could end up with more segments hence asserting on exact count could get more complicated. But if we keep a single doc we should be good and it's good to have a more precise check that also differs for the two scenarios. Thanks for your suggestion! -- 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. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org 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