Apache Lucene open-source search software
LUCENE-7872: TopDocs.totalHits is now a long.
Adrien Grand44d1f1fe3fe2
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 1f53d682f98..d695310e047 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -74,6 +74,8 @@ API Changeswas optimized to work directly instead of being implemented on getFields.(David Smiley)+* LUCENE-7872: TopDocs.totalHits is now a long. (Adrien Grand, hossman)+Bug Fixes* LUCENE-7626: IndexWriter will no longer accept broken token offsetsdiff --git a/lucene/MIGRATE.txt b/lucene/MIGRATE.txtindex 117b49c7999..10ce4bc5b38 100644--- a/lucene/MIGRATE.txt+++ b/lucene/MIGRATE.txt@@ -121,3 +121,13 @@ use TopGroupsCollector.Support for legacy numerics has been removed since legacy numerics had beendeprecated since Lucene 6.0. Points should be used instead, seeorg.apache.lucene.index.PointValues for an introduction.++## TopDocs.totalHits is now a long (LUCENE-7872)++TopDocs.totalHits is now a long so that TopDocs instances can be used to+represent top hits that have more than 2B matches. This is necessary for the+case that multiple TopDocs instances are merged together with TopDocs#merge as+they might have more than 2B matches in total. However TopDocs instances+returned by IndexSearcher will still have a total number of hits which is less+than 2B since Lucene indexes are still bound to at most 2B documents, so it+can safely be casted to an int in that case.diff --git a/lucene/classification/src/java/org/apache/lucene/classification/utils/DatasetSplitter.java b/lucene/classification/src/java/org/apache/lucene/classification/utils/DatasetSplitter.javaindex 913fb7f9be7..d75daf9c799 100644--- a/lucene/classification/src/java/org/apache/lucene/classification/utils/DatasetSplitter.java+++ b/lucene/classification/src/java/org/apache/lucene/classification/utils/DatasetSplitter.java@@ -122,7 +122,7 @@ public class DatasetSplitter {// iterate over existing documentsfor (GroupDocs<Object> group : topGroups.groups) {- int totalHits = group.totalHits;+ long totalHits = group.totalHits;double testSize = totalHits * testRatio;int tc = 0;double cvSize = totalHits * crossValidationRatio;diff --git a/lucene/core/src/java/org/apache/lucene/search/TopDocs.java b/lucene/core/src/java/org/apache/lucene/search/TopDocs.javaindex 3b66fca61bc..c1a4ca64df5 100644--- a/lucene/core/src/java/org/apache/lucene/search/TopDocs.java+++ b/lucene/core/src/java/org/apache/lucene/search/TopDocs.java@@ -23,7 +23,7 @@ import org.apache.lucene.util.PriorityQueue;public class TopDocs {/** The total number of hits for the query. */- public int totalHits;+ public long totalHits;/** The top hits for the query. */public ScoreDoc[] scoreDocs;@@ -45,11 +45,11 @@ public class TopDocs {}/** Constructs a TopDocs with a default maxScore=Float.NaN. */- TopDocs(int totalHits, ScoreDoc[] scoreDocs) {+ TopDocs(long totalHits, ScoreDoc[] scoreDocs) {this(totalHits, scoreDocs, Float.NaN);}- public TopDocs(int totalHits, ScoreDoc[] scoreDocs, float maxScore) {+ public TopDocs(long totalHits, ScoreDoc[] scoreDocs, float maxScore) {this.totalHits = totalHits;this.scoreDocs = scoreDocs;this.maxScore = maxScore;@@ -266,7 +266,7 @@ public class TopDocs {queue = new MergeSortQueue(sort, shardHits);}- int totalHitCount = 0;+ long totalHitCount = 0;int availHitCount = 0;float maxScore = Float.MIN_VALUE;for(int shardIDX=0;shardIDX<shardHits.length;shardIDX++) {diff --git a/lucene/core/src/java/org/apache/lucene/search/TopFieldDocs.java b/lucene/core/src/java/org/apache/lucene/search/TopFieldDocs.javaindex af187f375dc..52a51b7cb96 100644--- a/lucene/core/src/java/org/apache/lucene/search/TopFieldDocs.java+++ b/lucene/core/src/java/org/apache/lucene/search/TopFieldDocs.java@@ -32,7 +32,7 @@ public class TopFieldDocs extends TopDocs {* @param fields The sort criteria used to find the top hits.* @param maxScore The maximum score encountered.*/- public TopFieldDocs (int totalHits, ScoreDoc[] scoreDocs, SortField[] fields, float maxScore) {+ public TopFieldDocs (long totalHits, ScoreDoc[] scoreDocs, SortField[] fields, float maxScore) {super (totalHits, scoreDocs, maxScore);this.fields = fields;}diff --git a/lucene/core/src/test/org/apache/lucene/index/Test2BTerms.java b/lucene/core/src/test/org/apache/lucene/index/Test2BTerms.javaindex 22d12346d4e..2e962b68db7 100644--- a/lucene/core/src/test/org/apache/lucene/index/Test2BTerms.java+++ b/lucene/core/src/test/org/apache/lucene/index/Test2BTerms.java@@ -261,7 +261,7 @@ public class Test2BTerms extends LuceneTestCase {final BytesRef term = terms.get(random().nextInt(terms.size()));System.out.println("TEST: search " + term);final long t0 = System.currentTimeMillis();- final int count = s.search(new TermQuery(new Term("field", term)), 1).totalHits;+ final long count = s.search(new TermQuery(new Term("field", term)), 1).totalHits;if (count <= 0) {System.out.println(" FAILED: count=" + count);failed = true;diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterDelete.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterDelete.javaindex 25817d9a2e8..975f5f072f8 100644--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterDelete.java+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterDelete.java@@ -76,7 +76,7 @@ public class TestIndexWriterDelete extends LuceneTestCase {modifier.commit();Term term = new Term("city", "Amsterdam");- int hitCount = getHitCount(dir, term);+ long hitCount = getHitCount(dir, term);assertEquals(1, hitCount);if (VERBOSE) {System.out.println("\nTEST: now delete by term=" + term);@@ -177,7 +177,7 @@ public class TestIndexWriterDelete extends LuceneTestCase {IndexReader reader = DirectoryReader.open(dir);assertEquals(1, reader.numDocs());- int hitCount = getHitCount(dir, new Term("id", String.valueOf(id)));+ long hitCount = getHitCount(dir, new Term("id", String.valueOf(id)));assertEquals(1, hitCount);reader.close();modifier.close();@@ -470,10 +470,10 @@ public class TestIndexWriterDelete extends LuceneTestCase {modifier.addDocument(doc);}- private int getHitCount(Directory dir, Term term) throws IOException {+ private long getHitCount(Directory dir, Term term) throws IOException {IndexReader reader = DirectoryReader.open(dir);IndexSearcher searcher = newSearcher(reader);- int hitCount = searcher.search(new TermQuery(term), 1000).totalHits;+ long hitCount = searcher.search(new TermQuery(term), 1000).totalHits;reader.close();return hitCount;}@@ -802,7 +802,7 @@ public class TestIndexWriterDelete extends LuceneTestCase {// one of the two files hitsTerm term = new Term("city", "Amsterdam");- int hitCount = getHitCount(dir, term);+ long hitCount = getHitCount(dir, term);assertEquals(1, hitCount);// open the writer again (closed above)diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterReader.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterReader.javaindex 584e03cd71a..f8abc82e80c 100644--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterReader.java+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterReader.java@@ -768,7 +768,7 @@ public class TestIndexWriterReader extends LuceneTestCase {threads[i].start();}- int lastCount = 0;+ long lastCount = 0;while(threadDone.get() == false) {DirectoryReader r2 = DirectoryReader.openIfChanged(r);if (r2 != null) {@@ -776,7 +776,7 @@ public class TestIndexWriterReader extends LuceneTestCase {r = r2;Query q = new TermQuery(new Term("indexname", "test"));IndexSearcher searcher = newSearcher(r);- final int count = searcher.search(q, 10).totalHits;+ final long count = searcher.search(q, 10).totalHits;assertTrue(count >= lastCount);lastCount = count;}@@ -793,7 +793,7 @@ public class TestIndexWriterReader extends LuceneTestCase {}Query q = new TermQuery(new Term("indexname", "test"));IndexSearcher searcher = newSearcher(r);- final int count = searcher.search(q, 10).totalHits;+ final long count = searcher.search(q, 10).totalHits;assertTrue(count >= lastCount);assertEquals(0, excs.size());diff --git a/lucene/core/src/test/org/apache/lucene/index/TestManyFields.java b/lucene/core/src/test/org/apache/lucene/index/TestManyFields.javaindex 9b2f732649c..bcb8cd896e9 100644--- a/lucene/core/src/test/org/apache/lucene/index/TestManyFields.java+++ b/lucene/core/src/test/org/apache/lucene/index/TestManyFields.java@@ -107,7 +107,7 @@ public class TestManyFields extends LuceneTestCase {IndexReader reader = DirectoryReader.open(dir);IndexSearcher searcher = newSearcher(reader);- int totalHits = searcher.search(new TermQuery(new Term("field", "aaa")), 1).totalHits;+ long totalHits = searcher.search(new TermQuery(new Term("field", "aaa")), 1).totalHits;assertEquals(n*100, totalHits);reader.close();diff --git a/lucene/core/src/test/org/apache/lucene/search/TestAutomatonQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestAutomatonQuery.javaindex 3da69f08219..cfb1f5bd555 100644--- a/lucene/core/src/test/org/apache/lucene/search/TestAutomatonQuery.java+++ b/lucene/core/src/test/org/apache/lucene/search/TestAutomatonQuery.java@@ -85,7 +85,7 @@ public class TestAutomatonQuery extends LuceneTestCase {return new Term(FN, value);}- private int automatonQueryNrHits(AutomatonQuery query) throws IOException {+ private long automatonQueryNrHits(AutomatonQuery query) throws IOException {if (VERBOSE) {System.out.println("TEST: run aq=" + query);}diff --git a/lucene/core/src/test/org/apache/lucene/search/TestAutomatonQueryUnicode.java b/lucene/core/src/test/org/apache/lucene/search/TestAutomatonQueryUnicode.javaindex 2af30985325..48170368aea 100644--- a/lucene/core/src/test/org/apache/lucene/search/TestAutomatonQueryUnicode.java+++ b/lucene/core/src/test/org/apache/lucene/search/TestAutomatonQueryUnicode.java@@ -94,7 +94,7 @@ public class TestAutomatonQueryUnicode extends LuceneTestCase {return new Term(FN, value);}- private int automatonQueryNrHits(AutomatonQuery query) throws IOException {+ private long automatonQueryNrHits(AutomatonQuery query) throws IOException {return searcher.search(query, 5).totalHits;}diff --git a/lucene/core/src/test/org/apache/lucene/search/TestBooleanOr.java b/lucene/core/src/test/org/apache/lucene/search/TestBooleanOr.javaindex 4e232c488df..e95ffa44e24 100644--- a/lucene/core/src/test/org/apache/lucene/search/TestBooleanOr.java+++ b/lucene/core/src/test/org/apache/lucene/search/TestBooleanOr.java@@ -51,7 +51,7 @@ public class TestBooleanOr extends LuceneTestCase {private IndexReader reader;- private int search(Query q) throws IOException {+ private long search(Query q) throws IOException {QueryUtils.check(random(), q,searcher);return searcher.search(q, 1000).totalHits;}diff --git a/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java b/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.javaindex 4e80f9e9ed0..e13f9e077f2 100644--- a/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java+++ b/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java@@ -142,7 +142,7 @@ public class TestLRUQueryCache extends LuceneTestCase {TotalHitCountCollector collector = new TotalHitCountCollector();searcher.search(q, collector); // will use the cachefinal int totalHits1 = collector.getTotalHits();- final int totalHits2 = searcher.search(q, 1).totalHits; // will not use the cache because of scores+ final long totalHits2 = searcher.search(q, 1).totalHits; // will not use the cache because of scoresassertEquals(totalHits2, totalHits1);} finally {mgr.release(searcher);diff --git a/lucene/core/src/test/org/apache/lucene/search/TestRegexpQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestRegexpQuery.javaindex 505b26ff914..ad1319b5c1b 100644--- a/lucene/core/src/test/org/apache/lucene/search/TestRegexpQuery.java+++ b/lucene/core/src/test/org/apache/lucene/search/TestRegexpQuery.java@@ -68,7 +68,7 @@ public class TestRegexpQuery extends LuceneTestCase {return new Term(FN, value);}- private int regexQueryNrHits(String regex) throws IOException {+ private long regexQueryNrHits(String regex) throws IOException {RegexpQuery query = new RegexpQuery(newTerm(regex));return searcher.search(query, 5).totalHits;}diff --git a/lucene/core/src/test/org/apache/lucene/search/TestTermRangeQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestTermRangeQuery.javaindex 97b04056f97..be59eb98995 100644--- a/lucene/core/src/test/org/apache/lucene/search/TestTermRangeQuery.java+++ b/lucene/core/src/test/org/apache/lucene/search/TestTermRangeQuery.java@@ -271,7 +271,7 @@ public class TestTermRangeQuery extends LuceneTestCase {initializeIndex(new String[] {"A", "B", "", "C", "D"}, analyzer);IndexReader reader = DirectoryReader.open(dir);IndexSearcher searcher = newSearcher(reader);- int numHits = searcher.search(query, 1000).totalHits;+ long numHits = searcher.search(query, 1000).totalHits;// When Lucene-38 is fixed, use the assert on the next line:assertEquals("A,B,<empty string>,C,D => A, B & <empty string> are in range", 3, numHits);// until Lucene-38 is fixed, use this assert:@@ -306,7 +306,7 @@ public class TestTermRangeQuery extends LuceneTestCase {initializeIndex(new String[]{"A", "B", "","C", "D"}, analyzer);IndexReader reader = DirectoryReader.open(dir);IndexSearcher searcher = newSearcher(reader);- int numHits = searcher.search(query, 1000).totalHits;+ long numHits = searcher.search(query, 1000).totalHits;// When Lucene-38 is fixed, use the assert on the next line:assertEquals("A,B,<empty string>,C,D => A,B,<empty string>,C in range", 4, numHits);// until Lucene-38 is fixed, use this assertdiff --git a/lucene/core/src/test/org/apache/lucene/search/spans/TestSpans.java b/lucene/core/src/test/org/apache/lucene/search/spans/TestSpans.javaindex 2b5b919f385..4a7125b3ff2 100644--- a/lucene/core/src/test/org/apache/lucene/search/spans/TestSpans.java+++ b/lucene/core/src/test/org/apache/lucene/search/spans/TestSpans.java@@ -333,7 +333,7 @@ public class TestSpans extends LuceneTestCase {}// LUCENE-1404- private int hitCount(IndexSearcher searcher, String word) throws Throwable {+ private long hitCount(IndexSearcher searcher, String word) throws Throwable {return searcher.search(new TermQuery(new Term("text", word)), 10).totalHits;}diff --git a/lucene/demo/src/java/org/apache/lucene/demo/SearchFiles.java b/lucene/demo/src/java/org/apache/lucene/demo/SearchFiles.javaindex 46c75e14675..a7a6fee0314 100644--- a/lucene/demo/src/java/org/apache/lucene/demo/SearchFiles.java+++ b/lucene/demo/src/java/org/apache/lucene/demo/SearchFiles.java@@ -152,7 +152,7 @@ public class SearchFiles {TopDocs results = searcher.search(query, 5 * hitsPerPage);ScoreDoc[] hits = results.scoreDocs;- int numTotalHits = results.totalHits;+ int numTotalHits = Math.toIntExact(results.totalHits);System.out.println(numTotalHits + " total matching documents");int start = 0;diff --git a/lucene/grouping/src/java/org/apache/lucene/search/grouping/GroupDocs.java b/lucene/grouping/src/java/org/apache/lucene/search/grouping/GroupDocs.javaindex 48f12aa5717..a2213d9a526 100644--- a/lucene/grouping/src/java/org/apache/lucene/search/grouping/GroupDocs.java+++ b/lucene/grouping/src/java/org/apache/lucene/search/grouping/GroupDocs.java@@ -39,7 +39,7 @@ public class GroupDocs<T> {public final ScoreDoc[] scoreDocs;/** Total hits within this group */- public final int totalHits;+ public final long totalHits;/** Matches the groupSort passed to {@link* FirstPassGroupingCollector}. */@@ -47,7 +47,7 @@ public class GroupDocs<T> {public GroupDocs(float score,float maxScore,- int totalHits,+ long totalHits,ScoreDoc[] scoreDocs,T groupValue,Object[] groupSortValues) {diff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/classic/TestQueryParser.java b/lucene/queryparser/src/test/org/apache/lucene/queryparser/classic/TestQueryParser.javaindex 17107fc6c03..6b1a6aad61b 100644--- a/lucene/queryparser/src/test/org/apache/lucene/queryparser/classic/TestQueryParser.java+++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/classic/TestQueryParser.java@@ -942,7 +942,7 @@ public class TestQueryParser extends QueryParserTestBase {DirectoryReader ir = DirectoryReader.open(ramDir);IndexSearcher is = new IndexSearcher(ir);- int hits = is.search(q, 10).totalHits;+ long hits = is.search(q, 10).totalHits;ir.close();ramDir.close();if (hits == 1){diff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestCoreParser.java b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestCoreParser.javaindex 8f07c4a100a..11ffda628ba 100644--- a/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestCoreParser.java+++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestCoreParser.java@@ -105,7 +105,7 @@ public class TestCoreParser extends LuceneTestCase {public void testCustomFieldUserQueryXML() throws ParserException, IOException {Query q = parse("UserInputQueryCustomField.xml");- int h = searcher().search(q, 1000).totalHits;+ long h = searcher().search(q, 1000).totalHits;assertEquals("UserInputQueryCustomField should produce 0 result ", 0, h);}diff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestQueryTemplateManager.java b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestQueryTemplateManager.javaindex 4c2e34adddf..5ee693f11dc 100644--- a/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestQueryTemplateManager.java+++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestQueryTemplateManager.java@@ -93,7 +93,7 @@ public class TestQueryTemplateManager extends LuceneTestCase {Query q = builder.getQuery(doc.getDocumentElement());//Run the query- int h = searcher.search(q, 1000).totalHits;+ long h = searcher.search(q, 1000).totalHits;//Check we have the expected number of resultsint expectedHits = Integer.parseInt(queryFormProperties.getProperty("expectedMatches"));diff --git a/lucene/replicator/src/test/org/apache/lucene/replicator/nrt/SimpleReplicaNode.java b/lucene/replicator/src/test/org/apache/lucene/replicator/nrt/SimpleReplicaNode.javaindex c394c659627..874b5685dcb 100644--- a/lucene/replicator/src/test/org/apache/lucene/replicator/nrt/SimpleReplicaNode.java+++ b/lucene/replicator/src/test/org/apache/lucene/replicator/nrt/SimpleReplicaNode.java@@ -212,7 +212,7 @@ class SimpleReplicaNode extends ReplicaNode {IndexSearcher searcher = mgr.acquire();try {long version = ((DirectoryReader) searcher.getIndexReader()).getVersion();- int hitCount = searcher.search(new TermQuery(new Term("body", "the")), 1).totalHits;+ int hitCount = searcher.count(new TermQuery(new Term("body", "the")));//node.message("version=" + version + " searcher=" + searcher);out.writeVLong(version);out.writeVInt(hitCount);@@ -229,7 +229,7 @@ class SimpleReplicaNode extends ReplicaNode {IndexSearcher searcher = mgr.acquire();try {long version = ((DirectoryReader) searcher.getIndexReader()).getVersion();- int hitCount = searcher.search(new MatchAllDocsQuery(), 1).totalHits;+ int hitCount = searcher.count(new MatchAllDocsQuery());//node.message("version=" + version + " searcher=" + searcher);out.writeVLong(version);out.writeVInt(hitCount);diff --git a/lucene/spatial-extras/src/test/org/apache/lucene/spatial/SpatialExample.java b/lucene/spatial-extras/src/test/org/apache/lucene/spatial/SpatialExample.javaindex 76e0200f26b..1faae214c4a 100644--- a/lucene/spatial-extras/src/test/org/apache/lucene/spatial/SpatialExample.java+++ b/lucene/spatial-extras/src/test/org/apache/lucene/spatial/SpatialExample.java@@ -190,7 +190,7 @@ public class SpatialExample extends LuceneTestCase {}private void assertDocMatchedIds(IndexSearcher indexSearcher, TopDocs docs, int... ids) throws IOException {- int[] gotIds = new int[docs.totalHits];+ int[] gotIds = new int[Math.toIntExact(docs.totalHits)];for (int i = 0; i < gotIds.length; i++) {gotIds[i] = indexSearcher.doc(docs.scoreDocs[i].doc).getField("id").numericValue().intValue();}diff --git a/lucene/spatial-extras/src/test/org/apache/lucene/spatial/SpatialTestCase.java b/lucene/spatial-extras/src/test/org/apache/lucene/spatial/SpatialTestCase.javaindex 9f4ba0271b9..0b268d9f6e7 100644--- a/lucene/spatial-extras/src/test/org/apache/lucene/spatial/SpatialTestCase.java+++ b/lucene/spatial-extras/src/test/org/apache/lucene/spatial/SpatialTestCase.java@@ -205,10 +205,10 @@ public abstract class SpatialTestCase extends LuceneTestCase {protected static class SearchResults {- public int numFound;+ public long numFound;public List<SearchResult> results;- public SearchResults(int numFound, List<SearchResult> results) {+ public SearchResults(long numFound, List<SearchResult> results) {this.numFound = numFound;this.results = results;}diff --git a/lucene/suggest/src/test/org/apache/lucene/search/suggest/document/TestSuggestField.java b/lucene/suggest/src/test/org/apache/lucene/search/suggest/document/TestSuggestField.javaindex 3efb50d4976..a797ca5f1be 100644--- a/lucene/suggest/src/test/org/apache/lucene/search/suggest/document/TestSuggestField.java+++ b/lucene/suggest/src/test/org/apache/lucene/search/suggest/document/TestSuggestField.java@@ -126,7 +126,7 @@ public class TestSuggestField extends LuceneTestCase {SuggestIndexSearcher suggestIndexSearcher = new SuggestIndexSearcher(reader);PrefixCompletionQuery query = new PrefixCompletionQuery(analyzer, new Term("suggest_field", "ab"));TopSuggestDocs lookupDocs = suggestIndexSearcher.suggest(query, 3, false);- assertThat(lookupDocs.totalHits, equalTo(0));+ assertThat(lookupDocs.totalHits, equalTo(0L));reader.close();iw.close();}@@ -470,7 +470,7 @@ public class TestSuggestField extends LuceneTestCase {// calling suggest with filter that does not match any documents should early terminatePrefixCompletionQuery query = new PrefixCompletionQuery(analyzer, new Term("suggest_field", "abc_"), filter);TopSuggestDocs suggest = indexSearcher.suggest(query, num, false);- assertThat(suggest.totalHits, equalTo(0));+ assertThat(suggest.totalHits, equalTo(0L));reader.close();iw.close();}@@ -498,7 +498,7 @@ public class TestSuggestField extends LuceneTestCase {SuggestIndexSearcher indexSearcher = new SuggestIndexSearcher(reader);PrefixCompletionQuery query = new PrefixCompletionQuery(analyzer, new Term("suggest_field", "abc_"));TopSuggestDocs suggest = indexSearcher.suggest(query, num, false);- assertThat(suggest.totalHits, equalTo(0));+ assertThat(suggest.totalHits, equalTo(0L));reader.close();iw.close();diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.javaindex fa9d51081b3..3d9700493e6 100644--- a/lucene/test-framework/src/java/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java+++ b/lucene/test-framework/src/java/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java@@ -31,6 +31,7 @@ import java.util.concurrent.Executors;import java.util.concurrent.TimeUnit;import java.util.concurrent.atomic.AtomicBoolean;import java.util.concurrent.atomic.AtomicInteger;+import java.util.concurrent.atomic.AtomicLong;import org.apache.lucene.analysis.MockAnalyzer;import org.apache.lucene.document.Document;@@ -323,7 +324,7 @@ public abstract class ThreadedIndexingAndSearchingTestCase extends LuceneTestCasprotected void runSearchThreads(final long stopTimeMS) throws Exception {final int numThreads = TestUtil.nextInt(random(), 1, 5);final Thread[] searchThreads = new Thread[numThreads];- final AtomicInteger totHits = new AtomicInteger();+ final AtomicLong totHits = new AtomicLong();// silly starting guess:final AtomicInteger totTermCount = new AtomicInteger(100);@@ -664,11 +665,11 @@ public abstract class ThreadedIndexingAndSearchingTestCase extends LuceneTestCas}}- private int runQuery(IndexSearcher s, Query q) throws Exception {+ private long runQuery(IndexSearcher s, Query q) throws Exception {s.search(q, 10);- int hitCount = s.search(q, 10, new Sort(new SortField("titleDV", SortField.Type.STRING))).totalHits;+ long hitCount = s.search(q, 10, new Sort(new SortField("titleDV", SortField.Type.STRING))).totalHits;final Sort dvSort = new Sort(new SortField("titleDV", SortField.Type.STRING));- int hitCount2 = s.search(q, 10, dvSort).totalHits;+ long hitCount2 = s.search(q, 10, dvSort).totalHits;assertEquals(hitCount, hitCount2);return hitCount;}diff --git a/solr/contrib/ltr/src/java/org/apache/solr/ltr/LTRRescorer.java b/solr/contrib/ltr/src/java/org/apache/solr/ltr/LTRRescorer.javaindex 818d861f06e..33c9a3624ef 100644--- a/solr/contrib/ltr/src/java/org/apache/solr/ltr/LTRRescorer.java+++ b/solr/contrib/ltr/src/java/org/apache/solr/ltr/LTRRescorer.java@@ -110,7 +110,7 @@ public class LTRRescorer extends Rescorer {}});- topN = Math.min(topN, firstPassTopDocs.totalHits);+ topN = Math.toIntExact(Math.min(topN, firstPassTopDocs.totalHits));final ScoreDoc[] reranked = new ScoreDoc[topN];final List<LeafReaderContext> leaves = searcher.getIndexReader().leaves();final LTRScoringQuery.ModelWeight modelWeight = (LTRScoringQuery.ModelWeight) searcherdiff --git a/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java b/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.javaindex 34499356325..9b0805fa4b1 100644--- a/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java+++ b/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java@@ -234,7 +234,7 @@ public class RecoveryStrategy implements Runnable, Closeable {LOG.debug(core.getCoreContainer().getZkController().getNodeName()+ " replicated "- + searcher.search(new MatchAllDocsQuery(), 1).totalHits+ + searcher.count(new MatchAllDocsQuery())+ " from "+ leaderUrl+ " gen:"@@ -781,7 +781,7 @@ public class RecoveryStrategy implements Runnable, Closeable {RefCounted<SolrIndexSearcher> searchHolder = core.getNewestSearcher(false);SolrIndexSearcher searcher = searchHolder.get();try {- final int totalHits = searcher.search(new MatchAllDocsQuery(), 1).totalHits;+ final int totalHits = searcher.count(new MatchAllDocsQuery());final String nodeName = core.getCoreContainer().getZkController().getNodeName();LOG.debug("[{}] {} [{} total hits]", nodeName, op, totalHits);} finally {diff --git a/solr/core/src/java/org/apache/solr/handler/component/SpellCheckComponent.java b/solr/core/src/java/org/apache/solr/handler/component/SpellCheckComponent.javaindex eee36ccce5a..6aba296d657 100644--- a/solr/core/src/java/org/apache/solr/handler/component/SpellCheckComponent.java+++ b/solr/core/src/java/org/apache/solr/handler/component/SpellCheckComponent.java@@ -171,12 +171,12 @@ public class SpellCheckComponent extends SearchComponent implements SolrCoreAwarcustomParams.add(getCustomParams(checkerName, params));}- Integer hitsInteger = (Integer) rb.rsp.getToLog().get("hits");+ Number hitsLong = (Number) rb.rsp.getToLog().get("hits");long hits = 0;- if (hitsInteger == null) {+ if (hitsLong == null) {hits = rb.getNumberDocumentsFound();} else {- hits = hitsInteger.longValue();+ hits = hitsLong.longValue();}SpellingResult spellingResult = null;@@ -543,7 +543,7 @@ public class SpellCheckComponent extends SearchComponent implements SolrCoreAwarNamedList expandedCollation = (NamedList) o;SpellCheckCollation coll = new SpellCheckCollation();coll.setCollationQuery((String) expandedCollation.get("collationQuery"));- coll.setHits((Integer) expandedCollation.get("hits"));+ coll.setHits(((Number) expandedCollation.get("hits")).longValue());if(maxCollationTries>0){coll.setInternalRank((Integer) expandedCollation.get("collationInternalRank"));diff --git a/solr/core/src/java/org/apache/solr/search/DocList.java b/solr/core/src/java/org/apache/solr/search/DocList.javaindex 41f892abc5e..fee2c138b73 100644--- a/solr/core/src/java/org/apache/solr/search/DocList.java+++ b/solr/core/src/java/org/apache/solr/search/DocList.java@@ -45,7 +45,7 @@ public interface DocList extends DocSet {* Hence it's always true that matches() >= size()* @return number of matches for the search(query & any filters)*/- public int matches();+ public long matches();/***diff --git a/solr/core/src/java/org/apache/solr/search/DocSlice.java b/solr/core/src/java/org/apache/solr/search/DocSlice.javaindex 98de307ed21..0b33ae9b194 100644--- a/solr/core/src/java/org/apache/solr/search/DocSlice.java+++ b/solr/core/src/java/org/apache/solr/search/DocSlice.java@@ -36,7 +36,7 @@ public class DocSlice extends DocSetBase implements DocList {final int[] docs; // a slice of documents (docs 0-100 of the query)final float[] scores; // optional score list- final int matches;+ final long matches;final float maxScore;/**@@ -48,7 +48,7 @@ public class DocSlice extends DocSetBase implements DocList {* @param scores array of scores that corresponds to docs, may be null* @param matches total number of matches for the query*/- public DocSlice(int offset, int len, int[] docs, float[] scores, int matches, float maxScore) {+ public DocSlice(int offset, int len, int[] docs, float[] scores, long matches, float maxScore) {this.offset=offset;this.len=len;this.docs=docs;@@ -87,7 +87,7 @@ public class DocSlice extends DocSetBase implements DocList {@Overridepublic int size() { return len; }@Override- public int matches() { return matches; }+ public long matches() { return matches; }@Overridediff --git a/solr/core/src/java/org/apache/solr/search/Grouping.java b/solr/core/src/java/org/apache/solr/search/Grouping.javaindex eeb6b66f82d..245320dc17f 100644--- a/solr/core/src/java/org/apache/solr/search/Grouping.java+++ b/solr/core/src/java/org/apache/solr/search/Grouping.java@@ -605,7 +605,7 @@ public class Grouping {}protected DocList getDocList(GroupDocs groups) {- int max = groups.totalHits;+ int max = Math.toIntExact(groups.totalHits);int off = groupOffset;int len = docsPerGroup;if (format == Format.simple) {diff --git a/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/TopGroupsResultTransformer.java b/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/TopGroupsResultTransformer.javaindex 41145ba6eef..457814c1df7 100644--- a/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/TopGroupsResultTransformer.java+++ b/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/TopGroupsResultTransformer.java@@ -101,7 +101,7 @@ public class TopGroupsResultTransformer implements ShardResultTransformer<List<CString key = entry.getKey();NamedList commandResult = entry.getValue();Integer totalGroupedHitCount = (Integer) commandResult.get("totalGroupedHitCount");- Integer totalHits = (Integer) commandResult.get("totalHits");+ Number totalHits = (Number) commandResult.get("totalHits"); // previously Integer now Longif (totalHits != null) {Integer matches = (Integer) commandResult.get("matches");Float maxScore = (Float) commandResult.get("maxScore");@@ -114,9 +114,9 @@ public class TopGroupsResultTransformer implements ShardResultTransformer<List<CScoreDoc[] scoreDocs = transformToNativeShardDoc(documents, groupSort, shard, schema);final TopDocs topDocs;if (withinGroupSort.equals(Sort.RELEVANCE)) {- topDocs = new TopDocs(totalHits, scoreDocs, maxScore);+ topDocs = new TopDocs(totalHits.longValue(), scoreDocs, maxScore);} else {- topDocs = new TopFieldDocs(totalHits, scoreDocs, withinGroupSort.getSort(), maxScore);+ topDocs = new TopFieldDocs(totalHits.longValue(), scoreDocs, withinGroupSort.getSort(), maxScore);}result.put(key, new QueryCommandResult(topDocs, matches));continue;@@ -129,7 +129,7 @@ public class TopGroupsResultTransformer implements ShardResultTransformer<List<CString groupValue = commandResult.getName(i);@SuppressWarnings("unchecked")NamedList<Object> groupResult = (NamedList<Object>) commandResult.getVal(i);- Integer totalGroupHits = (Integer) groupResult.get("totalHits");+ Number totalGroupHits = (Number) groupResult.get("totalHits"); // // previously Integer now LongFloat maxScore = (Float) groupResult.get("maxScore");if (maxScore == null) {maxScore = Float.NaN;@@ -140,7 +140,7 @@ public class TopGroupsResultTransformer implements ShardResultTransformer<List<CScoreDoc[] scoreDocs = transformToNativeShardDoc(documents, withinGroupSort, shard, schema);BytesRef groupValueRef = groupValue != null ? new BytesRef(groupValue) : null;- groupDocs.add(new GroupDocs<>(Float.NaN, maxScore, totalGroupHits, scoreDocs, groupValueRef, null));+ groupDocs.add(new GroupDocs<>(Float.NaN, maxScore, totalGroupHits.longValue(), scoreDocs, groupValueRef, null));}@SuppressWarnings("unchecked")diff --git a/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollation.java b/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollation.javaindex 7f3bd95080f..77e3f9c9b90 100644--- a/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollation.java+++ b/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollation.java@@ -20,7 +20,7 @@ import org.apache.solr.common.util.NamedList;public class SpellCheckCollation implements Comparable<SpellCheckCollation> {private NamedList<String> misspellingsAndCorrections;- private int hits;+ private long hits;private int internalRank;private String collationQuery;@@ -42,11 +42,11 @@ public class SpellCheckCollation implements Comparable<SpellCheckCollation> {this.misspellingsAndCorrections = misspellingsAndCorrections;}- public int getHits() {+ public long getHits() {return hits;}- public void setHits(int hits) {+ public void setHits(long hits) {this.hits = hits;}diff --git a/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollator.java b/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollator.javaindex 12369f7e4c1..cc388988ff8 100644--- a/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollator.java+++ b/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollator.java@@ -93,7 +93,7 @@ public class SpellCheckCollator {PossibilityIterator.RankedSpellPossibility possibility = possibilityIter.next();String collationQueryStr = getCollation(originalQuery, possibility.corrections);- int hits = 0;+ long hits = 0;if (verifyCandidateWithQuery) {tryNo++;@@ -162,7 +162,7 @@ public class SpellCheckCollator {checkResponse.setFieldFlags(f |= SolrIndexSearcher.TERMINATE_EARLY);}queryComponent.process(checkResponse);- hits = (Integer) checkResponse.rsp.getToLog().get("hits");+ hits = ((Number) checkResponse.rsp.getToLog().get("hits")).longValue();} catch (EarlyTerminatingCollectorException etce) {assert (docCollectionLimit > 0);assert 0 < etce.getNumberScanned();@@ -171,7 +171,7 @@ public class SpellCheckCollator {if (etce.getNumberScanned() == maxDocId) {hits = etce.getNumberCollected();} else {- hits = (int) ( ((float)( maxDocId * etce.getNumberCollected() ))+ hits = (long) ( ((float)( maxDocId * etce.getNumberCollected() ))/ (float)etce.getNumberScanned() );}} catch (Exception e) {diff --git a/solr/core/src/test/org/apache/solr/search/TestRangeQuery.java b/solr/core/src/test/org/apache/solr/search/TestRangeQuery.javaindex 959386a4b2d..6591218024b 100644--- a/solr/core/src/test/org/apache/solr/search/TestRangeQuery.java+++ b/solr/core/src/test/org/apache/solr/search/TestRangeQuery.java@@ -303,7 +303,7 @@ public class TestRangeQuery extends SolrTestCaseJ4 {// now build some random queries (against *any* field) and validate that using it in a DBQ changes// the index by the expected number of docs- int numDocsLeftInIndex = numDocs;+ long numDocsLeftInIndex = numDocs;final int numDBQs= atLeast(10);for (int i=0; i < numDBQs; i++) {int lower = TestUtil.nextInt(random(), 2 * l, u);@@ -337,7 +337,7 @@ public class TestRangeQuery extends SolrTestCaseJ4 {assertU(commit());try (SolrQueryRequest req = req("q","*:*","rows","0","_trace_after_dbq",dbq)) {SolrQueryResponse qr = h.queryAndResponse(handler, req);- final int allDocsFound = ((ResultContext)qr.getResponse()).getDocList().matches();+ final long allDocsFound = ((ResultContext)qr.getResponse()).getDocList().matches();assertEquals(dbq, numDocsLeftInIndex, allDocsFound);}}diff --git a/solr/core/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java b/solr/core/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.javaindex 0833e0674b1..54280448a1b 100644--- a/solr/core/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java+++ b/solr/core/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java@@ -396,8 +396,7 @@ public class SpellCheckCollatorTest extends SolrTestCaseJ4 {assertTrue(!usedcollations.contains(multipleCollation));usedcollations.add(multipleCollation);- int hits = (Integer) expandedCollation.get("hits");- assertTrue(hits == 1);+ assertEquals(new Long(1L), expandedCollation.get("hits"));NamedList misspellingsAndCorrections = (NamedList) expandedCollation.get("misspellingsAndCorrections");assertTrue(misspellingsAndCorrections.size() == 3);@@ -473,7 +472,7 @@ public class SpellCheckCollatorTest extends SolrTestCaseJ4 {*/"//lst[@name='spellcheck']/bool[@name='correctlySpelled']='false'","//lst[@name='spellcheck']/lst[@name='collations']/lst[@name='collation']/str[@name='collationQuery']='teststop:(flew AND from AND heathrow)'",- "//lst[@name='spellcheck']/lst[@name='collations']/lst[@name='collation']/int[@name='hits']=1",+ "//lst[@name='spellcheck']/lst[@name='collations']/lst[@name='collation']/long[@name='hits']=1","//lst[@name='spellcheck']/lst[@name='collations']/lst[@name='collation']/lst[@name='misspellingsAndCorrections']/str[@name='form']='from'");@@ -497,7 +496,7 @@ public class SpellCheckCollatorTest extends SolrTestCaseJ4 {"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='june']/arr[@name='suggestion']/lst/str[@name='word']='jane'","//lst[@name='spellcheck']/bool[@name='correctlySpelled']='false'","//lst[@name='spellcheck']/lst[@name='collations']/lst[@name='collation']/str[@name='collationQuery']='teststop:(jane AND customs)'",- "//lst[@name='spellcheck']/lst[@name='collations']/lst[@name='collation']/int[@name='hits']=1",+ "//lst[@name='spellcheck']/lst[@name='collations']/lst[@name='collation']/long[@name='hits']=1","//lst[@name='spellcheck']/lst[@name='collations']/lst[@name='collation']/lst[@name='misspellingsAndCorrections']/str[@name='june']='jane'");//SOLR-5090, alternativeTermCount==0 was being evaluated, sometimes would throw NPE@@ -529,7 +528,7 @@ public class SpellCheckCollatorTest extends SolrTestCaseJ4 {assertQ(req(reusedParams,CommonParams.Q, "teststop:metnoia"), xpathPrefix + "str[@name='collationQuery']='teststop:metanoia'"- , xpathPrefix + "int[@name='hits']=6"+ , xpathPrefix + "long[@name='hits']=6");// specifying 0 means "exact" same as default, but specifing a value greater@@ -540,7 +539,7 @@ public class SpellCheckCollatorTest extends SolrTestCaseJ4 {CommonParams.Q, "teststop:metnoia",SpellingParams.SPELLCHECK_COLLATE_MAX_COLLECT_DOCS, val), xpathPrefix + "str[@name='collationQuery']='teststop:metanoia'"- , xpathPrefix + "int[@name='hits']=6"+ , xpathPrefix + "long[@name='hits']=6");}@@ -553,7 +552,7 @@ public class SpellCheckCollatorTest extends SolrTestCaseJ4 {CommonParams.Q, "teststop:metnoia",SpellingParams.SPELLCHECK_COLLATE_MAX_COLLECT_DOCS, ""+val), xpathPrefix + "str[@name='collationQuery']='teststop:metanoia'"- , xpathPrefix + "int[@name='hits' and . <= 17 and 0 < .]"+ , xpathPrefix + "long[@name='hits' and . <= 17 and 0 < .]");}@@ -570,7 +569,7 @@ public class SpellCheckCollatorTest extends SolrTestCaseJ4 {CommonParams.Q, "teststop:everother",SpellingParams.SPELLCHECK_COLLATE_MAX_COLLECT_DOCS, ""+val), xpathPrefix + "str[@name='collationQuery']='teststop:everyother'"- , xpathPrefix + "int[@name='hits' and " + min + " <= . and . <= " + max + "]"+ , xpathPrefix + "long[@name='hits' and " + min + " <= . and . <= " + max + "]");}diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/response/SpellCheckResponse.java b/solr/solrj/src/java/org/apache/solr/client/solrj/response/SpellCheckResponse.javaindex 89ef351f136..f8756ccb46f 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/response/SpellCheckResponse.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/response/SpellCheckResponse.java@@ -69,7 +69,7 @@ public class SpellCheckResponse {NamedList<Object> expandedCollation = (NamedList<Object>) o;String collationQuery= (String) expandedCollation.get("collationQuery");- int hits = (Integer) expandedCollation.get("hits");+ long hits = ((Number) expandedCollation.get("hits")).longValue();@SuppressWarnings("unchecked")NamedList<String> misspellingsAndCorrections= (NamedList<String>) expandedCollation.get("misspellingsAndCorrections");