diff --git a/lucene/MIGRATE.txt b/lucene/MIGRATE.txt index 4c146512c39..fc0930ce61a 100644 --- a/lucene/MIGRATE.txt +++ b/lucene/MIGRATE.txt @@ -89,3 +89,11 @@ Computing scores at collection time is less efficient than running a second request in order to only compute scores for documents that made it to the top hits. As a consequence, the trackDocScores option has been removed and can be replaced with the new TopFieldCollector#populateScores helper method. + +## TopDocs.totalHits is no longer a long ## + +Lucene 8 received optimizations for collection of top-k matches by not visiting +all matches. However these optimizations won't help if all matches still need +to be visited in order to compute the total number of hits. As a consequence, +TopDocs.totalHits is now an TotalHits object that is either an exact hit count +or a lower bound of the hit count. diff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/DocMakerTest.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/DocMakerTest.java index c2ead39e4b8..331fd23ee32 100644 --- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/DocMakerTest.java +++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/DocMakerTest.java @@ -94,7 +94,7 @@ public class DocMakerTest extends BenchmarkTestCase { IndexReader reader = DirectoryReader.open(runData.getDirectory()); IndexSearcher searcher = newSearcher(reader); TopDocs td = searcher.search(new TermQuery(new Term("key", "value")), 10); - assertEquals(numExpectedResults, td.totalHits); + assertEquals(numExpectedResults, td.totalHits.value); reader.close(); } diff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/LineDocSourceTest.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/LineDocSourceTest.java index 197ce4aefcc..e826e43c05a 100644 --- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/LineDocSourceTest.java +++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/LineDocSourceTest.java @@ -154,7 +154,7 @@ public class LineDocSourceTest extends BenchmarkTestCase { reader = DirectoryReader.open(runData.getDirectory()); searcher = newSearcher(reader); TopDocs td = searcher.search(new TermQuery(new Term("body", "body")), 10); - assertEquals(numAdds, td.totalHits); + assertEquals(numAdds, td.totalHits.value); assertNotNull(td.scoreDocs[0]); if (storedField==null) { diff --git a/lucene/classification/src/java/org/apache/lucene/classification/BM25NBClassifier.java b/lucene/classification/src/java/org/apache/lucene/classification/BM25NBClassifier.java index 061385606df..b23fc396df6 100644 --- a/lucene/classification/src/java/org/apache/lucene/classification/BM25NBClassifier.java +++ b/lucene/classification/src/java/org/apache/lucene/classification/BM25NBClassifier.java @@ -217,7 +217,7 @@ public class BM25NBClassifier implements Classifier { builder.add(query, BooleanClause.Occur.MUST); } TopDocs search = indexSearcher.search(builder.build(), 1); - return search.totalHits > 0 ? search.scoreDocs[0].score : 1; + return search.totalHits.value > 0 ? search.scoreDocs[0].score : 1; } private double calculateLogPrior(Term term) throws IOException { @@ -228,7 +228,7 @@ public class BM25NBClassifier implements Classifier { bq.add(query, BooleanClause.Occur.MUST); } TopDocs topDocs = indexSearcher.search(bq.build(), 1); - return topDocs.totalHits > 0 ? Math.log(topDocs.scoreDocs[0].score) : 0; + return topDocs.totalHits.value > 0 ? Math.log(topDocs.scoreDocs[0].score) : 0; } } diff --git a/lucene/classification/src/java/org/apache/lucene/classification/KNearestFuzzyClassifier.java b/lucene/classification/src/java/org/apache/lucene/classification/KNearestFuzzyClassifier.java index 0e90ccdecb8..0398fbc11cd 100644 --- a/lucene/classification/src/java/org/apache/lucene/classification/KNearestFuzzyClassifier.java +++ b/lucene/classification/src/java/org/apache/lucene/classification/KNearestFuzzyClassifier.java @@ -159,7 +159,7 @@ public class KNearestFuzzyClassifier implements Classifier { private List> buildListFromTopDocs(TopDocs topDocs) throws IOException { Map classCounts = new HashMap<>(); Map classBoosts = new HashMap<>(); // this is a boost based on class ranking positions in topDocs - float maxScore = topDocs.totalHits == 0 ? Float.NaN : topDocs.scoreDocs[0].score; + float maxScore = topDocs.totalHits.value == 0 ? Float.NaN : topDocs.scoreDocs[0].score; for (ScoreDoc scoreDoc : topDocs.scoreDocs) { IndexableField storableField = indexSearcher.doc(scoreDoc.doc).getField(classFieldName); if (storableField != null) { diff --git a/lucene/classification/src/java/org/apache/lucene/classification/KNearestNeighborClassifier.java b/lucene/classification/src/java/org/apache/lucene/classification/KNearestNeighborClassifier.java index 6c554934911..dadb8854e19 100644 --- a/lucene/classification/src/java/org/apache/lucene/classification/KNearestNeighborClassifier.java +++ b/lucene/classification/src/java/org/apache/lucene/classification/KNearestNeighborClassifier.java @@ -190,7 +190,7 @@ public class KNearestNeighborClassifier implements Classifier { protected List> buildListFromTopDocs(TopDocs topDocs) throws IOException { Map classCounts = new HashMap<>(); Map classBoosts = new HashMap<>(); // this is a boost based on class ranking positions in topDocs - float maxScore = topDocs.totalHits == 0 ? Float.NaN : topDocs.scoreDocs[0].score; + float maxScore = topDocs.totalHits.value == 0 ? Float.NaN : topDocs.scoreDocs[0].score; for (ScoreDoc scoreDoc : topDocs.scoreDocs) { IndexableField[] storableFields = indexSearcher.doc(scoreDoc.doc).getFields(classFieldName); for (IndexableField singleStorableField : storableFields) { 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.java index d75daf9c799..c2f04d36b6c 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 @@ -35,6 +35,7 @@ import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.Sort; +import org.apache.lucene.search.TotalHits; import org.apache.lucene.search.grouping.GroupDocs; import org.apache.lucene.search.grouping.GroupingSearch; import org.apache.lucene.search.grouping.TopGroups; @@ -122,7 +123,8 @@ public class DatasetSplitter { // iterate over existing documents for (GroupDocs group : topGroups.groups) { - long totalHits = group.totalHits; + assert group.totalHits.relation == TotalHits.Relation.EQUAL_TO; + long totalHits = group.totalHits.value; double testSize = totalHits * testRatio; int tc = 0; double cvSize = totalHits * crossValidationRatio; diff --git a/lucene/core/src/java/org/apache/lucene/search/SortRescorer.java b/lucene/core/src/java/org/apache/lucene/search/SortRescorer.java index 95f29824daa..5d35a58cdb0 100644 --- a/lucene/core/src/java/org/apache/lucene/search/SortRescorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/SortRescorer.java @@ -24,6 +24,7 @@ import java.util.Comparator; import java.util.List; import org.apache.lucene.index.LeafReaderContext; +import org.apache.lucene.search.TotalHits.Relation; /** * A {@link Rescorer} that re-sorts according to a provided @@ -98,9 +99,9 @@ public class SortRescorer extends Rescorer { @Override public Explanation explain(IndexSearcher searcher, Explanation firstPassExplanation, int docID) throws IOException { - TopDocs oneHit = new TopDocs(1, new ScoreDoc[] {new ScoreDoc(docID, firstPassExplanation.getValue().floatValue())}); + TopDocs oneHit = new TopDocs(new TotalHits(1, Relation.EQUAL_TO), new ScoreDoc[] {new ScoreDoc(docID, firstPassExplanation.getValue().floatValue())}); TopDocs hits = rescore(searcher, oneHit, 1); - assert hits.totalHits == 1; + assert hits.totalHits.value == 1; List subs = new ArrayList<>(); diff --git a/lucene/core/src/java/org/apache/lucene/search/TopDocs.java b/lucene/core/src/java/org/apache/lucene/search/TopDocs.java index 25f7b34688d..d4668930781 100644 --- a/lucene/core/src/java/org/apache/lucene/search/TopDocs.java +++ b/lucene/core/src/java/org/apache/lucene/search/TopDocs.java @@ -23,13 +23,13 @@ import org.apache.lucene.util.PriorityQueue; public class TopDocs { /** The total number of hits for the query. */ - public long totalHits; + public TotalHits totalHits; /** The top hits for the query. */ public ScoreDoc[] scoreDocs; /** Constructs a TopDocs. */ - public TopDocs(long totalHits, ScoreDoc[] scoreDocs) { + public TopDocs(TotalHits totalHits, ScoreDoc[] scoreDocs) { this.totalHits = totalHits; this.scoreDocs = scoreDocs; } @@ -246,12 +246,18 @@ public class TopDocs { } long totalHitCount = 0; + TotalHits.Relation totalHitsRelation = TotalHits.Relation.EQUAL_TO; int availHitCount = 0; for(int shardIDX=0;shardIDX 0) { availHitCount += shard.scoreDocs.length; queue.add(new ShardRef(shardIDX, setShardIndex == false)); @@ -292,10 +298,11 @@ public class TopDocs { } } + TotalHits totalHits = new TotalHits(totalHitCount, totalHitsRelation); if (sort == null) { - return new TopDocs(totalHitCount, hits); + return new TopDocs(totalHits, hits); } else { - return new TopFieldDocs(totalHitCount, hits, sort.getSort()); + return new TopFieldDocs(totalHits, hits, sort.getSort()); } } } diff --git a/lucene/core/src/java/org/apache/lucene/search/TopDocsCollector.java b/lucene/core/src/java/org/apache/lucene/search/TopDocsCollector.java index 1ad3553a77c..3e9f8344e92 100644 --- a/lucene/core/src/java/org/apache/lucene/search/TopDocsCollector.java +++ b/lucene/core/src/java/org/apache/lucene/search/TopDocsCollector.java @@ -35,7 +35,7 @@ public abstract class TopDocsCollector implements Collector /** This is used in case topDocs() is called with illegal parameters, or there * simply aren't (enough) results. */ - protected static final TopDocs EMPTY_TOPDOCS = new TopDocs(0, new ScoreDoc[0]); + protected static final TopDocs EMPTY_TOPDOCS = new TopDocs(new TotalHits(0, TotalHits.Relation.EQUAL_TO), new ScoreDoc[0]); /** * The priority queue which holds the top documents. Note that different @@ -47,7 +47,10 @@ public abstract class TopDocsCollector implements Collector /** The total number of documents that the collector encountered. */ protected int totalHits; - + + /** Whether {@link #totalHits} is exact or a lower bound. */ + protected TotalHits.Relation totalHitsRelation = TotalHits.Relation.EQUAL_TO; + protected TopDocsCollector(PriorityQueue pq) { this.pq = pq; } @@ -69,7 +72,7 @@ public abstract class TopDocsCollector implements Collector * topDocs were invalid. */ protected TopDocs newTopDocs(ScoreDoc[] results, int start) { - return results == null ? EMPTY_TOPDOCS : new TopDocs(totalHits, results); + return results == null ? EMPTY_TOPDOCS : new TopDocs(new TotalHits(totalHits, totalHitsRelation), results); } /** The total number of documents that matched this query. */ diff --git a/lucene/core/src/java/org/apache/lucene/search/TopFieldCollector.java b/lucene/core/src/java/org/apache/lucene/search/TopFieldCollector.java index 99f4e2ca53b..af2310b4b72 100644 --- a/lucene/core/src/java/org/apache/lucene/search/TopFieldCollector.java +++ b/lucene/core/src/java/org/apache/lucene/search/TopFieldCollector.java @@ -25,6 +25,7 @@ import java.util.List; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.ReaderUtil; import org.apache.lucene.search.FieldValueHitQueue.Entry; +import org.apache.lucene.search.TotalHits.Relation; import org.apache.lucene.util.FutureObjects; import org.apache.lucene.util.PriorityQueue; @@ -77,13 +78,6 @@ public abstract class TopFieldCollector extends TopDocsCollector { return Arrays.asList(fields1).equals(Arrays.asList(fields2).subList(0, fields1.length)); } - static int estimateRemainingHits(int hitCount, int doc, int maxDoc) { - double hitRatio = (double) hitCount / (doc + 1); - int remainingDocs = maxDoc - doc - 1; - int remainingHits = (int) (remainingDocs * hitRatio); - return remainingHits; - } - /* * Implements a TopFieldCollector over one SortField criteria, with tracking * document scores and maxScore. @@ -111,7 +105,6 @@ public abstract class TopFieldCollector extends TopDocsCollector { final boolean canEarlyTerminate = trackTotalHits == false && indexSort != null && canEarlyTerminate(sort, indexSort); - final int initialTotalHits = totalHits; return new MultiComparatorLeafCollector(comparators, reverseMul) { @@ -124,10 +117,7 @@ public abstract class TopFieldCollector extends TopDocsCollector { // this document is largest than anything else in the queue, and // therefore not competitive. if (canEarlyTerminate) { - // scale totalHits linearly based on the number of docs - // and terminate collection - totalHits += estimateRemainingHits(totalHits - initialTotalHits, doc, context.reader().maxDoc()); - earlyTerminated = true; + totalHitsRelation = Relation.GREATER_THAN_OR_EQUAL_TO; throw new CollectionTerminatedException(); } else { // just move to the next doc @@ -193,7 +183,6 @@ public abstract class TopFieldCollector extends TopDocsCollector { final boolean canEarlyTerminate = trackTotalHits == false && indexSort != null && canEarlyTerminate(sort, indexSort); - final int initialTotalHits = totalHits; return new MultiComparatorLeafCollector(queue.getComparators(context), queue.getReverseMul()) { @Override @@ -209,10 +198,7 @@ public abstract class TopFieldCollector extends TopDocsCollector { if (cmp <= 0) { // not competitive since documents are visited in doc id order if (canEarlyTerminate) { - // scale totalHits linearly based on the number of docs - // and terminate collection - totalHits += estimateRemainingHits(totalHits - initialTotalHits, doc, context.reader().maxDoc()); - earlyTerminated = true; + totalHitsRelation = Relation.GREATER_THAN_OR_EQUAL_TO; throw new CollectionTerminatedException(); } else { // just move to the next doc @@ -261,7 +247,6 @@ public abstract class TopFieldCollector extends TopDocsCollector { FieldValueHitQueue.Entry bottom = null; boolean queueFull; int docBase; - boolean earlyTerminated = false; final boolean needsScores; // Declaring the constructor private prevents extending this class by anyone @@ -423,7 +408,7 @@ public abstract class TopFieldCollector extends TopDocsCollector { } // If this is a maxScoring tracking collector and there were no results, - return new TopFieldDocs(totalHits, results, ((FieldValueHitQueue) pq).getFields()); + return new TopFieldDocs(new TotalHits(totalHits, totalHitsRelation), results, ((FieldValueHitQueue) pq).getFields()); } @Override @@ -433,6 +418,6 @@ public abstract class TopFieldCollector extends TopDocsCollector { /** Return whether collection terminated early. */ public boolean isEarlyTerminated() { - return earlyTerminated; + return totalHitsRelation == Relation.GREATER_THAN_OR_EQUAL_TO; } } diff --git a/lucene/core/src/java/org/apache/lucene/search/TopFieldDocs.java b/lucene/core/src/java/org/apache/lucene/search/TopFieldDocs.java index 95c7deeb79a..772d7a90acd 100644 --- a/lucene/core/src/java/org/apache/lucene/search/TopFieldDocs.java +++ b/lucene/core/src/java/org/apache/lucene/search/TopFieldDocs.java @@ -31,7 +31,7 @@ public class TopFieldDocs extends TopDocs { * @param scoreDocs The top hits for the query. * @param fields The sort criteria used to find the top hits. */ - public TopFieldDocs (long totalHits, ScoreDoc[] scoreDocs, SortField[] fields) { + public TopFieldDocs (TotalHits totalHits, ScoreDoc[] scoreDocs, SortField[] fields) { super (totalHits, scoreDocs); this.fields = fields; } diff --git a/lucene/core/src/java/org/apache/lucene/search/TopScoreDocCollector.java b/lucene/core/src/java/org/apache/lucene/search/TopScoreDocCollector.java index a319de760e8..839a6268eec 100644 --- a/lucene/core/src/java/org/apache/lucene/search/TopScoreDocCollector.java +++ b/lucene/core/src/java/org/apache/lucene/search/TopScoreDocCollector.java @@ -20,6 +20,7 @@ package org.apache.lucene.search; import java.io.IOException; import org.apache.lucene.index.LeafReaderContext; +import org.apache.lucene.search.TotalHits.Relation; /** * A {@link Collector} implementation that collects the top-scoring hits, @@ -49,22 +50,20 @@ public abstract class TopScoreDocCollector extends TopDocsCollector { private static class SimpleTopScoreDocCollector extends TopScoreDocCollector { - private final int numHits; private final boolean trackTotalHits; - private int sumMaxDoc; - private int maxCollectedExactly = -1; SimpleTopScoreDocCollector(int numHits, boolean trackTotalHits) { super(numHits); - this.numHits = numHits; this.trackTotalHits = trackTotalHits; + if (trackTotalHits == false) { + totalHitsRelation = Relation.GREATER_THAN_OR_EQUAL_TO; + } } @Override public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException { final int docBase = context.docBase; - sumMaxDoc += context.reader().maxDoc(); return new ScorerLeafCollector() { @Override @@ -100,30 +99,12 @@ public abstract class TopScoreDocCollector extends TopDocsCollector { // since we tie-break on doc id and collect in doc id order, we can require // the next float scorer.setMinCompetitiveScore(Math.nextUp(pqTop.score)); - if (maxCollectedExactly < 0) { - assert totalHits == numHits; - maxCollectedExactly = doc + docBase; - } } } }; } - @Override - public TopDocs topDocs() { - TopDocs topDocs = super.topDocs(); - if (trackTotalHits == false && maxCollectedExactly >= 0) { - // assume matches are evenly spread in the doc id space - // this may be completely off - long totalHitsEstimate = (long) numHits * sumMaxDoc / (maxCollectedExactly + 1); - // we take the max since the current topDocs.totalHits is a lower bound - // of the total hit count - topDocs.totalHits = Math.max(topDocs.totalHits, totalHitsEstimate); - } - return topDocs; - } - @Override public ScoreMode scoreMode() { return trackTotalHits ? ScoreMode.COMPLETE : ScoreMode.TOP_SCORES; @@ -148,7 +129,9 @@ public abstract class TopScoreDocCollector extends TopDocsCollector { @Override protected TopDocs newTopDocs(ScoreDoc[] results, int start) { - return results == null ? new TopDocs(totalHits, new ScoreDoc[0]) : new TopDocs(totalHits, results); + return results == null + ? new TopDocs(new TotalHits(totalHits, totalHitsRelation), new ScoreDoc[0]) + : new TopDocs(new TotalHits(totalHits, totalHitsRelation), results); } @Override @@ -240,7 +223,7 @@ public abstract class TopScoreDocCollector extends TopDocsCollector { return EMPTY_TOPDOCS; } - return new TopDocs(totalHits, results); + return new TopDocs(new TotalHits(totalHits, totalHitsRelation), results); } @Override diff --git a/lucene/core/src/java/org/apache/lucene/search/TotalHits.java b/lucene/core/src/java/org/apache/lucene/search/TotalHits.java new file mode 100644 index 00000000000..1b852a9c99d --- /dev/null +++ b/lucene/core/src/java/org/apache/lucene/search/TotalHits.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.lucene.search; + +import java.util.Objects; + +/** + * Description of the total number of hits of a query. The total hit count + * can't generally be computed accurately without visiting all matches, which + * is costly for queries that match lots of documents. Given that it is often + * enough to have a lower bounds of the number of hits, such as + * "there are more than 1000 hits", Lucene has options to stop counting as soon + * as a threshold has been reached in order to improve query times. + */ +public final class TotalHits { + + /** How the {@link TotalHits#value} should be interpreted. */ + public enum Relation { + /** + * The total hit count is equal to {@link TotalHits#value}. + */ + EQUAL_TO, + /** + * The total hit count is greater than or eual to {@link TotalHits#value}. + */ + GREATER_THAN_OR_EQUAL_TO + } + + /** + * The value of the total hit count. Must be interpreted in the context of + * {@link #relation}. + */ + public final long value; + + /** + * Whether {@link #value} is the exact hit count, in which case + * {@link #relation} is equal to {@link Relation#EQUAL_TO}, or a lower bound + * of the total hit count, in which case {@link #relation} is equal to + * {@link Relation#GREATER_THAN_OR_EQUAL_TO}. + */ + public final Relation relation; + + /** Sole constructor. */ + public TotalHits(long value, Relation relation) { + if (value < 0) { + throw new IllegalArgumentException("value must be >= 0, got " + value); + } + this.value = value; + this.relation = Objects.requireNonNull(relation); + } + + @Override + public String toString() { + return value + (relation == Relation.EQUAL_TO ? "" : "+") + " hits"; + } + +} diff --git a/lucene/core/src/test/org/apache/lucene/TestDemo.java b/lucene/core/src/test/org/apache/lucene/TestDemo.java index a49bbe54910..f2d3a61fd59 100644 --- a/lucene/core/src/test/org/apache/lucene/TestDemo.java +++ b/lucene/core/src/test/org/apache/lucene/TestDemo.java @@ -61,7 +61,7 @@ public class TestDemo extends LuceneTestCase { assertEquals(1, isearcher.count(new TermQuery(new Term("fieldname", longTerm)))); Query query = new TermQuery(new Term("fieldname", "text")); TopDocs hits = isearcher.search(query, 1); - assertEquals(1, hits.totalHits); + assertEquals(1, hits.totalHits.value); // Iterate through the results: for (int i = 0; i < hits.scoreDocs.length; i++) { Document hitDoc = isearcher.doc(hits.scoreDocs[i].doc); diff --git a/lucene/core/src/test/org/apache/lucene/codecs/perfield/TestPerFieldDocValuesFormat.java b/lucene/core/src/test/org/apache/lucene/codecs/perfield/TestPerFieldDocValuesFormat.java index 1541dcb9636..ea3f9cc2513 100644 --- a/lucene/core/src/test/org/apache/lucene/codecs/perfield/TestPerFieldDocValuesFormat.java +++ b/lucene/core/src/test/org/apache/lucene/codecs/perfield/TestPerFieldDocValuesFormat.java @@ -117,7 +117,7 @@ public class TestPerFieldDocValuesFormat extends BaseDocValuesFormatTestCase { assertEquals(1, isearcher.count(new TermQuery(new Term("fieldname", longTerm)))); Query query = new TermQuery(new Term("fieldname", "text")); TopDocs hits = isearcher.search(query, 1); - assertEquals(1, hits.totalHits); + assertEquals(1, hits.totalHits.value); // Iterate through the results: for (int i = 0; i < hits.scoreDocs.length; i++) { int hitDocID = hits.scoreDocs[i].doc; diff --git a/lucene/core/src/test/org/apache/lucene/codecs/perfield/TestPerFieldPostingsFormat2.java b/lucene/core/src/test/org/apache/lucene/codecs/perfield/TestPerFieldPostingsFormat2.java index f72ffcc055d..b7cc2bf2b2f 100644 --- a/lucene/core/src/test/org/apache/lucene/codecs/perfield/TestPerFieldPostingsFormat2.java +++ b/lucene/core/src/test/org/apache/lucene/codecs/perfield/TestPerFieldPostingsFormat2.java @@ -209,7 +209,7 @@ public class TestPerFieldPostingsFormat2 extends LuceneTestCase { IndexReader reader = DirectoryReader.open(dir); IndexSearcher searcher = newSearcher(reader); TopDocs search = searcher.search(new TermQuery(t), num + 10); - assertEquals(num, search.totalHits); + assertEquals(num, search.totalHits.value); reader.close(); } diff --git a/lucene/core/src/test/org/apache/lucene/document/TestField.java b/lucene/core/src/test/org/apache/lucene/document/TestField.java index c08750502f6..5c5f47b745a 100644 --- a/lucene/core/src/test/org/apache/lucene/document/TestField.java +++ b/lucene/core/src/test/org/apache/lucene/document/TestField.java @@ -487,7 +487,7 @@ public class TestField extends LuceneTestCase { IndexSearcher s = newSearcher(r); TopDocs hits = s.search(new TermQuery(new Term("binary", br)), 1); - assertEquals(1, hits.totalHits); + assertEquals(1, hits.totalHits.value); Document storedDoc = s.doc(hits.scoreDocs[0].doc); assertEquals(br, storedDoc.getField("binary").binaryValue()); diff --git a/lucene/core/src/test/org/apache/lucene/index/TestBinaryTerms.java b/lucene/core/src/test/org/apache/lucene/index/TestBinaryTerms.java index 8da8c23574b..81593b71eb4 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestBinaryTerms.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestBinaryTerms.java @@ -60,7 +60,7 @@ public class TestBinaryTerms extends LuceneTestCase { bytes.bytes[1] = (byte) (255 - i); bytes.length = 2; TopDocs docs = is.search(new TermQuery(new Term("bytes", bytes)), 5); - assertEquals(1, docs.totalHits); + assertEquals(1, docs.totalHits.value); assertEquals("" + i, is.doc(docs.scoreDocs[0].doc).get("id")); } diff --git a/lucene/core/src/test/org/apache/lucene/index/TestCrashCausesCorruptIndex.java b/lucene/core/src/test/org/apache/lucene/index/TestCrashCausesCorruptIndex.java index 9fd20aba509..c7d300bd800 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestCrashCausesCorruptIndex.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestCrashCausesCorruptIndex.java @@ -112,7 +112,7 @@ public class TestCrashCausesCorruptIndex extends LuceneTestCase { IndexSearcher indexSearcher = newSearcher(indexReader); TopDocs topDocs = indexSearcher.search(new TermQuery(new Term(TEXT_FIELD, "fleas")), 10); assertNotNull(topDocs); - assertEquals(expectedTotalHits, topDocs.totalHits); + assertEquals(expectedTotalHits, topDocs.totalHits.value); indexReader.close(); realDirectory.close(); } diff --git a/lucene/core/src/test/org/apache/lucene/index/TestForTooMuchCloning.java b/lucene/core/src/test/org/apache/lucene/index/TestForTooMuchCloning.java index 89a77cd29eb..6be8e78d9f8 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestForTooMuchCloning.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestForTooMuchCloning.java @@ -71,7 +71,7 @@ public class TestForTooMuchCloning extends LuceneTestCase { new BytesRef("\uFFFF"), true, true), 10); - assertTrue(hits.totalHits > 0); + assertTrue(hits.totalHits.value > 0); final int queryCloneCount = dir.getInputCloneCount() - cloneCount; //System.out.println("query clone count=" + queryCloneCount); assertTrue("too many calls to IndexInput.clone during TermRangeQuery: " + queryCloneCount, queryCloneCount < 50); diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexSorting.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexSorting.java index 858a874c427..2eab9c67d4e 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestIndexSorting.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexSorting.java @@ -1534,9 +1534,9 @@ public class TestIndexSorting extends LuceneTestCase { TermQuery termQuery = new TermQuery(new Term("id", Integer.toString(i))); final TopDocs topDocs = searcher.search(termQuery, 1); if (deleted.get(i)) { - assertEquals(0, topDocs.totalHits); + assertEquals(0, topDocs.totalHits.value); } else { - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); NumericDocValues values = MultiDocValues.getNumericValues(reader, "id"); assertEquals(topDocs.scoreDocs[0].doc, values.advance(topDocs.scoreDocs[0].doc)); assertEquals(i, values.longValue()); @@ -1586,9 +1586,9 @@ public class TestIndexSorting extends LuceneTestCase { TermQuery termQuery = new TermQuery(new Term("id", Integer.toString(i))); final TopDocs topDocs = searcher.search(termQuery, 1); if (deleted.get(i)) { - assertEquals(0, topDocs.totalHits); + assertEquals(0, topDocs.totalHits.value); } else { - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); NumericDocValues values = MultiDocValues.getNumericValues(reader, "id"); assertEquals(topDocs.scoreDocs[0].doc, values.advance(topDocs.scoreDocs[0].doc)); assertEquals(i, values.longValue()); @@ -1685,9 +1685,9 @@ public class TestIndexSorting extends LuceneTestCase { for (int i = 0; i < numDocs; ++i) { final TopDocs topDocs = searcher.search(new TermQuery(new Term("id", Integer.toString(i))), 1); if (values.containsKey(i) == false) { - assertEquals(0, topDocs.totalHits); + assertEquals(0, topDocs.totalHits.value); } else { - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); NumericDocValues dvs = MultiDocValues.getNumericValues(reader, "foo"); int docID = topDocs.scoreDocs[0].doc; assertEquals(docID, dvs.advance(docID)); @@ -1807,7 +1807,7 @@ public class TestIndexSorting extends LuceneTestCase { IndexSearcher searcher = newSearcher(reader); for (int i = 0; i < numDocs; ++i) { final TopDocs topDocs = searcher.search(new TermQuery(new Term("id", Integer.toString(i))), 1); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); NumericDocValues dvs = MultiDocValues.getNumericValues(reader, "bar"); int hitDoc = topDocs.scoreDocs[0].doc; assertEquals(hitDoc, dvs.advance(hitDoc)); @@ -1865,8 +1865,8 @@ public class TestIndexSorting extends LuceneTestCase { Query query = new TermQuery(new Term("id", Integer.toString(i))); final TopDocs topDocs = searcher.search(query, 1); final TopDocs topDocs2 = searcher2.search(query, 1); - assertEquals(topDocs.totalHits, topDocs2.totalHits); - if (topDocs.totalHits == 1) { + assertEquals(topDocs.totalHits.value, topDocs2.totalHits.value); + if (topDocs.totalHits.value == 1) { NumericDocValues dvs1 = MultiDocValues.getNumericValues(reader, "foo"); int hitDoc1 = topDocs.scoreDocs[0].doc; assertEquals(hitDoc1, dvs1.advance(hitDoc1)); @@ -2334,11 +2334,11 @@ public class TestIndexSorting extends LuceneTestCase { TopDocs hits2 = c2.topDocs(); if (VERBOSE) { - System.out.println(" topDocs query-time sort: totalHits=" + hits1.totalHits); + System.out.println(" topDocs query-time sort: totalHits=" + hits1.totalHits.value); for(ScoreDoc scoreDoc : hits1.scoreDocs) { System.out.println(" " + scoreDoc.doc); } - System.out.println(" topDocs index-time sort: totalHits=" + hits2.totalHits); + System.out.println(" topDocs index-time sort: totalHits=" + hits2.totalHits.value); for(ScoreDoc scoreDoc : hits2.scoreDocs) { System.out.println(" " + scoreDoc.doc); } diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java index 4861929d2cb..b6402988721 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java @@ -1778,7 +1778,7 @@ public class TestIndexWriter extends LuceneTestCase { builder.add(new Term("body", "test"), 2); PhraseQuery pq = builder.build(); // body:"just ? test" - assertEquals(1, is.search(pq, 5).totalHits); + assertEquals(1, is.search(pq, 5).totalHits.value); ir.close(); dir.close(); } @@ -1810,7 +1810,7 @@ public class TestIndexWriter extends LuceneTestCase { builder.add(new Term("body", "test"), 3); PhraseQuery pq = builder.build(); // body:"just ? ? test" - assertEquals(1, is.search(pq, 5).totalHits); + assertEquals(1, is.search(pq, 5).totalHits.value); ir.close(); dir.close(); } @@ -3109,7 +3109,7 @@ public class TestIndexWriter extends LuceneTestCase { assertEquals(2, reader.docFreq(new Term("id", "1"))); IndexSearcher searcher = new IndexSearcher(reader); TopDocs topDocs = searcher.search(new TermQuery(new Term("id", "1")), 10); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); Document document = reader.document(topDocs.scoreDocs[0].doc); assertEquals("2", document.get("version")); @@ -3125,7 +3125,7 @@ public class TestIndexWriter extends LuceneTestCase { oldReader.close(); searcher = new IndexSearcher(reader); topDocs = searcher.search(new TermQuery(new Term("id", "1")), 10); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); document = reader.document(topDocs.scoreDocs[0].doc); assertEquals("3", document.get("version")); @@ -3138,7 +3138,7 @@ public class TestIndexWriter extends LuceneTestCase { oldReader.close(); searcher = new IndexSearcher(reader); topDocs = searcher.search(new TermQuery(new Term("id", "1")), 10); - assertEquals(0, topDocs.totalHits); + assertEquals(0, topDocs.totalHits.value); int numSoftDeleted = 0; for (SegmentCommitInfo info : writer.cloneSegmentInfos()) { numSoftDeleted += info.getSoftDelCount(); @@ -3261,10 +3261,10 @@ public class TestIndexWriter extends LuceneTestCase { for (String id : ids) { TopDocs topDocs = searcher.search(new TermQuery(new Term("id", id)), 10); if (updateSeveralDocs) { - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); assertEquals(Math.abs(topDocs.scoreDocs[0].doc - topDocs.scoreDocs[1].doc), 1); } else { - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); } } if (mixDeletes == false) { diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterDelete.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterDelete.java index 2f15cbb079a..1ee4bd0d0e9 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterDelete.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterDelete.java @@ -477,7 +477,7 @@ public class TestIndexWriterDelete extends LuceneTestCase { private long getHitCount(Directory dir, Term term) throws IOException { IndexReader reader = DirectoryReader.open(dir); IndexSearcher searcher = newSearcher(reader); - long hitCount = searcher.search(new TermQuery(term), 1000).totalHits; + long hitCount = searcher.search(new TermQuery(term), 1000).totalHits.value; reader.close(); return hitCount; } diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterMaxDocs.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterMaxDocs.java index 237ad382f81..5d41459de1b 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterMaxDocs.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterMaxDocs.java @@ -68,11 +68,11 @@ public class TestIndexWriterMaxDocs extends LuceneTestCase { assertEquals(IndexWriter.MAX_DOCS, ir.numDocs()); IndexSearcher searcher = new IndexSearcher(ir); TopDocs hits = searcher.search(new TermQuery(new Term("field", "text")), 10); - assertEquals(IndexWriter.MAX_DOCS, hits.totalHits); + assertEquals(IndexWriter.MAX_DOCS, hits.totalHits.value); // Sort by docID reversed: hits = searcher.search(new TermQuery(new Term("field", "text")), 10, new Sort(new SortField(null, SortField.Type.DOC, true))); - assertEquals(IndexWriter.MAX_DOCS, hits.totalHits); + assertEquals(IndexWriter.MAX_DOCS, hits.totalHits.value); assertEquals(10, hits.scoreDocs.length); assertEquals(IndexWriter.MAX_DOCS-1, hits.scoreDocs[0].doc); ir.close(); diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterReader.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterReader.java index 86881acff10..de05b206daf 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterReader.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterReader.java @@ -700,7 +700,7 @@ public class TestIndexWriterReader extends LuceneTestCase { assertEquals(100, r.numDocs()); Query q = new TermQuery(new Term("indexname", "test")); IndexSearcher searcher = newSearcher(r); - assertEquals(100, searcher.search(q, 10).totalHits); + assertEquals(100, searcher.search(q, 10).totalHits.value); expectThrows(AlreadyClosedException.class, () -> { DirectoryReader.openIfChanged(r); @@ -768,7 +768,7 @@ public class TestIndexWriterReader extends LuceneTestCase { r = r2; Query q = new TermQuery(new Term("indexname", "test")); IndexSearcher searcher = newSearcher(r); - final long count = searcher.search(q, 10).totalHits; + final long count = searcher.search(q, 10).totalHits.value; assertTrue(count >= lastCount); lastCount = count; } @@ -785,7 +785,7 @@ public class TestIndexWriterReader extends LuceneTestCase { } Query q = new TermQuery(new Term("indexname", "test")); IndexSearcher searcher = newSearcher(r); - final long count = searcher.search(q, 10).totalHits; + final long count = searcher.search(q, 10).totalHits.value; assertTrue(count >= lastCount); assertEquals(0, excs.size()); @@ -865,7 +865,7 @@ public class TestIndexWriterReader extends LuceneTestCase { r = r2; Query q = new TermQuery(new Term("indexname", "test")); IndexSearcher searcher = newSearcher(r); - sum += searcher.search(q, 10).totalHits; + sum += searcher.search(q, 10).totalHits.value; } } @@ -880,7 +880,7 @@ public class TestIndexWriterReader extends LuceneTestCase { } Query q = new TermQuery(new Term("indexname", "test")); IndexSearcher searcher = newSearcher(r); - sum += searcher.search(q, 10).totalHits; + sum += searcher.search(q, 10).totalHits.value; assertTrue("no documents found at all", sum > 0); assertEquals(0, excs.size()); @@ -966,7 +966,7 @@ public class TestIndexWriterReader extends LuceneTestCase { .setMergedSegmentWarmer((r) -> { IndexSearcher s = newSearcher(r); TopDocs hits = s.search(new TermQuery(new Term("foo", "bar")), 10); - assertEquals(20, hits.totalHits); + assertEquals(20, hits.totalHits.value); didWarm.set(true); }) .setMergePolicy(newLogMergePolicy(10)) diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexableField.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexableField.java index 510a8997f9b..25b48c8f5c1 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestIndexableField.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexableField.java @@ -228,7 +228,7 @@ public class TestIndexableField extends LuceneTestCase { } final TopDocs hits = s.search(new TermQuery(new Term("id", ""+id)), 1); - assertEquals(1, hits.totalHits); + assertEquals(1, hits.totalHits.value); final int docID = hits.scoreDocs[0].doc; final Document doc = s.doc(docID); final int endCounter = counter + fieldsPerDoc[id]; @@ -298,14 +298,14 @@ public class TestIndexableField extends LuceneTestCase { bq.add(new TermQuery(new Term("id", ""+id)), BooleanClause.Occur.MUST); bq.add(new TermQuery(new Term(name, "text")), BooleanClause.Occur.MUST); final TopDocs hits2 = s.search(bq.build(), 1); - assertEquals(1, hits2.totalHits); + assertEquals(1, hits2.totalHits.value); assertEquals(docID, hits2.scoreDocs[0].doc); bq = new BooleanQuery.Builder(); bq.add(new TermQuery(new Term("id", ""+id)), BooleanClause.Occur.MUST); bq.add(new TermQuery(new Term(name, ""+counter)), BooleanClause.Occur.MUST); final TopDocs hits3 = s.search(bq.build(), 1); - assertEquals(1, hits3.totalHits); + assertEquals(1, hits3.totalHits.value); assertEquals(docID, hits3.scoreDocs[0].doc); } diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexingSequenceNumbers.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexingSequenceNumbers.java index 44ea74dbd81..e3f42fc57ce 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestIndexingSequenceNumbers.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexingSequenceNumbers.java @@ -126,7 +126,7 @@ public class TestIndexingSequenceNumbers extends LuceneTestCase { DirectoryReader r = w.getReader(); IndexSearcher s = newSearcher(r); TopDocs hits = s.search(new TermQuery(id), 1); - assertEquals("maxDoc: " + r.maxDoc(), 1, hits.totalHits); + assertEquals("maxDoc: " + r.maxDoc(), 1, hits.totalHits.value); Document doc = r.document(hits.scoreDocs[0].doc); assertEquals(maxThread, doc.getField("thread").numericValue().intValue()); r.close(); @@ -270,7 +270,7 @@ public class TestIndexingSequenceNumbers extends LuceneTestCase { TopDocs hits = s.search(new TermQuery(new Term("id", ""+id)), 1); if (expectedThreadIDs[id] != -1) { - assertEquals(1, hits.totalHits); + assertEquals(1, hits.totalHits.value); Document doc = r.document(hits.scoreDocs[0].doc); int actualThreadID = doc.getField("thread").numericValue().intValue(); if (expectedThreadIDs[id] != actualThreadID) { @@ -284,8 +284,8 @@ public class TestIndexingSequenceNumbers extends LuceneTestCase { } assertEquals("id=" + id, expectedThreadIDs[id], actualThreadID); } - } else if (hits.totalHits != 0) { - System.out.println("FAIL: id=" + id + " expectedThreadID=" + expectedThreadIDs[id] + " vs totalHits=" + hits.totalHits + " commitSeqNo=" + commitSeqNo + " numThreads=" + numThreads); + } else if (hits.totalHits.value != 0) { + System.out.println("FAIL: id=" + id + " expectedThreadID=" + expectedThreadIDs[id] + " vs totalHits=" + hits.totalHits.value + " commitSeqNo=" + commitSeqNo + " numThreads=" + numThreads); for(int threadID=0;threadID leaves = reader.leaves(); int subIndex = ReaderUtil.subIndex(docID, leaves); @@ -540,7 +540,7 @@ public class TestMixedDocValuesUpdates extends LuceneTestCase { do { // retry if we just committing a merge try (DirectoryReader reader = writer.getReader()) { TopDocs topDocs = new IndexSearcher(reader).search(new TermQuery(doc), 10); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); int theDoc = topDocs.scoreDocs[0].doc; seqId = writer.tryUpdateDocValue(reader, theDoc, fields); } @@ -625,7 +625,7 @@ public class TestMixedDocValuesUpdates extends LuceneTestCase { IndexSearcher searcher = new IndexSearcher(reader); TopDocs is_live = searcher.search(new DocValuesFieldExistsQuery("is_live"), 5); - assertEquals(numHits, is_live.totalHits); + assertEquals(numHits, is_live.totalHits.value); for (ScoreDoc doc : is_live.scoreDocs) { int id = Integer.parseInt(reader.document(doc.doc).get("id")); int i = ReaderUtil.subIndex(doc.doc, reader.leaves()); diff --git a/lucene/core/src/test/org/apache/lucene/index/TestNumericDocValuesUpdates.java b/lucene/core/src/test/org/apache/lucene/index/TestNumericDocValuesUpdates.java index c6b9340cb86..4c2b2192a92 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestNumericDocValuesUpdates.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestNumericDocValuesUpdates.java @@ -165,7 +165,7 @@ public class TestNumericDocValuesUpdates extends LuceneTestCase { String id = "doc-" + expect.getKey(); TopFieldDocs td = searcher.search(new TermQuery(new Term("id", id)), 1, new Sort(new SortField("val", SortField.Type.LONG))); - assertEquals(id + " missing?", 1, td.totalHits); + assertEquals(id + " missing?", 1, td.totalHits.value); assertEquals(id + " value", expect.getValue(), ((FieldDoc)td.scoreDocs[0]).fields[0]); } diff --git a/lucene/core/src/test/org/apache/lucene/index/TestReadOnlyIndex.java b/lucene/core/src/test/org/apache/lucene/index/TestReadOnlyIndex.java index 0c9f18572b6..5eb11511815 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestReadOnlyIndex.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestReadOnlyIndex.java @@ -86,7 +86,7 @@ public class TestReadOnlyIndex extends LuceneTestCase { assertEquals(1, isearcher.count(new TermQuery(new Term("fieldname", longTerm)))); Query query = new TermQuery(new Term("fieldname", "text")); TopDocs hits = isearcher.search(query, 1); - assertEquals(1, hits.totalHits); + assertEquals(1, hits.totalHits.value); // Iterate through the results: for (int i = 0; i < hits.scoreDocs.length; i++) { Document hitDoc = isearcher.doc(hits.scoreDocs[i].doc); diff --git a/lucene/core/src/test/org/apache/lucene/index/TestRollingUpdates.java b/lucene/core/src/test/org/apache/lucene/index/TestRollingUpdates.java index 10e714ed753..fbafc9b1cf7 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestRollingUpdates.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestRollingUpdates.java @@ -79,7 +79,7 @@ public class TestRollingUpdates extends LuceneTestCase { final boolean doUpdate; if (s != null && updateCount < SIZE) { TopDocs hits = s.search(new TermQuery(idTerm), 1); - assertEquals(1, hits.totalHits); + assertEquals(1, hits.totalHits.value); doUpdate = w.tryDeleteDocument(r, hits.scoreDocs[0].doc) == -1; if (VERBOSE) { if (doUpdate) { diff --git a/lucene/core/src/test/org/apache/lucene/index/TestSoftDeletesRetentionMergePolicy.java b/lucene/core/src/test/org/apache/lucene/index/TestSoftDeletesRetentionMergePolicy.java index f6c1f6c30ca..909ee9c049a 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestSoftDeletesRetentionMergePolicy.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestSoftDeletesRetentionMergePolicy.java @@ -313,10 +313,10 @@ public class TestSoftDeletesRetentionMergePolicy extends LuceneTestCase { for (String id : ids) { TopDocs topDocs = searcher.search(new TermQuery(new Term("id", id)), 10); if (updateSeveralDocs) { - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); assertEquals(Math.abs(topDocs.scoreDocs[0].doc - topDocs.scoreDocs[1].doc), 1); } else { - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); } } writer.addDocument(new Document()); // add a dummy doc to trigger a segment here @@ -355,13 +355,13 @@ public class TestSoftDeletesRetentionMergePolicy extends LuceneTestCase { } }); TopDocs seq_id = searcher.search(IntPoint.newRangeQuery("seq_id", seqIds.intValue() - 50, Integer.MAX_VALUE), 10); - assertTrue(seq_id.totalHits + " hits", seq_id.totalHits >= 50); + assertTrue(seq_id.totalHits.value + " hits", seq_id.totalHits.value >= 50); searcher = new IndexSearcher(reader); for (String id : ids) { if (updateSeveralDocs) { - assertEquals(2, searcher.search(new TermQuery(new Term("id", id)), 10).totalHits); + assertEquals(2, searcher.search(new TermQuery(new Term("id", id)), 10).totalHits.value); } else { - assertEquals(1, searcher.search(new TermQuery(new Term("id", id)), 10).totalHits); + assertEquals(1, searcher.search(new TermQuery(new Term("id", id)), 10).totalHits.value); } } IOUtils.close(reader, writer, dir); @@ -595,7 +595,7 @@ public class TestSoftDeletesRetentionMergePolicy extends LuceneTestCase { while (true) { try (DirectoryReader reader = writer.getReader()) { TopDocs topDocs = new IndexSearcher(new NoDeletesWrapper(reader)).search(new TermQuery(new Term("id", "1")), 1); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); if (writer.tryDeleteDocument(reader, topDocs.scoreDocs[0].doc) > 0) { break; } @@ -635,7 +635,7 @@ public class TestSoftDeletesRetentionMergePolicy extends LuceneTestCase { do { // retry if we just committing a merge try (DirectoryReader reader = writer.getReader()) { TopDocs topDocs = new IndexSearcher(new NoDeletesWrapper(reader)).search(new TermQuery(doc), 10); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); int theDoc = topDocs.scoreDocs[0].doc; seqId = writer.tryUpdateDocValue(reader, theDoc, fields); } diff --git a/lucene/core/src/test/org/apache/lucene/index/TestStressDeletes.java b/lucene/core/src/test/org/apache/lucene/index/TestStressDeletes.java index 32becf30831..100a177e658 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestStressDeletes.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestStressDeletes.java @@ -108,9 +108,9 @@ public class TestStressDeletes extends LuceneTestCase { int id = ent.getKey(); TopDocs hits = s.search(new TermQuery(new Term("id", ""+id)), 1); if (ent.getValue()) { - assertEquals(1, hits.totalHits); + assertEquals(1, hits.totalHits.value); } else { - assertEquals(0, hits.totalHits); + assertEquals(0, hits.totalHits.value); } } r.close(); diff --git a/lucene/core/src/test/org/apache/lucene/index/TestStressNRT.java b/lucene/core/src/test/org/apache/lucene/index/TestStressNRT.java index 06aa27756a6..25b9d3860a2 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestStressNRT.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestStressNRT.java @@ -340,11 +340,11 @@ public class TestStressNRT extends LuceneTestCase { Query q = new TermQuery(new Term("id",Integer.toString(id))); TopDocs results = searcher.search(q, 10); - if (results.totalHits == 0 && tombstones) { + if (results.totalHits.value == 0 && tombstones) { // if we couldn't find the doc, look for its tombstone q = new TermQuery(new Term("id","-"+Integer.toString(id))); results = searcher.search(q, 1); - if (results.totalHits == 0) { + if (results.totalHits.value == 0) { if (val == -1L) { // expected... no doc was added yet r.decRef(); @@ -354,17 +354,17 @@ public class TestStressNRT extends LuceneTestCase { } } - if (results.totalHits == 0 && !tombstones) { + if (results.totalHits.value == 0 && !tombstones) { // nothing to do - we can't tell anything from a deleted doc without tombstones } else { // we should have found the document, or its tombstone - if (results.totalHits != 1) { + if (results.totalHits.value != 1) { System.out.println("FAIL: hits id:" + id + " val=" + val); for(ScoreDoc sd : results.scoreDocs) { final Document doc = r.document(sd.doc); System.out.println(" docID=" + sd.doc + " id:" + doc.get("id") + " foundVal=" + doc.get(field)); } - fail("id=" + id + " reader=" + r + " totalHits=" + results.totalHits); + fail("id=" + id + " reader=" + r + " totalHits=" + results.totalHits.value); } Document doc = searcher.doc(results.scoreDocs[0].doc); long foundVal = Long.parseLong(doc.get(field)); diff --git a/lucene/core/src/test/org/apache/lucene/index/TestTryDelete.java b/lucene/core/src/test/org/apache/lucene/index/TestTryDelete.java index 561006f88dc..0f0601ab09b 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestTryDelete.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestTryDelete.java @@ -83,7 +83,7 @@ public class TestTryDelete extends LuceneTestCase TopDocs topDocs = searcher.search(new TermQuery(new Term("foo", "0")), 100); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); long result; if (random().nextBoolean()) { @@ -111,7 +111,7 @@ public class TestTryDelete extends LuceneTestCase topDocs = searcher.search(new TermQuery(new Term("foo", "0")), 100); - assertEquals(0, topDocs.totalHits); + assertEquals(0, topDocs.totalHits.value); } public void testTryDeleteDocumentCloseAndReopen () @@ -128,7 +128,7 @@ public class TestTryDelete extends LuceneTestCase TopDocs topDocs = searcher.search(new TermQuery(new Term("foo", "0")), 100); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); long result = writer.tryDeleteDocument(DirectoryReader.open(writer), 0); @@ -144,7 +144,7 @@ public class TestTryDelete extends LuceneTestCase topDocs = searcher.search(new TermQuery(new Term("foo", "0")), 100); - assertEquals(0, topDocs.totalHits); + assertEquals(0, topDocs.totalHits.value); writer.close(); @@ -152,7 +152,7 @@ public class TestTryDelete extends LuceneTestCase topDocs = searcher.search(new TermQuery(new Term("foo", "0")), 100); - assertEquals(0, topDocs.totalHits); + assertEquals(0, topDocs.totalHits.value); } @@ -170,7 +170,7 @@ public class TestTryDelete extends LuceneTestCase TopDocs topDocs = searcher.search(new TermQuery(new Term("foo", "0")), 100); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); long result = writer.deleteDocuments(new TermQuery(new Term("foo", "0"))); @@ -186,6 +186,6 @@ public class TestTryDelete extends LuceneTestCase topDocs = searcher.search(new TermQuery(new Term("foo", "0")), 100); - assertEquals(0, topDocs.totalHits); + assertEquals(0, topDocs.totalHits.value); } } diff --git a/lucene/core/src/test/org/apache/lucene/search/TermInSetQueryTest.java b/lucene/core/src/test/org/apache/lucene/search/TermInSetQueryTest.java index ee14c3b08f9..9633ea46308 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TermInSetQueryTest.java +++ b/lucene/core/src/test/org/apache/lucene/search/TermInSetQueryTest.java @@ -105,7 +105,7 @@ public class TermInSetQueryTest extends LuceneTestCase { final int maxDoc = searcher.getIndexReader().maxDoc(); final TopDocs td1 = searcher.search(q1, maxDoc, scores ? Sort.RELEVANCE : Sort.INDEXORDER); final TopDocs td2 = searcher.search(q2, maxDoc, scores ? Sort.RELEVANCE : Sort.INDEXORDER); - assertEquals(td1.totalHits, td2.totalHits); + assertEquals(td1.totalHits.value, td2.totalHits.value); for (int i = 0; i < td1.scoreDocs.length; ++i) { assertEquals(td1.scoreDocs[i].doc, td2.scoreDocs[i].doc); if (scores) { diff --git a/lucene/core/src/test/org/apache/lucene/search/TestAutomatonQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestAutomatonQuery.java index cfb1f5bd555..8fa443cf5a0 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestAutomatonQuery.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestAutomatonQuery.java @@ -89,7 +89,7 @@ public class TestAutomatonQuery extends LuceneTestCase { if (VERBOSE) { System.out.println("TEST: run aq=" + query); } - return searcher.search(query, 5).totalHits; + return searcher.search(query, 5).totalHits.value; } private void assertAutomatonHits(int expected, Automaton automaton) diff --git a/lucene/core/src/test/org/apache/lucene/search/TestAutomatonQueryUnicode.java b/lucene/core/src/test/org/apache/lucene/search/TestAutomatonQueryUnicode.java index 48170368aea..ac25ce9df94 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestAutomatonQueryUnicode.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestAutomatonQueryUnicode.java @@ -95,7 +95,7 @@ public class TestAutomatonQueryUnicode extends LuceneTestCase { } private long automatonQueryNrHits(AutomatonQuery query) throws IOException { - return searcher.search(query, 5).totalHits; + return searcher.search(query, 5).totalHits.value; } private void assertAutomatonHits(int expected, Automaton automaton) diff --git a/lucene/core/src/test/org/apache/lucene/search/TestBlendedTermQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestBlendedTermQuery.java index c1010c3db89..3b064e22b3a 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestBlendedTermQuery.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestBlendedTermQuery.java @@ -108,7 +108,7 @@ public class TestBlendedTermQuery extends LuceneTestCase { .build(); TopDocs topDocs = searcher.search(query, 20); - assertEquals(11, topDocs.totalHits); + assertEquals(11, topDocs.totalHits.value); // All docs must have the same score for (int i = 0; i < topDocs.scoreDocs.length; ++i) { assertEquals(topDocs.scoreDocs[0].score, topDocs.scoreDocs[i].score, 0.0f); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestBoolean2.java b/lucene/core/src/test/org/apache/lucene/search/TestBoolean2.java index bc0531e83c6..cb2d8865fd5 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestBoolean2.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestBoolean2.java @@ -255,7 +255,7 @@ public class TestBoolean2 extends LuceneTestCase { // sanity check expected num matches in bigSearcher assertEquals(mulFactor * collector.totalHits, - bigSearcher.search(query, 1).totalHits); + bigSearcher.search(query, 1).totalHits.value); // now check 2 diff scorers from the bigSearcher as well collector = TopScoreDocCollector.create(topDocsToCheck); @@ -399,7 +399,7 @@ public class TestBoolean2 extends LuceneTestCase { q3.add(q1, BooleanClause.Occur.SHOULD); q3.add(new PrefixQuery(new Term("field2", "b")), BooleanClause.Occur.SHOULD); TopDocs hits4 = bigSearcher.search(q3.build(), 1); - assertEquals(mulFactor*collector.totalHits + NUM_EXTRA_DOCS/2, hits4.totalHits); + assertEquals(mulFactor*collector.totalHits + NUM_EXTRA_DOCS/2, hits4.totalHits.value); // test diff (randomized) scorers produce the same results on bigSearcher as well collector = TopFieldCollector.create(sort, 1000 * mulFactor, false); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestBooleanMinShouldMatch.java b/lucene/core/src/test/org/apache/lucene/search/TestBooleanMinShouldMatch.java index 1d01f9a39b4..643b45dc873 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestBooleanMinShouldMatch.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestBooleanMinShouldMatch.java @@ -359,19 +359,19 @@ public class TestBooleanMinShouldMatch extends LuceneTestCase { private void assertSubsetOfSameScores(Query q, TopDocs top1, TopDocs top2) { // The constrained query // should be a subset to the unconstrained query. - if (top2.totalHits > top1.totalHits) { + if (top2.totalHits.value > top1.totalHits.value) { fail("Constrained results not a subset:\n" + CheckHits.topdocsString(top1,0,0) + CheckHits.topdocsString(top2,0,0) + "for query:" + q.toString()); } - for (int hit=0; hit expectedScores = Arrays.stream(td1.scoreDocs).collect(Collectors.toMap(sd -> sd.doc, sd -> sd.score)); Set actualResultSet = Arrays.stream(td2.scoreDocs).map(sd -> sd.doc).collect(Collectors.toSet()); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestBooleanScorer.java b/lucene/core/src/test/org/apache/lucene/search/TestBooleanScorer.java index 843c89b8c1a..4d3d8d8ac5e 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestBooleanScorer.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestBooleanScorer.java @@ -149,7 +149,7 @@ public class TestBooleanScorer extends LuceneTestCase { q2.add(q1.build(), BooleanClause.Occur.SHOULD); q2.add(new CrazyMustUseBulkScorerQuery(), BooleanClause.Occur.SHOULD); - assertEquals(1, s.search(q2.build(), 10).totalHits); + assertEquals(1, s.search(q2.build(), 10).totalHits.value); r.close(); dir.close(); } diff --git a/lucene/core/src/test/org/apache/lucene/search/TestConjunctions.java b/lucene/core/src/test/org/apache/lucene/search/TestConjunctions.java index cc4f7fe67df..ebe7887384a 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestConjunctions.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestConjunctions.java @@ -79,7 +79,7 @@ public class TestConjunctions extends LuceneTestCase { bq.add(new TermQuery(new Term(F1, "nutch")), BooleanClause.Occur.MUST); bq.add(new TermQuery(new Term(F2, "is")), BooleanClause.Occur.MUST); TopDocs td = searcher.search(bq.build(), 3); - assertEquals(1, td.totalHits); + assertEquals(1, td.totalHits.value); assertEquals(3F, td.scoreDocs[0].score, 0.001F); // f1:nutch + f2:is + f2:is } diff --git a/lucene/core/src/test/org/apache/lucene/search/TestControlledRealTimeReopenThread.java b/lucene/core/src/test/org/apache/lucene/search/TestControlledRealTimeReopenThread.java index c1157fff55b..c8f9c8489c7 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestControlledRealTimeReopenThread.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestControlledRealTimeReopenThread.java @@ -107,7 +107,7 @@ public class TestControlledRealTimeReopenThread extends ThreadedIndexingAndSearc System.out.println(Thread.currentThread().getName() + ": nrt: got deletes searcher=" + s); } try { - assertEquals(docs.size(), s.search(new TermQuery(id), 10).totalHits); + assertEquals(docs.size(), s.search(new TermQuery(id), 10).totalHits.value); } finally { nrtDeletes.release(s); } @@ -131,7 +131,7 @@ public class TestControlledRealTimeReopenThread extends ThreadedIndexingAndSearc System.out.println(Thread.currentThread().getName() + ": nrt: got noDeletes searcher=" + s); } try { - assertEquals(docs.size(), s.search(new TermQuery(id), 10).totalHits); + assertEquals(docs.size(), s.search(new TermQuery(id), 10).totalHits.value); } finally { nrtNoDeletes.release(s); } @@ -155,7 +155,7 @@ public class TestControlledRealTimeReopenThread extends ThreadedIndexingAndSearc System.out.println(Thread.currentThread().getName() + ": nrt: got noDeletes searcher=" + s); } try { - assertEquals(1, s.search(new TermQuery(id), 10).totalHits); + assertEquals(1, s.search(new TermQuery(id), 10).totalHits.value); } finally { nrtNoDeletes.release(s); } @@ -178,7 +178,7 @@ public class TestControlledRealTimeReopenThread extends ThreadedIndexingAndSearc System.out.println(Thread.currentThread().getName() + ": nrt: got deletes searcher=" + s); } try { - assertEquals(1, s.search(new TermQuery(id), 10).totalHits); + assertEquals(1, s.search(new TermQuery(id), 10).totalHits.value); } finally { nrtDeletes.release(s); } @@ -201,7 +201,7 @@ public class TestControlledRealTimeReopenThread extends ThreadedIndexingAndSearc System.out.println(Thread.currentThread().getName() + ": nrt: got deletes searcher=" + s); } try { - assertEquals(0, s.search(new TermQuery(id), 10).totalHits); + assertEquals(0, s.search(new TermQuery(id), 10).totalHits.value); } finally { nrtDeletes.release(s); } @@ -524,7 +524,7 @@ public class TestControlledRealTimeReopenThread extends ThreadedIndexingAndSearc IndexSearcher searcher = sm.acquire(); TopDocs td = searcher.search(new TermQuery(new Term("count", i + "")), 10); sm.release(searcher); - assertEquals(1, td.totalHits); + assertEquals(1, td.totalHits.value); } for(Thread commitThread : commitThreads) { diff --git a/lucene/core/src/test/org/apache/lucene/search/TestDocValuesQueries.java b/lucene/core/src/test/org/apache/lucene/search/TestDocValuesQueries.java index d70c09d5372..0664709c478 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestDocValuesQueries.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestDocValuesQueries.java @@ -175,7 +175,7 @@ public class TestDocValuesQueries extends LuceneTestCase { final int maxDoc = searcher.getIndexReader().maxDoc(); final TopDocs td1 = searcher.search(q1, maxDoc, scores ? Sort.RELEVANCE : Sort.INDEXORDER); final TopDocs td2 = searcher.search(q2, maxDoc, scores ? Sort.RELEVANCE : Sort.INDEXORDER); - assertEquals(td1.totalHits, td2.totalHits); + assertEquals(td1.totalHits.value, td2.totalHits.value); for (int i = 0; i < td1.scoreDocs.length; ++i) { assertEquals(td1.scoreDocs[i].doc, td2.scoreDocs[i].doc); if (scores) { diff --git a/lucene/core/src/test/org/apache/lucene/search/TestDoubleValuesSource.java b/lucene/core/src/test/org/apache/lucene/search/TestDoubleValuesSource.java index 9806add2fec..e300cf71c59 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestDoubleValuesSource.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestDoubleValuesSource.java @@ -169,7 +169,7 @@ public class TestDoubleValuesSource extends LuceneTestCase { CheckHits.checkEqual(query, expected.scoreDocs, actual.scoreDocs); - if (size < actual.totalHits) { + if (size < actual.totalHits.value) { expected = searcher.searchAfter(expected.scoreDocs[size-1], query, size, sort); actual = searcher.searchAfter(actual.scoreDocs[size-1], query, size, mutatedSort); CheckHits.checkEqual(query, expected.scoreDocs, actual.scoreDocs); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestFieldValueQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestFieldValueQuery.java index f5d46e9a5c9..53ea61de641 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestFieldValueQuery.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestFieldValueQuery.java @@ -202,7 +202,7 @@ public class TestFieldValueQuery extends LuceneTestCase { final int maxDoc = searcher.getIndexReader().maxDoc(); final TopDocs td1 = searcher.search(q1, maxDoc, scores ? Sort.RELEVANCE : Sort.INDEXORDER); final TopDocs td2 = searcher.search(q2, maxDoc, scores ? Sort.RELEVANCE : Sort.INDEXORDER); - assertEquals(td1.totalHits, td2.totalHits); + assertEquals(td1.totalHits.value, td2.totalHits.value); for (int i = 0; i < td1.scoreDocs.length; ++i) { assertEquals(td1.scoreDocs[i].doc, td2.scoreDocs[i].doc); if (scores) { diff --git a/lucene/core/src/test/org/apache/lucene/search/TestFuzzyQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestFuzzyQuery.java index ebaf3c0095b..024abc3c95f 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestFuzzyQuery.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestFuzzyQuery.java @@ -367,7 +367,7 @@ public class TestFuzzyQuery extends LuceneTestCase { IndexSearcher searcher = newSearcher(mr); FuzzyQuery fq = new FuzzyQuery(new Term("field", "z123456"), 1, 0, 2, false); TopDocs docs = searcher.search(fq, 2); - assertEquals(5, docs.totalHits); // 5 docs, from the a and b's + assertEquals(5, docs.totalHits.value); // 5 docs, from the a and b's mr.close(); ir1.close(); ir2.close(); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestIndexSearcher.java b/lucene/core/src/test/org/apache/lucene/search/TestIndexSearcher.java index 37f90de1005..7e4c3c22d91 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestIndexSearcher.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestIndexSearcher.java @@ -165,7 +165,7 @@ public class TestIndexSearcher extends LuceneTestCase { .add(new TermQuery(new Term("foo", "baz")), Occur.SHOULD) .build() )) { - assertEquals(searcher.count(query), searcher.search(query, 1).totalHits); + assertEquals(searcher.count(query), searcher.search(query, 1).totalHits.value); } reader.close(); } diff --git a/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java b/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java index 8443d86700d..a30e026b499 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java @@ -148,7 +148,7 @@ public class TestLRUQueryCache extends LuceneTestCase { TotalHitCountCollector collector = new TotalHitCountCollector(); searcher.search(q, collector); // will use the cache final int totalHits1 = collector.getTotalHits(); - final long totalHits2 = searcher.search(q, 1).totalHits; // will not use the cache because of scores + final long totalHits2 = searcher.search(q, 1).totalHits.value; // will not use the cache because of scores assertEquals(totalHits2, totalHits1); } finally { mgr.release(searcher); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestLiveFieldValues.java b/lucene/core/src/test/org/apache/lucene/search/TestLiveFieldValues.java index 9346428fa2b..b0440facfcf 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestLiveFieldValues.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestLiveFieldValues.java @@ -62,8 +62,8 @@ public class TestLiveFieldValues extends LuceneTestCase { protected Integer lookupFromSearcher(IndexSearcher s, String id) throws IOException { TermQuery tq = new TermQuery(new Term("id", id)); TopDocs hits = s.search(tq, 1); - assertTrue(hits.totalHits <= 1); - if (hits.totalHits == 0) { + assertTrue(hits.totalHits.value <= 1); + if (hits.totalHits.value == 0) { return null; } else { Document doc = s.doc(hits.scoreDocs[0].doc); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestLongValuesSource.java b/lucene/core/src/test/org/apache/lucene/search/TestLongValuesSource.java index f33292d489e..dd6694e5d09 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestLongValuesSource.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestLongValuesSource.java @@ -141,7 +141,7 @@ public class TestLongValuesSource extends LuceneTestCase { CheckHits.checkEqual(query, expected.scoreDocs, actual.scoreDocs); - if (size < actual.totalHits) { + if (size < actual.totalHits.value) { expected = searcher.searchAfter(expected.scoreDocs[size-1], query, size, sort); actual = searcher.searchAfter(actual.scoreDocs[size-1], query, size, mutatedSort); CheckHits.checkEqual(query, expected.scoreDocs, actual.scoreDocs); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java index 419379622db..3d481baed87 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java @@ -376,10 +376,10 @@ public class TestMultiPhraseQuery extends LuceneTestCase { mpqb.add(new Term[] {new Term("field", "b"), new Term("field", "c")}, 0); } TopDocs hits = s.search(mpqb.build(), 2); - assertEquals(2, hits.totalHits); + assertEquals(2, hits.totalHits.value); assertEquals(hits.scoreDocs[0].score, hits.scoreDocs[1].score, 1e-5); /* - for(int hit=0;hit 0); } diff --git a/lucene/core/src/test/org/apache/lucene/search/TestPrefixInBooleanQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestPrefixInBooleanQuery.java index d33bdaf46b5..c9f723b01a1 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestPrefixInBooleanQuery.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestPrefixInBooleanQuery.java @@ -85,12 +85,12 @@ public class TestPrefixInBooleanQuery extends LuceneTestCase { public void testPrefixQuery() throws Exception { Query query = new PrefixQuery(new Term(FIELD, "tang")); assertEquals("Number of matched documents", 2, - searcher.search(query, 1000).totalHits); + searcher.search(query, 1000).totalHits.value); } public void testTermQuery() throws Exception { Query query = new TermQuery(new Term(FIELD, "tangfulin")); assertEquals("Number of matched documents", 2, - searcher.search(query, 1000).totalHits); + searcher.search(query, 1000).totalHits.value); } public void testTermBooleanQuery() throws Exception { BooleanQuery.Builder query = new BooleanQuery.Builder(); @@ -99,7 +99,7 @@ public class TestPrefixInBooleanQuery extends LuceneTestCase { query.add(new TermQuery(new Term(FIELD, "notexistnames")), BooleanClause.Occur.SHOULD); assertEquals("Number of matched documents", 2, - searcher.search(query.build(), 1000).totalHits); + searcher.search(query.build(), 1000).totalHits.value); } public void testPrefixBooleanQuery() throws Exception { @@ -109,6 +109,6 @@ public class TestPrefixInBooleanQuery extends LuceneTestCase { query.add(new TermQuery(new Term(FIELD, "notexistnames")), BooleanClause.Occur.SHOULD); assertEquals("Number of matched documents", 2, - searcher.search(query.build(), 1000).totalHits); + searcher.search(query.build(), 1000).totalHits.value); } } diff --git a/lucene/core/src/test/org/apache/lucene/search/TestPrefixQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestPrefixQuery.java index b5c5ca198a8..2395d0b94ef 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestPrefixQuery.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestPrefixQuery.java @@ -83,7 +83,7 @@ public class TestPrefixQuery extends LuceneTestCase { PrefixQuery query = new PrefixQuery(new Term("field", "")); IndexSearcher searcher = newSearcher(reader); - assertEquals(1, searcher.search(query, 1000).totalHits); + assertEquals(1, searcher.search(query, 1000).totalHits.value); writer.close(); reader.close(); directory.close(); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java b/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java index d1f307d063e..8bbfeb59fc6 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java @@ -79,7 +79,7 @@ public class TestQueryRescorer extends LuceneTestCase { searcher.setSimilarity(new ClassicSimilarity()); TopDocs hits = searcher.search(bq.build(), 10); - assertEquals(2, hits.totalHits); + assertEquals(2, hits.totalHits.value); assertEquals("0", searcher.doc(hits.scoreDocs[0].doc).get("id")); assertEquals("1", searcher.doc(hits.scoreDocs[1].doc).get("id")); @@ -89,7 +89,7 @@ public class TestQueryRescorer extends LuceneTestCase { TopDocs hits2 = QueryRescorer.rescore(searcher, hits, pq, 2.0, 10); // Resorting changed the order: - assertEquals(2, hits2.totalHits); + assertEquals(2, hits2.totalHits.value); assertEquals("1", searcher.doc(hits2.scoreDocs[0].doc).get("id")); assertEquals("0", searcher.doc(hits2.scoreDocs[1].doc).get("id")); @@ -101,7 +101,7 @@ public class TestQueryRescorer extends LuceneTestCase { TopDocs hits3 = QueryRescorer.rescore(searcher, hits, snq, 2.0, 10); // Resorting changed the order: - assertEquals(2, hits3.totalHits); + assertEquals(2, hits3.totalHits.value); assertEquals("1", searcher.doc(hits3.scoreDocs[0].doc).get("id")); assertEquals("0", searcher.doc(hits3.scoreDocs[1].doc).get("id")); @@ -134,7 +134,7 @@ public class TestQueryRescorer extends LuceneTestCase { searcher.setSimilarity(new ClassicSimilarity()); TopDocs hits = searcher.search(bq.build(), 10); - assertEquals(2, hits.totalHits); + assertEquals(2, hits.totalHits.value); assertEquals("0", searcher.doc(hits.scoreDocs[0].doc).get("id")); assertEquals("1", searcher.doc(hits.scoreDocs[1].doc).get("id")); @@ -143,7 +143,7 @@ public class TestQueryRescorer extends LuceneTestCase { TopDocs hits2 = QueryRescorer.rescore(searcher, hits, tq, 2.0, 10); // Just testing that null scorer is handled. - assertEquals(2, hits2.totalHits); + assertEquals(2, hits2.totalHits.value); r.close(); dir.close(); @@ -172,7 +172,7 @@ public class TestQueryRescorer extends LuceneTestCase { IndexSearcher searcher = getSearcher(r); TopDocs hits = searcher.search(bq.build(), 10); - assertEquals(2, hits.totalHits); + assertEquals(2, hits.totalHits.value); assertEquals("0", searcher.doc(hits.scoreDocs[0].doc).get("id")); assertEquals("1", searcher.doc(hits.scoreDocs[1].doc).get("id")); @@ -192,7 +192,7 @@ public class TestQueryRescorer extends LuceneTestCase { }.rescore(searcher, hits, 10); // Resorting didn't change the order: - assertEquals(2, hits2.totalHits); + assertEquals(2, hits2.totalHits.value); assertEquals("0", searcher.doc(hits2.scoreDocs[0].doc).get("id")); assertEquals("1", searcher.doc(hits2.scoreDocs[1].doc).get("id")); @@ -223,7 +223,7 @@ public class TestQueryRescorer extends LuceneTestCase { IndexSearcher searcher = getSearcher(r); TopDocs hits = searcher.search(bq.build(), 10); - assertEquals(2, hits.totalHits); + assertEquals(2, hits.totalHits.value); assertEquals("0", searcher.doc(hits.scoreDocs[0].doc).get("id")); assertEquals("1", searcher.doc(hits.scoreDocs[1].doc).get("id")); @@ -244,7 +244,7 @@ public class TestQueryRescorer extends LuceneTestCase { TopDocs hits2 = rescorer.rescore(searcher, hits, 10); // Resorting changed the order: - assertEquals(2, hits2.totalHits); + assertEquals(2, hits2.totalHits.value); assertEquals("1", searcher.doc(hits2.scoreDocs[0].doc).get("id")); assertEquals("0", searcher.doc(hits2.scoreDocs[1].doc).get("id")); @@ -298,7 +298,7 @@ public class TestQueryRescorer extends LuceneTestCase { IndexSearcher searcher = getSearcher(r); TopDocs hits = searcher.search(bq.build(), 10); - assertEquals(2, hits.totalHits); + assertEquals(2, hits.totalHits.value); assertEquals("0", searcher.doc(hits.scoreDocs[0].doc).get("id")); assertEquals("1", searcher.doc(hits.scoreDocs[1].doc).get("id")); @@ -308,7 +308,7 @@ public class TestQueryRescorer extends LuceneTestCase { TopDocs hits2 = QueryRescorer.rescore(searcher, hits, pq, 2.0, 10); // Resorting changed the order: - assertEquals(2, hits2.totalHits); + assertEquals(2, hits2.totalHits.value); assertEquals("1", searcher.doc(hits2.scoreDocs[0].doc).get("id")); assertEquals("0", searcher.doc(hits2.scoreDocs[1].doc).get("id")); @@ -320,7 +320,7 @@ public class TestQueryRescorer extends LuceneTestCase { TopDocs hits3 = QueryRescorer.rescore(searcher, hits, snq, 2.0, 10); // Resorting changed the order: - assertEquals(2, hits3.totalHits); + assertEquals(2, hits3.totalHits.value); assertEquals("1", searcher.doc(hits3.scoreDocs[0].doc).get("id")); assertEquals("0", searcher.doc(hits3.scoreDocs[1].doc).get("id")); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestRegexpQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestRegexpQuery.java index ad1319b5c1b..6a8e183e0d4 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestRegexpQuery.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestRegexpQuery.java @@ -70,7 +70,7 @@ public class TestRegexpQuery extends LuceneTestCase { private long regexQueryNrHits(String regex) throws IOException { RegexpQuery query = new RegexpQuery(newTerm(regex)); - return searcher.search(query, 5).totalHits; + return searcher.count(query); } public void testRegex1() throws IOException { @@ -112,7 +112,7 @@ public class TestRegexpQuery extends LuceneTestCase { }; RegexpQuery query = new RegexpQuery(newTerm(""), RegExp.ALL, myProvider, DEFAULT_MAX_DETERMINIZED_STATES); - assertEquals(1, searcher.search(query, 5).totalHits); + assertEquals(1, searcher.search(query, 5).totalHits.value); } /** diff --git a/lucene/core/src/test/org/apache/lucene/search/TestRegexpRandom.java b/lucene/core/src/test/org/apache/lucene/search/TestRegexpRandom.java index e16a426402f..45bd62518a1 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestRegexpRandom.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestRegexpRandom.java @@ -90,7 +90,7 @@ public class TestRegexpRandom extends LuceneTestCase { private void assertPatternHits(String pattern, int numHits) throws Exception { Query wq = new RegexpQuery(new Term("field", fillPattern(pattern))); TopDocs docs = searcher.search(wq, 25); - assertEquals("Incorrect hits for pattern: " + pattern, numHits, docs.totalHits); + assertEquals("Incorrect hits for pattern: " + pattern, numHits, docs.totalHits.value); } @Override diff --git a/lucene/core/src/test/org/apache/lucene/search/TestSameScoresWithThreads.java b/lucene/core/src/test/org/apache/lucene/search/TestSameScoresWithThreads.java index 88f92a5a503..efb7e5e254d 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestSameScoresWithThreads.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestSameScoresWithThreads.java @@ -97,7 +97,7 @@ public class TestSameScoresWithThreads extends LuceneTestCase { for(Map.Entry ent : shuffled) { TopDocs actual = s.search(new TermQuery(new Term("body", ent.getKey())), 100); TopDocs expected = ent.getValue(); - assertEquals(expected.totalHits, actual.totalHits); + assertEquals(expected.totalHits.value, actual.totalHits.value); assertEquals("query=" + ent.getKey().utf8ToString(), expected.scoreDocs.length, actual.scoreDocs.length); for(int hit=0;hit 0); + assertTrue(foodocs.totalHits.value > 0); TopDocs bardocs = searcher.search(new TermQuery(new Term("bar", "brown")), 10); - assertTrue(bardocs.totalHits > 0); + assertTrue(bardocs.totalHits.value > 0); assertTrue(foodocs.scoreDocs[0].score < bardocs.scoreDocs[0].score); } diff --git a/lucene/core/src/test/org/apache/lucene/search/TestSloppyPhraseQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestSloppyPhraseQuery.java index bee5126a790..2fd22a0278d 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestSloppyPhraseQuery.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestSloppyPhraseQuery.java @@ -261,13 +261,13 @@ public class TestSloppyPhraseQuery extends LuceneTestCase { builder.add(new Term("lyrics", "drug"), 4); PhraseQuery pq = builder.build(); // "drug the drug"~1 - assertEquals(1, is.search(pq, 4).totalHits); + assertEquals(1, is.search(pq, 4).totalHits.value); builder.setSlop(1); pq = builder.build(); - assertEquals(3, is.search(pq, 4).totalHits); + assertEquals(3, is.search(pq, 4).totalHits.value); builder.setSlop(2); pq = builder.build(); - assertEquals(4, is.search(pq, 4).totalHits); + assertEquals(4, is.search(pq, 4).totalHits.value); ir.close(); dir.close(); } diff --git a/lucene/core/src/test/org/apache/lucene/search/TestSort.java b/lucene/core/src/test/org/apache/lucene/search/TestSort.java index 2543c1bc541..d37c98ddc91 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestSort.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestSort.java @@ -102,7 +102,7 @@ public class TestSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.STRING)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); // 'bar' comes before 'foo' assertEquals("bar", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("foo", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -130,7 +130,7 @@ public class TestSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.STRING, true)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); // 'foo' comes after 'bar' in reverse order assertEquals("foo", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("bar", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -158,7 +158,7 @@ public class TestSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.STRING_VAL)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); // 'bar' comes before 'foo' assertEquals("bar", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("foo", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -186,7 +186,7 @@ public class TestSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.STRING_VAL, true)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); // 'foo' comes after 'bar' in reverse order assertEquals("foo", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("bar", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -214,7 +214,7 @@ public class TestSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.STRING_VAL)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); // 'bar' comes before 'foo' assertEquals("bar", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("foo", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -242,7 +242,7 @@ public class TestSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.STRING_VAL, true)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); // 'foo' comes after 'bar' in reverse order assertEquals("foo", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("bar", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -274,7 +274,7 @@ public class TestSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.INT)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // numeric order assertEquals("-1", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -307,7 +307,7 @@ public class TestSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.INT, true)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // reverse numeric order assertEquals("300000", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -338,7 +338,7 @@ public class TestSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.INT)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // null is treated as a 0 assertEquals("-1", searcher.doc(td.scoreDocs[0].doc).get("value")); assertNull(searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -371,7 +371,7 @@ public class TestSort extends LuceneTestCase { Sort sort = new Sort(sortField); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // null is treated as a Integer.MAX_VALUE assertEquals("-1", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -404,7 +404,7 @@ public class TestSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.LONG)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // numeric order assertEquals("-1", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -437,7 +437,7 @@ public class TestSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.LONG, true)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // reverse numeric order assertEquals("3000000000", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -468,7 +468,7 @@ public class TestSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.LONG)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // null is treated as 0 assertEquals("-1", searcher.doc(td.scoreDocs[0].doc).get("value")); assertNull(searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -501,7 +501,7 @@ public class TestSort extends LuceneTestCase { Sort sort = new Sort(sortField); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // null is treated as Long.MAX_VALUE assertEquals("-1", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -534,7 +534,7 @@ public class TestSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.FLOAT)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // numeric order assertEquals("-1.3", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4.2", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -567,7 +567,7 @@ public class TestSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.FLOAT, true)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // reverse numeric order assertEquals("30.1", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4.2", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -598,7 +598,7 @@ public class TestSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.FLOAT)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // null is treated as 0 assertEquals("-1.3", searcher.doc(td.scoreDocs[0].doc).get("value")); assertNull(searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -631,7 +631,7 @@ public class TestSort extends LuceneTestCase { Sort sort = new Sort(sortField); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // null is treated as Float.MAX_VALUE assertEquals("-1.3", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4.2", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -668,7 +668,7 @@ public class TestSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.DOUBLE)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(4, td.totalHits); + assertEquals(4, td.totalHits.value); // numeric order assertEquals("-1.3", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4.2333333333332", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -699,7 +699,7 @@ public class TestSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.DOUBLE)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); // numeric order assertEquals("-0", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("+0", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -735,7 +735,7 @@ public class TestSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.DOUBLE, true)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(4, td.totalHits); + assertEquals(4, td.totalHits.value); // numeric order assertEquals("30.1", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4.2333333333333", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -771,7 +771,7 @@ public class TestSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.DOUBLE)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(4, td.totalHits); + assertEquals(4, td.totalHits.value); // null treated as a 0 assertEquals("-1.3", searcher.doc(td.scoreDocs[0].doc).get("value")); assertNull(searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -809,7 +809,7 @@ public class TestSort extends LuceneTestCase { Sort sort = new Sort(sortField); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(4, td.totalHits); + assertEquals(4, td.totalHits.value); // null treated as Double.MAX_VALUE assertEquals("-1.3", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4.2333333333332", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -857,7 +857,7 @@ public class TestSort extends LuceneTestCase { new SortField("value2", SortField.Type.LONG)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(4, td.totalHits); + assertEquals(4, td.totalHits.value); // 'bar' comes before 'foo' assertEquals("bar", searcher.doc(td.scoreDocs[0].doc).get("value1")); assertEquals("bar", searcher.doc(td.scoreDocs[1].doc).get("value1")); @@ -871,7 +871,7 @@ public class TestSort extends LuceneTestCase { // Now with overflow td = searcher.search(new MatchAllDocsQuery(), 1, sort); - assertEquals(4, td.totalHits); + assertEquals(4, td.totalHits.value); assertEquals("bar", searcher.doc(td.scoreDocs[0].doc).get("value1")); assertEquals("0", searcher.doc(td.scoreDocs[0].doc).get("value2")); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestSortRescorer.java b/lucene/core/src/test/org/apache/lucene/search/TestSortRescorer.java index 105525996c5..a60ed49fc2e 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestSortRescorer.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestSortRescorer.java @@ -84,7 +84,7 @@ public class TestSortRescorer extends LuceneTestCase { // Just first pass query TopDocs hits = searcher.search(query, 10); - assertEquals(3, hits.totalHits); + assertEquals(3, hits.totalHits.value); assertEquals("3", r.document(hits.scoreDocs[0].doc).get("id")); assertEquals("1", r.document(hits.scoreDocs[1].doc).get("id")); assertEquals("2", r.document(hits.scoreDocs[2].doc).get("id")); @@ -93,7 +93,7 @@ public class TestSortRescorer extends LuceneTestCase { Sort sort = new Sort(new SortField("popularity", SortField.Type.INT, true)); Rescorer rescorer = new SortRescorer(sort); hits = rescorer.rescore(searcher, hits, 10); - assertEquals(3, hits.totalHits); + assertEquals(3, hits.totalHits.value); assertEquals("2", r.document(hits.scoreDocs[0].doc).get("id")); assertEquals("1", r.document(hits.scoreDocs[1].doc).get("id")); assertEquals("3", r.document(hits.scoreDocs[2].doc).get("id")); @@ -119,7 +119,7 @@ public class TestSortRescorer extends LuceneTestCase { // Just first pass query TopDocs hits = searcher.search(query, 10); - assertEquals(3, hits.totalHits); + assertEquals(3, hits.totalHits.value); assertEquals("3", r.document(hits.scoreDocs[0].doc).get("id")); assertEquals("1", r.document(hits.scoreDocs[1].doc).get("id")); assertEquals("2", r.document(hits.scoreDocs[2].doc).get("id")); @@ -130,7 +130,7 @@ public class TestSortRescorer extends LuceneTestCase { Sort sort = new Sort(source.getSortField(true)); Rescorer rescorer = new SortRescorer(sort); hits = rescorer.rescore(searcher, hits, 10); - assertEquals(3, hits.totalHits); + assertEquals(3, hits.totalHits.value); assertEquals("2", r.document(hits.scoreDocs[0].doc).get("id")); assertEquals("1", r.document(hits.scoreDocs[1].doc).get("id")); assertEquals("3", r.document(hits.scoreDocs[2].doc).get("id")); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestSortedNumericSortField.java b/lucene/core/src/test/org/apache/lucene/search/TestSortedNumericSortField.java index 37fb710902f..4aed2972d28 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestSortedNumericSortField.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestSortedNumericSortField.java @@ -37,13 +37,13 @@ public class TestSortedNumericSortField extends LuceneTestCase { Sort sort = new Sort(); sort.setSort(new SortedNumericSortField("sortednumeric", SortField.Type.LONG)); TopDocs td = empty.search(query, 10, sort, true); - assertEquals(0, td.totalHits); + assertEquals(0, td.totalHits.value); // for an empty index, any selector should work for (SortedNumericSelector.Type v : SortedNumericSelector.Type.values()) { sort.setSort(new SortedNumericSortField("sortednumeric", SortField.Type.LONG, false, v)); td = empty.search(query, 10, sort, true); - assertEquals(0, td.totalHits); + assertEquals(0, td.totalHits.value); } } @@ -83,7 +83,7 @@ public class TestSortedNumericSortField extends LuceneTestCase { Sort sort = new Sort(new SortedNumericSortField("value", SortField.Type.INT)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); // 3 comes before 5 assertEquals("1", searcher.doc(td.scoreDocs[0].doc).get("id")); assertEquals("2", searcher.doc(td.scoreDocs[1].doc).get("id")); @@ -112,7 +112,7 @@ public class TestSortedNumericSortField extends LuceneTestCase { Sort sort = new Sort(new SortedNumericSortField("value", SortField.Type.INT, true)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); // 'bar' comes before 'baz' assertEquals("2", searcher.doc(td.scoreDocs[0].doc).get("id")); assertEquals("1", searcher.doc(td.scoreDocs[1].doc).get("id")); @@ -145,7 +145,7 @@ public class TestSortedNumericSortField extends LuceneTestCase { Sort sort = new Sort(sortField); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // 3 comes before 5 // null comes first assertEquals("3", searcher.doc(td.scoreDocs[0].doc).get("id")); @@ -180,7 +180,7 @@ public class TestSortedNumericSortField extends LuceneTestCase { Sort sort = new Sort(sortField); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // 3 comes before 5 assertEquals("1", searcher.doc(td.scoreDocs[0].doc).get("id")); assertEquals("2", searcher.doc(td.scoreDocs[1].doc).get("id")); @@ -209,7 +209,7 @@ public class TestSortedNumericSortField extends LuceneTestCase { Sort sort = new Sort(new SortedNumericSortField("value", SortField.Type.INT)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); // 3 comes before 5 assertEquals("1", searcher.doc(td.scoreDocs[0].doc).get("id")); assertEquals("2", searcher.doc(td.scoreDocs[1].doc).get("id")); @@ -237,7 +237,7 @@ public class TestSortedNumericSortField extends LuceneTestCase { Sort sort = new Sort(new SortedNumericSortField("value", SortField.Type.FLOAT)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); // -5 comes before -3 assertEquals("1", searcher.doc(td.scoreDocs[0].doc).get("id")); assertEquals("2", searcher.doc(td.scoreDocs[1].doc).get("id")); @@ -265,7 +265,7 @@ public class TestSortedNumericSortField extends LuceneTestCase { Sort sort = new Sort(new SortedNumericSortField("value", SortField.Type.DOUBLE)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); // -5 comes before -3 assertEquals("1", searcher.doc(td.scoreDocs[0].doc).get("id")); assertEquals("2", searcher.doc(td.scoreDocs[1].doc).get("id")); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestSortedSetSelector.java b/lucene/core/src/test/org/apache/lucene/search/TestSortedSetSelector.java index 16daf2b2629..faff91076cc 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestSortedSetSelector.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestSortedSetSelector.java @@ -53,7 +53,7 @@ public class TestSortedSetSelector extends LuceneTestCase { Sort sort = new Sort(new SortedSetSortField("value", false, SortedSetSelector.Type.MAX)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); // 'baz' comes before 'foo' assertEquals("2", searcher.doc(td.scoreDocs[0].doc).get("id")); assertEquals("1", searcher.doc(td.scoreDocs[1].doc).get("id")); @@ -83,7 +83,7 @@ public class TestSortedSetSelector extends LuceneTestCase { Sort sort = new Sort(new SortedSetSortField("value", true, SortedSetSelector.Type.MAX)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); // 'baz' comes before 'foo' assertEquals("1", searcher.doc(td.scoreDocs[0].doc).get("id")); assertEquals("2", searcher.doc(td.scoreDocs[1].doc).get("id")); @@ -118,7 +118,7 @@ public class TestSortedSetSelector extends LuceneTestCase { Sort sort = new Sort(sortField); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // null comes first assertEquals("1", searcher.doc(td.scoreDocs[0].doc).get("id")); // 'baz' comes before 'foo' @@ -155,7 +155,7 @@ public class TestSortedSetSelector extends LuceneTestCase { Sort sort = new Sort(sortField); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // 'baz' comes before 'foo' assertEquals("3", searcher.doc(td.scoreDocs[0].doc).get("id")); assertEquals("2", searcher.doc(td.scoreDocs[1].doc).get("id")); @@ -185,7 +185,7 @@ public class TestSortedSetSelector extends LuceneTestCase { Sort sort = new Sort(new SortedSetSortField("value", false, SortedSetSelector.Type.MAX)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); // 'bar' comes before 'baz' assertEquals("1", searcher.doc(td.scoreDocs[0].doc).get("id")); assertEquals("2", searcher.doc(td.scoreDocs[1].doc).get("id")); @@ -216,7 +216,7 @@ public class TestSortedSetSelector extends LuceneTestCase { Sort sort = new Sort(new SortedSetSortField("value", false, SortedSetSelector.Type.MIDDLE_MIN)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); // 'b' comes before 'c' assertEquals("1", searcher.doc(td.scoreDocs[0].doc).get("id")); assertEquals("2", searcher.doc(td.scoreDocs[1].doc).get("id")); @@ -247,7 +247,7 @@ public class TestSortedSetSelector extends LuceneTestCase { Sort sort = new Sort(new SortedSetSortField("value", true, SortedSetSelector.Type.MIDDLE_MIN)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); // 'b' comes before 'c' assertEquals("2", searcher.doc(td.scoreDocs[0].doc).get("id")); assertEquals("1", searcher.doc(td.scoreDocs[1].doc).get("id")); @@ -283,7 +283,7 @@ public class TestSortedSetSelector extends LuceneTestCase { Sort sort = new Sort(sortField); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // null comes first assertEquals("3", searcher.doc(td.scoreDocs[0].doc).get("id")); // 'b' comes before 'c' @@ -321,7 +321,7 @@ public class TestSortedSetSelector extends LuceneTestCase { Sort sort = new Sort(sortField); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // 'b' comes before 'c' assertEquals("1", searcher.doc(td.scoreDocs[0].doc).get("id")); assertEquals("2", searcher.doc(td.scoreDocs[1].doc).get("id")); @@ -351,7 +351,7 @@ public class TestSortedSetSelector extends LuceneTestCase { Sort sort = new Sort(new SortedSetSortField("value", false, SortedSetSelector.Type.MIDDLE_MIN)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); // 'bar' comes before 'baz' assertEquals("1", searcher.doc(td.scoreDocs[0].doc).get("id")); assertEquals("2", searcher.doc(td.scoreDocs[1].doc).get("id")); @@ -382,7 +382,7 @@ public class TestSortedSetSelector extends LuceneTestCase { Sort sort = new Sort(new SortedSetSortField("value", false, SortedSetSelector.Type.MIDDLE_MAX)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); // 'b' comes before 'c' assertEquals("2", searcher.doc(td.scoreDocs[0].doc).get("id")); assertEquals("1", searcher.doc(td.scoreDocs[1].doc).get("id")); @@ -413,7 +413,7 @@ public class TestSortedSetSelector extends LuceneTestCase { Sort sort = new Sort(new SortedSetSortField("value", true, SortedSetSelector.Type.MIDDLE_MAX)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); // 'b' comes before 'c' assertEquals("1", searcher.doc(td.scoreDocs[0].doc).get("id")); assertEquals("2", searcher.doc(td.scoreDocs[1].doc).get("id")); @@ -449,7 +449,7 @@ public class TestSortedSetSelector extends LuceneTestCase { Sort sort = new Sort(sortField); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // null comes first assertEquals("3", searcher.doc(td.scoreDocs[0].doc).get("id")); // 'b' comes before 'c' @@ -487,7 +487,7 @@ public class TestSortedSetSelector extends LuceneTestCase { Sort sort = new Sort(sortField); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // 'b' comes before 'c' assertEquals("2", searcher.doc(td.scoreDocs[0].doc).get("id")); assertEquals("1", searcher.doc(td.scoreDocs[1].doc).get("id")); @@ -517,7 +517,7 @@ public class TestSortedSetSelector extends LuceneTestCase { Sort sort = new Sort(new SortedSetSortField("value", false, SortedSetSelector.Type.MIDDLE_MAX)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); // 'bar' comes before 'baz' assertEquals("1", searcher.doc(td.scoreDocs[0].doc).get("id")); assertEquals("2", searcher.doc(td.scoreDocs[1].doc).get("id")); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestSortedSetSortField.java b/lucene/core/src/test/org/apache/lucene/search/TestSortedSetSortField.java index 899e46dd8f1..d5851287b5b 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestSortedSetSortField.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestSortedSetSortField.java @@ -38,13 +38,13 @@ public class TestSortedSetSortField extends LuceneTestCase { Sort sort = new Sort(); sort.setSort(new SortedSetSortField("sortedset", false)); TopDocs td = empty.search(query, 10, sort, true); - assertEquals(0, td.totalHits); + assertEquals(0, td.totalHits.value); // for an empty index, any selector should work for (SortedSetSelector.Type v : SortedSetSelector.Type.values()) { sort.setSort(new SortedSetSortField("sortedset", false, v)); td = empty.search(query, 10, sort, true); - assertEquals(0, td.totalHits); + assertEquals(0, td.totalHits.value); } } @@ -83,7 +83,7 @@ public class TestSortedSetSortField extends LuceneTestCase { Sort sort = new Sort(new SortedSetSortField("value", false)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); // 'bar' comes before 'baz' assertEquals("1", searcher.doc(td.scoreDocs[0].doc).get("id")); assertEquals("2", searcher.doc(td.scoreDocs[1].doc).get("id")); @@ -112,7 +112,7 @@ public class TestSortedSetSortField extends LuceneTestCase { Sort sort = new Sort(new SortedSetSortField("value", true)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); // 'bar' comes before 'baz' assertEquals("2", searcher.doc(td.scoreDocs[0].doc).get("id")); assertEquals("1", searcher.doc(td.scoreDocs[1].doc).get("id")); @@ -145,7 +145,7 @@ public class TestSortedSetSortField extends LuceneTestCase { Sort sort = new Sort(sortField); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // 'bar' comes before 'baz' // null comes first assertEquals("3", searcher.doc(td.scoreDocs[0].doc).get("id")); @@ -180,7 +180,7 @@ public class TestSortedSetSortField extends LuceneTestCase { Sort sort = new Sort(sortField); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // 'bar' comes before 'baz' assertEquals("1", searcher.doc(td.scoreDocs[0].doc).get("id")); assertEquals("2", searcher.doc(td.scoreDocs[1].doc).get("id")); @@ -209,7 +209,7 @@ public class TestSortedSetSortField extends LuceneTestCase { Sort sort = new Sort(new SortedSetSortField("value", false)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); // 'bar' comes before 'baz' assertEquals("1", searcher.doc(td.scoreDocs[0].doc).get("id")); assertEquals("2", searcher.doc(td.scoreDocs[1].doc).get("id")); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestSynonymQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestSynonymQuery.java index 44f915e0c49..6165a1f80c6 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestSynonymQuery.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestSynonymQuery.java @@ -92,7 +92,7 @@ public class TestSynonymQuery extends LuceneTestCase { searcher.search(query, collector); TopDocs topDocs = collector.topDocs(); if (trackTotalHits) { - assertEquals(11, topDocs.totalHits); + assertEquals(11, topDocs.totalHits.value); } // All docs must have the same score for (int i = 0; i < topDocs.scoreDocs.length; ++i) { diff --git a/lucene/core/src/test/org/apache/lucene/search/TestTermRangeQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestTermRangeQuery.java index be59eb98995..892508b73b5 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); - long numHits = searcher.search(query, 1000).totalHits; + long numHits = searcher.search(query, 1000).totalHits.value; // When Lucene-38 is fixed, use the assert on the next line: assertEquals("A,B,,C,D => A, B & are in range", 3, numHits); // until Lucene-38 is fixed, use this assert: @@ -281,7 +281,7 @@ public class TestTermRangeQuery extends LuceneTestCase { initializeIndex(new String[] {"A", "B", "", "D"}, analyzer); reader = DirectoryReader.open(dir); searcher = newSearcher(reader); - numHits = searcher.search(query, 1000).totalHits; + numHits = searcher.search(query, 1000).totalHits.value; // When Lucene-38 is fixed, use the assert on the next line: assertEquals("A,B,,D => A, B & are in range", 3, numHits); // until Lucene-38 is fixed, use this assert: @@ -290,7 +290,7 @@ public class TestTermRangeQuery extends LuceneTestCase { addDoc("C"); reader = DirectoryReader.open(dir); searcher = newSearcher(reader); - numHits = searcher.search(query, 1000).totalHits; + numHits = searcher.search(query, 1000).totalHits.value; // When Lucene-38 is fixed, use the assert on the next line: assertEquals("C added, still A, B & 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); - long numHits = searcher.search(query, 1000).totalHits; + long numHits = searcher.search(query, 1000).totalHits.value; // When Lucene-38 is fixed, use the assert on the next line: assertEquals("A,B,,C,D => A,B,,C in range", 4, numHits); // until Lucene-38 is fixed, use this assert @@ -315,7 +315,7 @@ public class TestTermRangeQuery extends LuceneTestCase { initializeIndex(new String[]{"A", "B", "", "D"}, analyzer); reader = DirectoryReader.open(dir); searcher = newSearcher(reader); - numHits = searcher.search(query, 1000).totalHits; + numHits = searcher.search(query, 1000).totalHits.value; // When Lucene-38 is fixed, use the assert on the next line: assertEquals("A,B,,D - A, B and in range", 3, numHits); // until Lucene-38 is fixed, use this assert @@ -324,7 +324,7 @@ public class TestTermRangeQuery extends LuceneTestCase { addDoc("C"); reader = DirectoryReader.open(dir); searcher = newSearcher(reader); - numHits = searcher.search(query, 1000).totalHits; + numHits = searcher.search(query, 1000).totalHits.value; // When Lucene-38 is fixed, use the assert on the next line: assertEquals("C added => A,B,,C in range", 4, numHits); // until Lucene-38 is fixed, use this assert diff --git a/lucene/core/src/test/org/apache/lucene/search/TestTopDocsCollector.java b/lucene/core/src/test/org/apache/lucene/search/TestTopDocsCollector.java index 4cf36ef3294..831146512ce 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestTopDocsCollector.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestTopDocsCollector.java @@ -46,7 +46,7 @@ public class TestTopDocsCollector extends LuceneTestCase { return EMPTY_TOPDOCS; } - return new TopDocs(totalHits, results); + return new TopDocs(new TotalHits(totalHits, totalHitsRelation), results); } @Override @@ -288,7 +288,7 @@ public class TestTopDocsCollector extends LuceneTestCase { dir.close(); } - public void testEstimateHitCount() throws Exception { + public void testNotTrackTotalHits() throws Exception { Directory dir = newDirectory(); IndexWriter w = new IndexWriter(dir, newIndexWriterConfig().setMergePolicy(NoMergePolicy.INSTANCE)); Document doc = new Document(); @@ -323,64 +323,8 @@ public class TestTopDocsCollector extends LuceneTestCase { TopDocs topDocs = collector.topDocs(); // It assumes all docs matched since numHits was 2 and the first 2 collected docs matched - assertEquals(10, topDocs.totalHits); - - // Now test an index that is more sparsely collected - collector = TopScoreDocCollector.create(2, null, false); - - leafCollector = collector.getLeafCollector(reader.leaves().get(0)); - leafCollector.setScorer(scorer); - - scorer.doc = 1; - scorer.score = 3; - leafCollector.collect(1); - - leafCollector = collector.getLeafCollector(reader.leaves().get(1)); - leafCollector.setScorer(scorer); - - scorer.doc = 0; - scorer.score = 2; - leafCollector.collect(0); - - scorer.doc = 2; - scorer.score = 5; - leafCollector.collect(2); - - topDocs = collector.topDocs(); - assertEquals(4, topDocs.totalHits); - - // Same 2 first collected docs, but then we collect more docs to make sure - // that we use the actual number of collected docs as a lower bound - collector = TopScoreDocCollector.create(2, null, false); - - leafCollector = collector.getLeafCollector(reader.leaves().get(0)); - leafCollector.setScorer(scorer); - - scorer.doc = 1; - scorer.score = 3; - leafCollector.collect(1); - - leafCollector = collector.getLeafCollector(reader.leaves().get(1)); - leafCollector.setScorer(scorer); - - scorer.doc = 0; - scorer.score = 2; - leafCollector.collect(0); - - scorer.doc = 2; - scorer.score = 5; - leafCollector.collect(2); - - scorer.doc = 3; - scorer.score = 4; - leafCollector.collect(3); - - scorer.doc = 4; - scorer.score = 1; - leafCollector.collect(4); - - topDocs = collector.topDocs(); - assertEquals(5, topDocs.totalHits); + assertEquals(3, topDocs.totalHits.value); + assertEquals(TotalHits.Relation.GREATER_THAN_OR_EQUAL_TO, topDocs.totalHits.relation); reader.close(); dir.close(); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestTopDocsMerge.java b/lucene/core/src/test/org/apache/lucene/search/TestTopDocsMerge.java index 8d6e9d5d708..36f52751d64 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestTopDocsMerge.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestTopDocsMerge.java @@ -77,8 +77,8 @@ public class TestTopDocsMerge extends LuceneTestCase { public void testInconsistentTopDocsFail() { TopDocs[] topDocs = new TopDocs[] { - new TopDocs(1, new ScoreDoc[] { new ScoreDoc(1, 1.0f) }), - new TopDocs(1, new ScoreDoc[] { new ScoreDoc(1, 1.0f, -1) }) + new TopDocs(new TotalHits(1, TotalHits.Relation.EQUAL_TO), new ScoreDoc[] { new ScoreDoc(1, 1.0f) }), + new TopDocs(new TotalHits(1, TotalHits.Relation.EQUAL_TO), new ScoreDoc[] { new ScoreDoc(1, 1.0f, -1) }) }; if (random().nextBoolean()) { ArrayUtil.swap(topDocs, 0, 1); @@ -103,7 +103,7 @@ public class TestTopDocsMerge extends LuceneTestCase { // we set the shard index to index in the list here but shuffle the entire list below scoreDocs[j] = new ScoreDoc((100 * i) + j, score , i); } - topDocs.add(new TopDocs(numHits, scoreDocs)); + topDocs.add(new TopDocs(new TotalHits(numHits, TotalHits.Relation.EQUAL_TO), scoreDocs)); shardResultMapping.put(i, topDocs.get(i)); } // shuffle the entire thing such that we don't get 1 to 1 mapping of shard index to index in the array @@ -306,7 +306,7 @@ public class TestTopDocsMerge extends LuceneTestCase { if (useFrom) { System.out.println("from=" + from + " size=" + size); } - System.out.println(" top search: " + topHits.totalHits + " totalHits; hits=" + (topHits.scoreDocs == null ? "null" : topHits.scoreDocs.length)); + System.out.println(" top search: " + topHits.totalHits.value + " totalHits; hits=" + (topHits.scoreDocs == null ? "null" : topHits.scoreDocs.length)); if (topHits.scoreDocs != null) { for(int hitIDX=0;hitIDX hitsCollector; if (sort != null) { diff --git a/lucene/facet/src/test/org/apache/lucene/facet/TestDrillDownQuery.java b/lucene/facet/src/test/org/apache/lucene/facet/TestDrillDownQuery.java index 41d102f8c42..9eb325333e9 100644 --- a/lucene/facet/src/test/org/apache/lucene/facet/TestDrillDownQuery.java +++ b/lucene/facet/src/test/org/apache/lucene/facet/TestDrillDownQuery.java @@ -123,7 +123,7 @@ public class TestDrillDownQuery extends FacetTestCase { q.add("a", "2"); q.add("b", "1"); TopDocs docs = searcher.search(q, 100); - assertEquals(5, docs.totalHits); + assertEquals(5, docs.totalHits.value); } public void testQuery() throws IOException { @@ -134,14 +134,14 @@ public class TestDrillDownQuery extends FacetTestCase { q.add("a"); QueryUtils.check(q); TopDocs docs = searcher.search(q, 100); - assertEquals(25, docs.totalHits); + assertEquals(25, docs.totalHits.value); // Making sure the query yields 5 documents with the facet "b" and the // previous (facet "a") query as a base query DrillDownQuery q2 = new DrillDownQuery(config, q); q2.add("b"); docs = searcher.search(q2, 100); - assertEquals(5, docs.totalHits); + assertEquals(5, docs.totalHits.value); // Making sure that a query of both facet "a" and facet "b" yields 5 results DrillDownQuery q3 = new DrillDownQuery(config); @@ -149,14 +149,14 @@ public class TestDrillDownQuery extends FacetTestCase { q3.add("b"); docs = searcher.search(q3, 100); - assertEquals(5, docs.totalHits); + assertEquals(5, docs.totalHits.value); // Check that content:foo (which yields 50% results) and facet/b (which yields 20%) // would gather together 10 results (10%..) Query fooQuery = new TermQuery(new Term("content", "foo")); DrillDownQuery q4 = new DrillDownQuery(config, fooQuery); q4.add("b"); docs = searcher.search(q4, 100); - assertEquals(10, docs.totalHits); + assertEquals(10, docs.totalHits.value); } public void testQueryImplicitDefaultParams() throws IOException { @@ -171,7 +171,7 @@ public class TestDrillDownQuery extends FacetTestCase { DrillDownQuery q2 = new DrillDownQuery(config, q); q2.add("b"); TopDocs docs = searcher.search(q2, 100); - assertEquals(5, docs.totalHits); + assertEquals(5, docs.totalHits.value); // Check that content:foo (which yields 50% results) and facet/b (which yields 20%) // would gather together 10 results (10%..) @@ -179,7 +179,7 @@ public class TestDrillDownQuery extends FacetTestCase { DrillDownQuery q4 = new DrillDownQuery(config, fooQuery); q4.add("b"); docs = searcher.search(q4, 100); - assertEquals(10, docs.totalHits); + assertEquals(10, docs.totalHits.value); } public void testZeroLimit() throws IOException { diff --git a/lucene/facet/src/test/org/apache/lucene/facet/TestDrillSideways.java b/lucene/facet/src/test/org/apache/lucene/facet/TestDrillSideways.java index 45a0aa2ddc4..ad7754f71fe 100644 --- a/lucene/facet/src/test/org/apache/lucene/facet/TestDrillSideways.java +++ b/lucene/facet/src/test/org/apache/lucene/facet/TestDrillSideways.java @@ -168,7 +168,7 @@ public class TestDrillSideways extends FacetTestCase { DrillDownQuery ddq = new DrillDownQuery(config); ddq.add("Author", "Lisa"); DrillSidewaysResult r = ds.search(null, ddq, 10); - assertEquals(2, r.hits.totalHits); + assertEquals(2, r.hits.totalHits.value); // Publish Date is only drill-down, and Lisa published // one in 2012 and one in 2010: assertEquals("dim=Publish Date path=[] value=2 childCount=2\n 2010 (1)\n 2012 (1)\n", @@ -188,7 +188,7 @@ public class TestDrillSideways extends FacetTestCase { ddq.add("Author", "Lisa"); r = ds.search(null, ddq, 10); - assertEquals(2, r.hits.totalHits); + assertEquals(2, r.hits.totalHits.value); // Publish Date is only drill-down, and Lisa published // one in 2012 and one in 2010: assertEquals("dim=Publish Date path=[] value=2 childCount=2\n 2010 (1)\n 2012 (1)\n", @@ -206,7 +206,7 @@ public class TestDrillSideways extends FacetTestCase { ddq.add("Author", "Lisa"); ddq.add("Author", "Bob"); r = ds.search(null, ddq, 10); - assertEquals(3, r.hits.totalHits); + assertEquals(3, r.hits.totalHits.value); // Publish Date is only drill-down: Lisa and Bob // (drill-down) published twice in 2010 and once in 2012: assertEquals("dim=Publish Date path=[] value=3 childCount=2\n 2010 (2)\n 2012 (1)\n", @@ -230,7 +230,7 @@ public class TestDrillSideways extends FacetTestCase { ddq.add("Author", "Lisa"); ddq.add("Publish Date", "2010"); r = ds.search(null, ddq, 10); - assertEquals(1, r.hits.totalHits); + assertEquals(1, r.hits.totalHits.value); // Publish Date is drill-sideways + drill-down: Lisa // (drill-down) published once in 2010 and once in 2012: assertEquals("dim=Publish Date path=[] value=2 childCount=2\n 2010 (1)\n 2012 (1)\n", @@ -249,7 +249,7 @@ public class TestDrillSideways extends FacetTestCase { ddq.add("Publish Date", "2010"); ddq.add("Author", "Bob"); r = ds.search(null, ddq, 10); - assertEquals(2, r.hits.totalHits); + assertEquals(2, r.hits.totalHits.value); // Publish Date is both drill-sideways + drill-down: // Lisa or Bob published twice in 2010 and once in 2012: assertEquals("dim=Publish Date path=[] value=3 childCount=2\n 2010 (2)\n 2012 (1)\n", @@ -263,7 +263,7 @@ public class TestDrillSideways extends FacetTestCase { ddq = new DrillDownQuery(config); ddq.add("Foobar", "Baz"); r = ds.search(null, ddq, 10); - assertEquals(0, r.hits.totalHits); + assertEquals(0, r.hits.totalHits.value); assertNull(r.facets.getTopChildren(10, "Publish Date")); assertNull(r.facets.getTopChildren(10, "Foobar")); @@ -272,7 +272,7 @@ public class TestDrillSideways extends FacetTestCase { ddq.add("Author", "Lisa"); ddq.add("Author", "Tom"); r = ds.search(null, ddq, 10); - assertEquals(2, r.hits.totalHits); + assertEquals(2, r.hits.totalHits.value); // Publish Date is only drill-down, and Lisa published // one in 2012 and one in 2010: assertEquals("dim=Publish Date path=[] value=2 childCount=2\n 2010 (1)\n 2012 (1)\n", @@ -289,7 +289,7 @@ public class TestDrillSideways extends FacetTestCase { ddq.add("Author", "Lisa"); ddq.add("Author", "Tom"); r = ds.search(null, ddq, 10); - assertEquals(2, r.hits.totalHits); + assertEquals(2, r.hits.totalHits.value); // Publish Date is only drill-down, and Lisa published // one in 2012 and one in 2010: assertEquals("dim=Publish Date path=[] value=2 childCount=2\n 2010 (1)\n 2012 (1)\n", @@ -300,7 +300,7 @@ public class TestDrillSideways extends FacetTestCase { ddq.add("Author", "Lisa"); r = ds.search(null, ddq, 10); - assertEquals(0, r.hits.totalHits); + assertEquals(0, r.hits.totalHits.value); assertNull(r.facets.getTopChildren(10, "Publish Date")); assertNull(r.facets.getTopChildren(10, "Author")); writer.close(); @@ -349,7 +349,7 @@ public class TestDrillSideways extends FacetTestCase { ddq.add("Author", "Lisa"); DrillSidewaysResult r = getNewDrillSideways(searcher, config, taxoReader).search(null, ddq, 10); - assertEquals(1, r.hits.totalHits); + assertEquals(1, r.hits.totalHits.value); // Publish Date is only drill-down, and Lisa published // one in 2012 and one in 2010: assertEquals("dim=Publish Date path=[] value=1 childCount=1\n 2010 (1)\n", @@ -412,7 +412,7 @@ public class TestDrillSideways extends FacetTestCase { ddq.add("dim", "a"); DrillSidewaysResult r = getNewDrillSideways(searcher, config, taxoReader).search(null, ddq, 10); - assertEquals(3, r.hits.totalHits); + assertEquals(3, r.hits.totalHits.value); assertEquals("dim=dim path=[] value=6 childCount=4\n a (3)\n b (1)\n c (1)\n d (1)\n", r.facets.getTopChildren(10, "dim").toString()); assertEquals("dim=dim path=[a] value=3 childCount=3\n x (1)\n y (1)\n z (1)\n", @@ -831,7 +831,7 @@ public class TestDrillSideways extends FacetTestCase { q = new BooleanQuery.Builder().add(q, Occur.MUST).add(filter, Occur.FILTER).build(); } TopDocs ddqHits = s.search(q, numDocs); - assertEquals(expected.hits.size(), ddqHits.totalHits); + assertEquals(expected.hits.size(), ddqHits.totalHits.value); for (int i = 0; i < expected.hits.size(); i++) { // Score should be IDENTICAL: assertEquals(scores.get(expected.hits.get(i).id), ddqHits.scoreDocs[i].score, 0.0f); @@ -1033,7 +1033,7 @@ public class TestDrillSideways extends FacetTestCase { if (VERBOSE) { System.out.println(" verify totHits=" + expected.hits.size()); } - assertEquals(expected.hits.size(), actual.hits.totalHits); + assertEquals(expected.hits.size(), actual.hits.totalHits.value); assertEquals(expected.hits.size(), actual.hits.scoreDocs.length); for (int i = 0; i < expected.hits.size(); i++) { if (VERBOSE) { @@ -1143,10 +1143,10 @@ public class TestDrillSideways extends FacetTestCase { ddq.add("Author", "Lisa"); DrillSidewaysResult r = ds.search(ddq, 10); // this used to fail on IllegalArgEx - assertEquals(0, r.hits.totalHits); + assertEquals(0, r.hits.totalHits.value); r = ds.search(ddq, null, null, 10, new Sort(new SortField("foo", SortField.Type.INT)), false); // this used to fail on IllegalArgEx - assertEquals(0, r.hits.totalHits); + assertEquals(0, r.hits.totalHits.value); writer.close(); IOUtils.close(taxoWriter, searcher.getIndexReader(), taxoReader, dir, taxoDir); @@ -1187,7 +1187,7 @@ public class TestDrillSideways extends FacetTestCase { ddq.add("author", bq.build()); ddq.add("dim", bq.build()); DrillSidewaysResult r = ds.search(null, ddq, 10); - assertEquals(0, r.hits.totalHits); + assertEquals(0, r.hits.totalHits.value); writer.close(); IOUtils.close(searcher.getIndexReader(), taxoReader, taxoWriter, dir, taxoDir); diff --git a/lucene/facet/src/test/org/apache/lucene/facet/TestFacetQuery.java b/lucene/facet/src/test/org/apache/lucene/facet/TestFacetQuery.java index 07edd6ebf7f..da75f741ef2 100644 --- a/lucene/facet/src/test/org/apache/lucene/facet/TestFacetQuery.java +++ b/lucene/facet/src/test/org/apache/lucene/facet/TestFacetQuery.java @@ -91,13 +91,13 @@ public class TestFacetQuery extends FacetTestCase { @Test public void testSingleValued() throws Exception { TopDocs topDocs = searcher.search(new FacetQuery("Author", "Mark Twain"), 10); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); } @Test public void testMultiValued() throws Exception { TopDocs topDocs = searcher.search( new MultiFacetQuery("Author", new String[] { "Mark Twain" }, new String[] { "Kurt Vonnegut" }), 10); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); } } diff --git a/lucene/facet/src/test/org/apache/lucene/facet/range/TestRangeFacetCounts.java b/lucene/facet/src/test/org/apache/lucene/facet/range/TestRangeFacetCounts.java index f7f4b028fc0..24082867824 100644 --- a/lucene/facet/src/test/org/apache/lucene/facet/range/TestRangeFacetCounts.java +++ b/lucene/facet/src/test/org/apache/lucene/facet/range/TestRangeFacetCounts.java @@ -298,7 +298,7 @@ public class TestRangeFacetCounts extends FacetTestCase { DrillDownQuery ddq = new DrillDownQuery(config); DrillSidewaysResult dsr = ds.search(null, ddq, 10); - assertEquals(100, dsr.hits.totalHits); + assertEquals(100, dsr.hits.totalHits.value); assertEquals("dim=dim path=[] value=100 childCount=2\n b (75)\n a (25)\n", dsr.facets.getTopChildren(10, "dim").toString()); assertEquals("dim=field path=[] value=21 childCount=5\n less than 10 (10)\n less than or equal to 10 (11)\n over 90 (9)\n 90 or above (10)\n over 1000 (0)\n", dsr.facets.getTopChildren(10, "field").toString()); @@ -308,7 +308,7 @@ public class TestRangeFacetCounts extends FacetTestCase { ddq.add("dim", "b"); dsr = ds.search(null, ddq, 10); - assertEquals(75, dsr.hits.totalHits); + assertEquals(75, dsr.hits.totalHits.value); assertEquals("dim=dim path=[] value=100 childCount=2\n b (75)\n a (25)\n", dsr.facets.getTopChildren(10, "dim").toString()); assertEquals("dim=field path=[] value=16 childCount=5\n less than 10 (7)\n less than or equal to 10 (8)\n over 90 (7)\n 90 or above (8)\n over 1000 (0)\n", dsr.facets.getTopChildren(10, "field").toString()); @@ -318,7 +318,7 @@ public class TestRangeFacetCounts extends FacetTestCase { ddq.add("field", LongPoint.newRangeQuery("field", 0L, 10L)); dsr = ds.search(null, ddq, 10); - assertEquals(11, dsr.hits.totalHits); + assertEquals(11, dsr.hits.totalHits.value); assertEquals("dim=dim path=[] value=11 childCount=2\n b (8)\n a (3)\n", dsr.facets.getTopChildren(10, "dim").toString()); assertEquals("dim=field path=[] value=21 childCount=5\n less than 10 (10)\n less than or equal to 10 (11)\n over 90 (9)\n 90 or above (10)\n over 1000 (0)\n", dsr.facets.getTopChildren(10, "field").toString()); @@ -495,7 +495,7 @@ public class TestRangeFacetCounts extends FacetTestCase { } else { ddq.add("field", range.getQuery(fastMatchQuery, vs)); } - assertEquals(expectedCounts[rangeID], s.search(ddq, 10).totalHits); + assertEquals(expectedCounts[rangeID], s.search(ddq, 10).totalHits.value); } } @@ -639,7 +639,7 @@ public class TestRangeFacetCounts extends FacetTestCase { ddq.add("field", range.getQuery(fastMatchFilter, vs)); } - assertEquals(expectedCounts[rangeID], s.search(ddq, 10).totalHits); + assertEquals(expectedCounts[rangeID], s.search(ddq, 10).totalHits.value); } } @@ -841,7 +841,7 @@ public class TestRangeFacetCounts extends FacetTestCase { ddq.add("field", ranges[1].getQuery(fastMatchFilter, vs)); // Test simple drill-down: - assertEquals(1, s.search(ddq, 10).totalHits); + assertEquals(1, s.search(ddq, 10).totalHits.value); // Test drill-sideways after drill-down DrillSideways ds = new DrillSideways(s, config, (TaxonomyReader) null) { @@ -860,7 +860,7 @@ public class TestRangeFacetCounts extends FacetTestCase { DrillSidewaysResult dsr = ds.search(ddq, 10); - assertEquals(1, dsr.hits.totalHits); + assertEquals(1, dsr.hits.totalHits.value); assertEquals("dim=field path=[] value=3 childCount=6\n < 1 (0)\n < 2 (1)\n < 5 (3)\n < 10 (3)\n < 20 (3)\n < 50 (3)\n", dsr.facets.getTopChildren(10, "field").toString()); diff --git a/lucene/facet/src/test/org/apache/lucene/facet/sortedset/TestSortedSetDocValuesFacets.java b/lucene/facet/src/test/org/apache/lucene/facet/sortedset/TestSortedSetDocValuesFacets.java index 805eae8b505..8aae80354d1 100644 --- a/lucene/facet/src/test/org/apache/lucene/facet/sortedset/TestSortedSetDocValuesFacets.java +++ b/lucene/facet/src/test/org/apache/lucene/facet/sortedset/TestSortedSetDocValuesFacets.java @@ -92,7 +92,7 @@ public class TestSortedSetDocValuesFacets extends FacetTestCase { q.add("a", "foo"); q.add("b", "baz"); TopDocs hits = searcher.search(q, 1); - assertEquals(1, hits.totalHits); + assertEquals(1, hits.totalHits.value); if (exec != null) { exec.shutdownNow(); diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetSumValueSource.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetSumValueSource.java index 5bc847287fb..76493ed1b61 100644 --- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetSumValueSource.java +++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetSumValueSource.java @@ -261,7 +261,7 @@ public class TestTaxonomyFacetSumValueSource extends FacetTestCase { Facets facets = new TaxonomyFacetSumValueSource(taxoReader, config, fc, DoubleValuesSource.SCORES); - int expected = (int) (csq.getBoost() * td.totalHits); + int expected = (int) (csq.getBoost() * td.totalHits.value); assertEquals(expected, facets.getSpecificValue("dim", "a").intValue()); iw.close(); diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java index 202bd2c00a6..28534619848 100644 --- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java +++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java @@ -481,7 +481,7 @@ public class TestDirectoryTaxonomyWriter extends FacetTestCase { IndexSearcher searcher = new IndexSearcher(indexReader); DrillDownQuery ddq = new DrillDownQuery(new FacetsConfig()); ddq.add("dim", bigs); - assertEquals(1, searcher.search(ddq, 10).totalHits); + assertEquals(1, searcher.search(ddq, 10).totalHits.value); IOUtils.close(indexReader, taxoReader, indexDir, taxoDir); } diff --git a/lucene/grouping/src/java/org/apache/lucene/search/grouping/BlockGroupingCollector.java b/lucene/grouping/src/java/org/apache/lucene/search/grouping/BlockGroupingCollector.java index 200d5e7b28a..58f2232c192 100644 --- a/lucene/grouping/src/java/org/apache/lucene/search/grouping/BlockGroupingCollector.java +++ b/lucene/grouping/src/java/org/apache/lucene/search/grouping/BlockGroupingCollector.java @@ -33,6 +33,7 @@ import org.apache.lucene.search.TopDocs; import org.apache.lucene.search.TopDocsCollector; import org.apache.lucene.search.TopFieldCollector; import org.apache.lucene.search.TopScoreDocCollector; +import org.apache.lucene.search.TotalHits; import org.apache.lucene.search.Weight; import org.apache.lucene.util.ArrayUtil; import org.apache.lucene.util.PriorityQueue; @@ -334,7 +335,7 @@ public class BlockGroupingCollector extends SimpleCollector { // by Sum/Avg instead of passing NaN: groups[downTo] = new GroupDocs<>(Float.NaN, groupMaxScore, - og.count, + new TotalHits(og.count, TotalHits.Relation.EQUAL_TO), topDocs.scoreDocs, null, groupSortValues); 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.java index a2213d9a526..78861d05141 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 @@ -17,6 +17,7 @@ package org.apache.lucene.search.grouping; import org.apache.lucene.search.ScoreDoc; +import org.apache.lucene.search.TotalHits; /** Represents one group in the results. * @@ -39,7 +40,7 @@ public class GroupDocs { public final ScoreDoc[] scoreDocs; /** Total hits within this group */ - public final long totalHits; + public final TotalHits totalHits; /** Matches the groupSort passed to {@link * FirstPassGroupingCollector}. */ @@ -47,7 +48,7 @@ public class GroupDocs { public GroupDocs(float score, float maxScore, - long totalHits, + TotalHits totalHits, ScoreDoc[] scoreDocs, T groupValue, Object[] groupSortValues) { diff --git a/lucene/grouping/src/java/org/apache/lucene/search/grouping/TopGroups.java b/lucene/grouping/src/java/org/apache/lucene/search/grouping/TopGroups.java index c87dd0d2a76..71338f96358 100644 --- a/lucene/grouping/src/java/org/apache/lucene/search/grouping/TopGroups.java +++ b/lucene/grouping/src/java/org/apache/lucene/search/grouping/TopGroups.java @@ -21,6 +21,8 @@ import org.apache.lucene.search.Sort; import org.apache.lucene.search.SortField; import org.apache.lucene.search.TopDocs; import org.apache.lucene.search.TopFieldDocs; +import org.apache.lucene.search.TotalHits; +import org.apache.lucene.search.TotalHits.Relation; /** Represents result returned by a grouping search. * @@ -168,7 +170,8 @@ public class TopGroups { docSort.getSort()); } maxScore = Math.max(maxScore, shardGroupDocs.maxScore); - totalHits += shardGroupDocs.totalHits; + assert shardGroupDocs.totalHits.relation == Relation.EQUAL_TO; + totalHits += shardGroupDocs.totalHits.value; scoreSum += shardGroupDocs.score; } @@ -216,7 +219,7 @@ public class TopGroups { //System.out.println("SHARDS=" + Arrays.toString(mergedTopDocs.shardIndex)); mergedGroupDocs[groupIDX] = new GroupDocs<>(groupScore, maxScore, - totalHits, + new TotalHits(totalHits, TotalHits.Relation.EQUAL_TO), mergedScoreDocs, groupValue, shardGroups[0].groups[groupIDX].groupSortValues); diff --git a/lucene/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java b/lucene/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java index 8415f6a07de..87a1d97efe7 100644 --- a/lucene/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java +++ b/lucene/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java @@ -58,6 +58,7 @@ import org.apache.lucene.search.ScoreMode; import org.apache.lucene.search.Sort; import org.apache.lucene.search.SortField; import org.apache.lucene.search.TermQuery; +import org.apache.lucene.search.TotalHits; import org.apache.lucene.search.Weight; import org.apache.lucene.search.similarities.BM25Similarity; import org.apache.lucene.store.Directory; @@ -513,7 +514,7 @@ public class TestGrouping extends LuceneTestCase { result[idx-groupOffset] = new GroupDocs<>(Float.NaN, 0.0f, - docs.size(), + new TotalHits(docs.size(), TotalHits.Relation.EQUAL_TO), hits, group, sortedGroupFields.get(idx)); @@ -979,7 +980,7 @@ public class TestGrouping extends LuceneTestCase { } else { System.out.println("TEST: expected groups totalGroupedHitCount=" + expectedGroups.totalGroupedHitCount); for(GroupDocs gd : expectedGroups.groups) { - System.out.println(" group=" + (gd.groupValue == null ? "null" : gd.groupValue) + " totalHits=" + gd.totalHits + " scoreDocs.len=" + gd.scoreDocs.length); + System.out.println(" group=" + (gd.groupValue == null ? "null" : gd.groupValue) + " totalHits=" + gd.totalHits.value + " scoreDocs.len=" + gd.scoreDocs.length); for(ScoreDoc sd : gd.scoreDocs) { System.out.println(" id=" + sd.doc + " score=" + sd.score); } @@ -991,7 +992,7 @@ public class TestGrouping extends LuceneTestCase { } else { System.out.println("TEST: matched groups totalGroupedHitCount=" + groupsResult.totalGroupedHitCount); for(GroupDocs gd : groupsResult.groups) { - System.out.println(" group=" + (gd.groupValue == null ? "null" : gd.groupValue) + " totalHits=" + gd.totalHits); + System.out.println(" group=" + (gd.groupValue == null ? "null" : gd.groupValue) + " totalHits=" + gd.totalHits.value); for(ScoreDoc sd : gd.scoreDocs) { System.out.println(" id=" + docIDToID[sd.doc] + " score=" + sd.score); } @@ -1009,7 +1010,7 @@ public class TestGrouping extends LuceneTestCase { } else { System.out.println("TEST: matched-merged groups totalGroupedHitCount=" + topGroupsShards.totalGroupedHitCount); for(GroupDocs gd : topGroupsShards.groups) { - System.out.println(" group=" + (gd.groupValue == null ? "null" : gd.groupValue) + " totalHits=" + gd.totalHits); + System.out.println(" group=" + (gd.groupValue == null ? "null" : gd.groupValue) + " totalHits=" + gd.totalHits.value); for(ScoreDoc sd : gd.scoreDocs) { System.out.println(" id=" + docIDToID[sd.doc] + " score=" + sd.score); } @@ -1058,7 +1059,7 @@ public class TestGrouping extends LuceneTestCase { System.out.println("TEST: block groups totalGroupedHitCount=" + groupsResultBlocks.totalGroupedHitCount); boolean first = true; for(GroupDocs gd : groupsResultBlocks.groups) { - System.out.println(" group=" + (gd.groupValue == null ? "null" : gd.groupValue.utf8ToString()) + " totalHits=" + gd.totalHits); + System.out.println(" group=" + (gd.groupValue == null ? "null" : gd.groupValue.utf8ToString()) + " totalHits=" + gd.totalHits.value); for(ScoreDoc sd : gd.scoreDocs) { System.out.println(" id=" + docIDToIDBlocks[sd.doc] + " score=" + sd.score); if (first) { @@ -1261,7 +1262,7 @@ public class TestGrouping extends LuceneTestCase { // TODO // assertEquals(expectedGroup.maxScore, actualGroup.maxScore); - assertEquals(expectedGroup.totalHits, actualGroup.totalHits); + assertEquals(expectedGroup.totalHits.value, actualGroup.totalHits.value); final ScoreDoc[] expectedFDs = expectedGroup.scoreDocs; final ScoreDoc[] actualFDs = actualGroup.scoreDocs; diff --git a/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterPhraseTest.java b/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterPhraseTest.java index 29c9ca6c543..cd4dcc6ad8c 100644 --- a/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterPhraseTest.java +++ b/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterPhraseTest.java @@ -74,7 +74,7 @@ public class HighlighterPhraseTest extends LuceneTestCase { final IndexSearcher indexSearcher = newSearcher(indexReader); final PhraseQuery phraseQuery = new PhraseQuery(FIELD, "fox", "jumped"); TopDocs hits = indexSearcher.search(phraseQuery, 1); - assertEquals(1, hits.totalHits); + assertEquals(1, hits.totalHits.value); final Highlighter highlighter = new Highlighter( new SimpleHTMLFormatter(), new SimpleHTMLEncoder(), new QueryScorer(phraseQuery)); @@ -179,7 +179,7 @@ public class HighlighterPhraseTest extends LuceneTestCase { final IndexSearcher indexSearcher = newSearcher(indexReader); final PhraseQuery phraseQuery = new PhraseQuery(FIELD, "did", "jump"); TopDocs hits = indexSearcher.search(phraseQuery, 1); - assertEquals(0, hits.totalHits); + assertEquals(0, hits.totalHits.value); final Highlighter highlighter = new Highlighter( new SimpleHTMLFormatter(), new SimpleHTMLEncoder(), new QueryScorer(phraseQuery)); @@ -216,7 +216,7 @@ public class HighlighterPhraseTest extends LuceneTestCase { final IndexSearcher indexSearcher = newSearcher(indexReader); final PhraseQuery phraseQuery = new PhraseQuery(1, FIELD, "did", "jump"); TopDocs hits = indexSearcher.search(phraseQuery, 1); - assertEquals(1, hits.totalHits); + assertEquals(1, hits.totalHits.value); final Highlighter highlighter = new Highlighter( new SimpleHTMLFormatter(), new SimpleHTMLEncoder(), new QueryScorer(phraseQuery)); @@ -255,7 +255,7 @@ public class HighlighterPhraseTest extends LuceneTestCase { new SpanTermQuery(new Term(FIELD, "jump")) }, 0, true); TopDocs hits = indexSearcher.search(phraseQuery, 1); - assertEquals(0, hits.totalHits); + assertEquals(0, hits.totalHits.value); final Highlighter highlighter = new Highlighter( new SimpleHTMLFormatter(), new SimpleHTMLEncoder(), new QueryScorer(phraseQuery)); @@ -292,7 +292,7 @@ public class HighlighterPhraseTest extends LuceneTestCase { .add(new Term(FIELD, "ef"), 7).build(); TopDocs hits = indexSearcher.search(phraseQuery, 100); - assertEquals(1, hits.totalHits); + assertEquals(1, hits.totalHits.value); final Highlighter highlighter = new Highlighter( new SimpleHTMLFormatter(), new SimpleHTMLEncoder(), new QueryScorer(phraseQuery)); @@ -324,7 +324,7 @@ public class HighlighterPhraseTest extends LuceneTestCase { .add(new Term(FIELD, "cd"), 2).build(); TopDocs hits = indexSearcher.search(phraseQuery, 100); - assertEquals(1, hits.totalHits); + assertEquals(1, hits.totalHits.value); final Highlighter highlighter = new Highlighter( new SimpleHTMLFormatter(), new SimpleHTMLEncoder(), diff --git a/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java b/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java index 5c2fe356bb8..89c81db01dc 100644 --- a/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java +++ b/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java @@ -151,7 +151,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte searcher = newSearcher(reader); TopDocs hits = searcher.search(query, 10, new Sort(SortField.FIELD_DOC, SortField.FIELD_SCORE)); - assertEquals(2, hits.totalHits); + assertEquals(2, hits.totalHits.value); QueryScorer scorer = new QueryScorer(query, FIELD_NAME); Highlighter highlighter = new Highlighter(scorer); @@ -203,7 +203,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte searcher = newSearcher(reader); TopDocs hits = searcher.search(query, 10, new Sort(SortField.FIELD_DOC, SortField.FIELD_SCORE)); - assertEquals(2, hits.totalHits); + assertEquals(2, hits.totalHits.value); QueryScorer scorer = new QueryScorer(query, FIELD_NAME); Highlighter highlighter = new Highlighter(scorer); @@ -275,7 +275,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte searcher = newSearcher(reader); TopDocs hits = searcher.search(query, 10, new Sort(SortField.FIELD_DOC, SortField.FIELD_SCORE)); - assertEquals(2, hits.totalHits); + assertEquals(2, hits.totalHits.value); QueryScorer scorer = new QueryScorer(query, FIELD_NAME); Highlighter highlighter = new Highlighter(scorer); @@ -355,7 +355,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte QueryScorer scorer = new QueryScorer(query, FIELD_NAME); Highlighter highlighter = new Highlighter(scorer); - for (int i = 0; i < hits.totalHits; i++) { + for (int i = 0; i < hits.totalHits.value; i++) { String text = searcher.doc(hits.scoreDocs[i].doc).get(FIELD_NAME); TokenStream tokenStream = analyzer.tokenStream(FIELD_NAME, text); highlighter.setTextFragmenter(new SimpleFragmenter(40)); @@ -378,8 +378,8 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte QueryScorer scorer = new QueryScorer(query, FIELD_NAME); Highlighter highlighter = new Highlighter(scorer); - assertEquals("Must have one hit", 1, hits.totalHits); - for (int i = 0; i < hits.totalHits; i++) { + assertEquals("Must have one hit", 1, hits.totalHits.value); + for (int i = 0; i < hits.totalHits.value; i++) { String text = searcher.doc(hits.scoreDocs[i].doc).get(FIELD_NAME); TokenStream tokenStream = analyzer.tokenStream(FIELD_NAME, text); @@ -443,7 +443,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte QueryScorer scorer = new QueryScorer(query, FIELD_NAME); Highlighter highlighter = new Highlighter(this, scorer); - for (int i = 0; i < hits.totalHits; i++) { + for (int i = 0; i < hits.totalHits.value; i++) { final int docId = hits.scoreDocs[i].doc; final Document doc = searcher.doc(docId); String text = doc.get(FIELD_NAME); @@ -475,7 +475,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte scorer = new QueryScorer(query, FIELD_NAME); highlighter = new Highlighter(this, scorer); - for (int i = 0; i < hits.totalHits; i++) { + for (int i = 0; i < hits.totalHits.value; i++) { final int docId = hits.scoreDocs[i].doc; final Document doc = searcher.doc(docId); String text = doc.get(FIELD_NAME); @@ -507,7 +507,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte scorer = new QueryScorer(query, FIELD_NAME); highlighter = new Highlighter(this, scorer); - for (int i = 0; i < hits.totalHits; i++) { + for (int i = 0; i < hits.totalHits.value; i++) { final int docId = hits.scoreDocs[i].doc; final Document doc = searcher.doc(docId); String text = doc.get(FIELD_NAME); @@ -534,7 +534,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte QueryScorer scorer = new QueryScorer(query, FIELD_NAME); Highlighter highlighter = new Highlighter(this, scorer); - for (int i = 0; i < hits.totalHits; i++) { + for (int i = 0; i < hits.totalHits.value; i++) { final int docId = hits.scoreDocs[i].doc; final Document doc = searcher.doc(docId); String text = doc.get(FIELD_NAME); @@ -560,7 +560,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte QueryScorer scorer = new QueryScorer(query, FIELD_NAME); Highlighter highlighter = new Highlighter(this, scorer); - for (int i = 0; i < hits.totalHits; i++) { + for (int i = 0; i < hits.totalHits.value; i++) { final int docId = hits.scoreDocs[i].doc; final Document doc = searcher.doc(docId); String text = doc.get(FIELD_NAME); @@ -586,7 +586,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte QueryScorer scorer = new QueryScorer(query, reader, FIELD_NAME); Highlighter highlighter = new Highlighter(this, scorer); - for (int i = 0; i < hits.totalHits; i++) { + for (int i = 0; i < hits.totalHits.value; i++) { final int docId = hits.scoreDocs[i].doc; final Document doc = searcher.doc(docId); String text = doc.get(FIELD_NAME); @@ -614,7 +614,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte QueryScorer scorer = new QueryScorer(query, FIELD_NAME); Highlighter highlighter = new Highlighter(this, scorer); - for (int i = 0; i < hits.totalHits; i++) { + for (int i = 0; i < hits.totalHits.value; i++) { String text = searcher.doc(hits.scoreDocs[i].doc).getField(NUMERIC_FIELD_NAME).numericValue().toString(); TokenStream tokenStream = analyzer.tokenStream(FIELD_NAME, text); @@ -641,7 +641,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte QueryScorer scorer = new QueryScorer(query, FIELD_NAME); Highlighter highlighter = new Highlighter(this, scorer); - for (int i = 0; i < hits.totalHits; i++) { + for (int i = 0; i < hits.totalHits.value; i++) { String text = "child document"; TokenStream tokenStream = analyzer.tokenStream(FIELD_NAME, text); @@ -670,7 +670,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte QueryScorer scorer = new QueryScorer(query, FIELD_NAME); Highlighter highlighter = new Highlighter(this, scorer); - for (int i = 0; i < hits.totalHits; i++) { + for (int i = 0; i < hits.totalHits.value; i++) { String text = "parent document"; final int docId = hits.scoreDocs[i].doc; TokenStream tokenStream = getAnyTokenStream(FIELD_NAME, docId); @@ -693,7 +693,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte Highlighter highlighter = new Highlighter(this,scorer); highlighter.setTextFragmenter(new SimpleFragmenter(40)); - for (int i = 0; i < hits.totalHits; i++) { + for (int i = 0; i < hits.totalHits.value; i++) { final int docId = hits.scoreDocs[i].doc; final Document doc = searcher.doc(docId); String text = doc.get(FIELD_NAME); @@ -714,7 +714,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte int maxNumFragmentsRequired = 2; - for (int i = 0; i < hits.totalHits; i++) { + for (int i = 0; i < hits.totalHits.value; i++) { final int docId = hits.scoreDocs[i].doc; final Document doc = searcher.doc(docId); String text = doc.get(FIELD_NAME); @@ -747,7 +747,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte QueryScorer scorer = new QueryScorer(query, FIELD_NAME); Highlighter highlighter = new Highlighter(this, scorer); - for (int i = 0; i < hits.totalHits; i++) { + for (int i = 0; i < hits.totalHits.value; i++) { final int docId = hits.scoreDocs[i].doc; final Document doc = searcher.doc(docId); String text = doc.get(FIELD_NAME); @@ -770,7 +770,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte scorer = new QueryScorer(query, FIELD_NAME); highlighter = new Highlighter(this, scorer); - for (int i = 0; i < hits.totalHits; i++) { + for (int i = 0; i < hits.totalHits.value; i++) { String text = searcher.doc(hits.scoreDocs[i].doc).get(FIELD_NAME); TokenStream tokenStream = analyzer.tokenStream(FIELD_NAME, text); @@ -798,7 +798,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte QueryScorer scorer = new QueryScorer(query, FIELD_NAME); Highlighter highlighter = new Highlighter(this,scorer); - for (int i = 0; i < hits.totalHits; i++) { + for (int i = 0; i < hits.totalHits.value; i++) { final int docId = hits.scoreDocs[i].doc; final Document doc = searcher.doc(docId); String text = doc.get(FIELD_NAME); @@ -871,7 +871,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte Highlighter highlighter = new Highlighter(new QueryTermScorer(query)); highlighter.setTextFragmenter(new SimpleFragmenter(40)); int maxNumFragmentsRequired = 2; - for (int i = 0; i < hits.totalHits; i++) { + for (int i = 0; i < hits.totalHits.value; i++) { final int docId = hits.scoreDocs[i].doc; final Document doc = searcher.doc(docId); String text = doc.get(FIELD_NAME); @@ -1067,7 +1067,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte if (VERBOSE) System.out.println("Searching for: " + query.toString(FIELD_NAME)); hits = searcher.search(query, 1000); - for (int i = 0; i < hits.totalHits; i++) { + for (int i = 0; i < hits.totalHits.value; i++) { final int docId = hits.scoreDocs[i].doc; final Document doc = searcher.doc(docId); String text = doc.get(FIELD_NAME); @@ -1093,7 +1093,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte numHighlights = 0; - for (int i = 0; i < hits.totalHits; i++) { + for (int i = 0; i < hits.totalHits.value; i++) { final int docId = hits.scoreDocs[i].doc; final Document doc = searcher.doc(docId); String text = doc.get(FIELD_NAME); @@ -1119,7 +1119,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte numHighlights = 0; - for (int i = 0; i < hits.totalHits; i++) { + for (int i = 0; i < hits.totalHits.value; i++) { final int docId = hits.scoreDocs[i].doc; final Document doc = searcher.doc(docId); String text = doc.get(FIELD_NAME); @@ -1293,7 +1293,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte public void run() throws Exception { doSearching(new TermQuery(new Term(FIELD_NAME, "kennedy"))); numHighlights = 0; - for (int i = 0; i < hits.totalHits; i++) { + for (int i = 0; i < hits.totalHits.value; i++) { final int docId = hits.scoreDocs[i].doc; final Document doc = searcher.doc(docId); String text = doc.get(FIELD_NAME); @@ -1309,7 +1309,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte numHighlights == 4); numHighlights = 0; - for (int i = 0; i < hits.totalHits; i++) { + for (int i = 0; i < hits.totalHits.value; i++) { final int docId = hits.scoreDocs[i].doc; final Document doc = searcher.doc(docId); String text = doc.get(FIELD_NAME); @@ -1322,7 +1322,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte numHighlights == 4); numHighlights = 0; - for (int i = 0; i < hits.totalHits; i++) { + for (int i = 0; i < hits.totalHits.value; i++) { final int docId = hits.scoreDocs[i].doc; final Document doc = searcher.doc(docId); String text = doc.get(FIELD_NAME); @@ -1448,7 +1448,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte doSearching(new TermQuery(new Term(FIELD_NAME, "kennedy"))); // new Highlighter(HighlighterTest.this, new QueryTermScorer(query)); - for (int i = 0; i < hits.totalHits; i++) { + for (int i = 0; i < hits.totalHits.value; i++) { String text = searcher.doc(hits.scoreDocs[i].doc).get(FIELD_NAME); TokenStream tokenStream = analyzer.tokenStream(FIELD_NAME, text); Highlighter highlighter = getHighlighter(query, FIELD_NAME, @@ -1471,7 +1471,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte doSearching(new TermQuery(new Term(FIELD_NAME, "kennedy"))); - for (int i = 0; i < hits.totalHits; i++) { + for (int i = 0; i < hits.totalHits.value; i++) { final int docId = hits.scoreDocs[i].doc; final Document doc = searcher.doc(docId); String text = doc.get(FIELD_NAME); @@ -1660,7 +1660,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte int maxNumFragmentsRequired = 3; - for (int i = 0; i < hits.totalHits; i++) { + for (int i = 0; i < hits.totalHits.value; i++) { final int docId = hits.scoreDocs[i].doc; final Document doc = searcher.doc(docId); String text = doc.get(FIELD_NAME); @@ -2024,7 +2024,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte Highlighter h = new Highlighter( scorer ); TopDocs hits = searcher.search(query, 10); - for( int i = 0; i < hits.totalHits; i++ ){ + for( int i = 0; i < hits.totalHits.value; i++ ){ Document doc = searcher.doc( hits.scoreDocs[i].doc ); String result = h.getBestFragment( a, "t_text1", doc.get( "t_text1" )); if (VERBOSE) System.out.println("result:" + result); @@ -2084,7 +2084,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte * Highlighter highlighter = new Highlighter(this,new * QueryFragmentScorer(query)); * - * for (int i = 0; i < hits.totalHits; i++) { String text = + * for (int i = 0; i < hits.totalHits.value; i++) { String text = * searcher.doc2(hits.scoreDocs[i].doc).get(FIELD_NAME); TokenStream * tokenStream=bigramAnalyzer.tokenStream(FIELD_NAME,text); * String highlightedText = highlighter.getBestFragment(tokenStream,text); @@ -2111,7 +2111,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte public void assertExpectedHighlightCount(final int maxNumFragmentsRequired, final int expectedHighlights) throws Exception { - for (int i = 0; i < hits.totalHits; i++) { + for (int i = 0; i < hits.totalHits.value; i++) { String text = searcher.doc(hits.scoreDocs[i].doc).get(FIELD_NAME); TokenStream tokenStream = analyzer.tokenStream(FIELD_NAME, text); QueryScorer scorer = new QueryScorer(query, FIELD_NAME); @@ -2368,7 +2368,7 @@ final class SynonymTokenizer extends TokenStream { void doStandardHighlights(Analyzer analyzer, IndexSearcher searcher, TopDocs hits, Query query, Formatter formatter, boolean expandMT) throws Exception { - for (int i = 0; i < hits.totalHits; i++) { + for (int i = 0; i < hits.totalHits.value; i++) { final int docId = hits.scoreDocs[i].doc; final Document doc = searcher.doc(docId); String text = doc.get(HighlighterTest.FIELD_NAME); diff --git a/lucene/highlighter/src/test/org/apache/lucene/search/highlight/TokenSourcesTest.java b/lucene/highlighter/src/test/org/apache/lucene/search/highlight/TokenSourcesTest.java index d49434a248e..df139f7c11c 100644 --- a/lucene/highlighter/src/test/org/apache/lucene/search/highlight/TokenSourcesTest.java +++ b/lucene/highlighter/src/test/org/apache/lucene/search/highlight/TokenSourcesTest.java @@ -129,7 +129,7 @@ public class TokenSourcesTest extends BaseTokenStreamTestCase { // new SpanTermQuery(new Term(FIELD, "fox")) }, 0, true); TopDocs hits = indexSearcher.search(query, 1); - assertEquals(1, hits.totalHits); + assertEquals(1, hits.totalHits.value); final Highlighter highlighter = new Highlighter( new SimpleHTMLFormatter(), new SimpleHTMLEncoder(), new QueryScorer(query)); @@ -174,7 +174,7 @@ public class TokenSourcesTest extends BaseTokenStreamTestCase { // new SpanTermQuery(new Term(FIELD, "fox")) }, 0, true); TopDocs hits = indexSearcher.search(query, 1); - assertEquals(1, hits.totalHits); + assertEquals(1, hits.totalHits.value); final Highlighter highlighter = new Highlighter( new SimpleHTMLFormatter(), new SimpleHTMLEncoder(), new QueryScorer(query)); @@ -217,7 +217,7 @@ public class TokenSourcesTest extends BaseTokenStreamTestCase { new SpanTermQuery(new Term(FIELD, "fox"))}, 0, true); TopDocs hits = indexSearcher.search(phraseQuery, 1); - assertEquals(1, hits.totalHits); + assertEquals(1, hits.totalHits.value); final Highlighter highlighter = new Highlighter( new SimpleHTMLFormatter(), new SimpleHTMLEncoder(), new QueryScorer(phraseQuery)); @@ -260,7 +260,7 @@ public class TokenSourcesTest extends BaseTokenStreamTestCase { new SpanTermQuery(new Term(FIELD, "fox"))}, 0, true); TopDocs hits = indexSearcher.search(phraseQuery, 1); - assertEquals(1, hits.totalHits); + assertEquals(1, hits.totalHits.value); final Highlighter highlighter = new Highlighter( new SimpleHTMLFormatter(), new SimpleHTMLEncoder(), new QueryScorer(phraseQuery)); diff --git a/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighter.java b/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighter.java index 086d7a03cfb..fa6f2867dbc 100644 --- a/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighter.java +++ b/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighter.java @@ -138,7 +138,7 @@ public class TestUnifiedHighlighter extends LuceneTestCase { UnifiedHighlighter highlighter = randomUnifiedHighlighter(searcher, indexAnalyzer); Query query = new TermQuery(new Term("body", "highlighting")); TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); String snippets[] = highlighter.highlight("body", query, topDocs); assertEquals(2, snippets.length); assertEquals("Just a test highlighting from postings. ", snippets[0]); @@ -199,7 +199,7 @@ public class TestUnifiedHighlighter extends LuceneTestCase { Query query = new TermQuery(new Term("body", "test")); TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); UnifiedHighlighter highlighter = randomUnifiedHighlighter(searcher, indexAnalyzer); highlighter.setMaxLength(maxLength); @@ -228,7 +228,7 @@ public class TestUnifiedHighlighter extends LuceneTestCase { UnifiedHighlighter highlighter = randomUnifiedHighlighter(searcher, indexAnalyzer); Query query = new TermQuery(new Term("body", "test")); TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); String snippets[] = highlighter.highlight("body", query, topDocs); assertEquals(1, snippets.length); assertEquals("This is a test", snippets[0]); @@ -256,7 +256,7 @@ public class TestUnifiedHighlighter extends LuceneTestCase { UnifiedHighlighter highlighter = randomUnifiedHighlighter(searcher, indexAnalyzer); Query query = new TermQuery(new Term("body", "test")); TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); String snippets[] = highlighter.highlight("body", query, topDocs); assertEquals(2, snippets.length); assertEquals("This is a test.", snippets[0]); @@ -286,7 +286,7 @@ public class TestUnifiedHighlighter extends LuceneTestCase { highlighter.setMaxLength(value.length() * 2 + 1); Query query = new TermQuery(new Term("body", "field")); TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); String snippets[] = highlighter.highlight("body", query, topDocs, 10); assertEquals(1, snippets.length); String highlightedValue = "This is a multivalued field. Sentencetwo field."; @@ -321,7 +321,7 @@ public class TestUnifiedHighlighter extends LuceneTestCase { .add(new TermQuery(new Term("title", "best")), BooleanClause.Occur.SHOULD) .build(); TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); Map snippets = highlighter.highlightFields(new String[]{"body", "title"}, query, topDocs); assertEquals(2, snippets.size()); assertEquals("Just a test highlighting from postings. ", snippets.get("body")[0]); @@ -354,7 +354,7 @@ public class TestUnifiedHighlighter extends LuceneTestCase { .add(new TermQuery(new Term("body", "first")), BooleanClause.Occur.SHOULD) .build(); TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); String snippets[] = highlighter.highlight("body", query, topDocs); assertEquals(2, snippets.length); assertEquals("Just a test highlighting from postings. ", snippets[0]); @@ -382,7 +382,7 @@ public class TestUnifiedHighlighter extends LuceneTestCase { UnifiedHighlighter highlighter = randomUnifiedHighlighter(searcher, indexAnalyzer); Query query = new TermQuery(new Term("body", "test")); TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); String snippets[] = highlighter.highlight("body", query, topDocs, 2); assertEquals(2, snippets.length); assertEquals("This is a test. Just a test highlighting from postings. ", snippets[0]); @@ -415,7 +415,7 @@ public class TestUnifiedHighlighter extends LuceneTestCase { .add(new Term("body", "origins")) .build(); TopDocs topDocs = searcher.search(query, 10); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); UnifiedHighlighter highlighter = randomUnifiedHighlighter(searcher, indexAnalyzer); highlighter.setHighlightPhrasesStrictly(false); String snippets[] = highlighter.highlight("body", query, topDocs, 2); @@ -443,7 +443,7 @@ public class TestUnifiedHighlighter extends LuceneTestCase { .add(new Term("body", "george")) .build(); TopDocs topDocs = searcher.search(query, 10); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); UnifiedHighlighter highlighter = randomUnifiedHighlighter(searcher, indexAnalyzer); highlighter.setHighlightPhrasesStrictly(false); String snippets[] = highlighter.highlight("body", query, topDocs, 2); @@ -471,7 +471,7 @@ public class TestUnifiedHighlighter extends LuceneTestCase { .add(new TermQuery(new Term("body", "massachusetts")), BooleanClause.Occur.SHOULD) .build(); TopDocs topDocs = searcher.search(query, 10); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); UnifiedHighlighter highlighter = randomUnifiedHighlighter(searcher, indexAnalyzer); highlighter.setMaxLength(Integer.MAX_VALUE - 1); String snippets[] = highlighter.highlight("body", query, topDocs, 2); @@ -498,7 +498,7 @@ public class TestUnifiedHighlighter extends LuceneTestCase { UnifiedHighlighter highlighter = randomUnifiedHighlighter(searcher, indexAnalyzer); Query query = new TermQuery(new Term("body", "test")); TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); String snippets[] = highlighter.highlight("body", query, topDocs, 2); assertEquals(1, snippets.length); assertEquals("This is a test. ... Feel free to test test test test test test test.", snippets[0]); @@ -527,7 +527,7 @@ public class TestUnifiedHighlighter extends LuceneTestCase { .build(); TopDocs topDocs = searcher.search(query, 10); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); UnifiedHighlighter highlighter = randomUnifiedHighlighter(searcher, indexAnalyzer); highlighter.setMaxLength(Integer.MAX_VALUE - 1); String snippets[] = highlighter.highlight("body", query, topDocs, 2); @@ -559,7 +559,7 @@ public class TestUnifiedHighlighter extends LuceneTestCase { highlighter.setMaxLength(10000); Query query = new TermQuery(new Term("body", "test")); TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); String snippets[] = highlighter.highlight("body", query, topDocs, 2); assertEquals(1, snippets.length); assertEquals("This is a test. Just highlighting from postings. This is also a much sillier test. Feel free to test test test test test test test.", snippets[0]); @@ -586,7 +586,7 @@ public class TestUnifiedHighlighter extends LuceneTestCase { UnifiedHighlighter highlighter = randomUnifiedHighlighter(searcher, indexAnalyzer); Query query = new TermQuery(new Term("body", "highlighting")); TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); ScoreDoc[] hits = topDocs.scoreDocs; int[] docIDs = new int[2]; docIDs[0] = hits[0].doc; @@ -632,7 +632,7 @@ public class TestUnifiedHighlighter extends LuceneTestCase { Query query = new TermQuery(new Term("body", "test")); TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); String snippets[] = highlighter.highlight("body", query, topDocs, 2); assertEquals(1, snippets.length); assertEquals("This is a test. Just highlighting from postings. This is also a much sillier test. Feel free to test test test test test test test.", snippets[0]); @@ -872,7 +872,7 @@ public class TestUnifiedHighlighter extends LuceneTestCase { highlighter.setCacheFieldValCharsThreshold(random().nextInt(10) * 10);// 0 thru 90 intervals of 10 Query query = new TermQuery(new Term("body", "answer")); TopDocs hits = searcher.search(query, numDocs); - assertEquals(numDocs, hits.totalHits); + assertEquals(numDocs, hits.totalHits.value); String snippets[] = highlighter.highlight("body", query, hits); assertEquals(numDocs, snippets.length); @@ -941,7 +941,7 @@ public class TestUnifiedHighlighter extends LuceneTestCase { }; Query query = new TermQuery(new Term("body", "highlighting")); TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); String snippets[] = highlighter.highlight("body", query, topDocs); assertEquals(1, snippets.length); assertEquals("Just a test highlighting from <i>postings</i>. ", snippets[0]); @@ -982,7 +982,7 @@ public class TestUnifiedHighlighter extends LuceneTestCase { Query query = new TermQuery(new Term("body", "highlighting")); TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); int[] docIDs = new int[1]; docIDs[0] = topDocs.scoreDocs[0].doc; Map snippets = highlighter.highlightFieldsAsObjects(new String[]{"body"}, query, docIDs, new int[]{1}); @@ -1046,7 +1046,7 @@ public class TestUnifiedHighlighter extends LuceneTestCase { // title { TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); String[] snippets = highlighterNoFieldMatch.highlight("title", query, topDocs, 10); assertEquals(1, snippets.length); assertEquals("This is the title field.", snippets[0]); @@ -1065,7 +1065,7 @@ public class TestUnifiedHighlighter extends LuceneTestCase { // text { TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); String[] snippets = highlighterNoFieldMatch.highlight("text", query, topDocs, 10); assertEquals(1, snippets.length); assertEquals("This is the text field. You can put some text if you want.", snippets[0]); @@ -1084,7 +1084,7 @@ public class TestUnifiedHighlighter extends LuceneTestCase { // category { TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); String[] snippets = highlighterNoFieldMatch.highlight("category", query, topDocs, 10); assertEquals(1, snippets.length); assertEquals("This is the category field.", snippets[0]); @@ -1130,7 +1130,7 @@ public class TestUnifiedHighlighter extends LuceneTestCase { // title { TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); String[] snippets = highlighterNoFieldMatch.highlight("title", query, topDocs, 10); assertEquals(1, snippets.length); assertEquals("This is the title field.", snippets[0]); @@ -1149,7 +1149,7 @@ public class TestUnifiedHighlighter extends LuceneTestCase { // text { TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); String[] snippets = highlighterNoFieldMatch.highlight("text", query, topDocs, 10); assertEquals(1, snippets.length); assertEquals("This is the text field. You can put some text if you want.", snippets[0]); @@ -1168,7 +1168,7 @@ public class TestUnifiedHighlighter extends LuceneTestCase { // category { TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); String[] snippets = highlighterNoFieldMatch.highlight("category", query, topDocs, 10); assertEquals(1, snippets.length); assertEquals("This is the category field.", snippets[0]); @@ -1211,7 +1211,7 @@ public class TestUnifiedHighlighter extends LuceneTestCase { // title { TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); String[] snippets = highlighterNoFieldMatch.highlight("title", query, topDocs, 10); assertEquals(1, snippets.length); assertEquals("This is the title field.", snippets[0]); @@ -1230,7 +1230,7 @@ public class TestUnifiedHighlighter extends LuceneTestCase { // text { TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); String[] snippets = highlighterNoFieldMatch.highlight("text", query, topDocs, 10); assertEquals(1, snippets.length); assertEquals("This is the text field. You can put some text if you want.", snippets[0]); @@ -1249,7 +1249,7 @@ public class TestUnifiedHighlighter extends LuceneTestCase { // category { TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); String[] snippets = highlighterNoFieldMatch.highlight("category", query, topDocs, 10); assertEquals(1, snippets.length); assertEquals("This is the category field.", snippets[0]); diff --git a/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighterMTQ.java b/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighterMTQ.java index a9fadc0175f..2f97ad4eeb0 100644 --- a/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighterMTQ.java +++ b/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighterMTQ.java @@ -123,7 +123,7 @@ public class TestUnifiedHighlighterMTQ extends LuceneTestCase { UnifiedHighlighter highlighter = new UnifiedHighlighter(searcher, indexAnalyzer); Query query = new WildcardQuery(new Term("body", "te*")); TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); String snippets[] = highlighter.highlight("body", query, topDocs); assertEquals(2, snippets.length); assertEquals("This is a test.", snippets[0]); @@ -143,7 +143,7 @@ public class TestUnifiedHighlighterMTQ extends LuceneTestCase { .add(new WildcardQuery(new Term("bogus", "te*")), BooleanClause.Occur.SHOULD) .build(); topDocs = searcher.search(bq, 10, Sort.INDEXORDER); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); snippets = highlighter.highlight("body", bq, topDocs); assertEquals(2, snippets.length); assertEquals("This is a test.", snippets[0]); @@ -177,7 +177,7 @@ public class TestUnifiedHighlighterMTQ extends LuceneTestCase { // wrap in a BoostQuery to also show we see inside it Query query = new BoostQuery(new PrefixQuery(new Term("body", "te")), 2.0f); TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); String snippets[] = highlighter.highlight("body", query, topDocs); assertEquals(2, snippets.length); assertEquals("This is a test.", snippets[0]); @@ -190,7 +190,7 @@ public class TestUnifiedHighlighterMTQ extends LuceneTestCase { .add(new PrefixQuery(new Term("bogus", "te")), BooleanClause.Occur.SHOULD) .build(); topDocs = searcher.search(bq, 10, Sort.INDEXORDER); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); snippets = highlighter.highlight("body", bq, topDocs); assertEquals(2, snippets.length); assertEquals("This is a test.", snippets[0]); @@ -218,7 +218,7 @@ public class TestUnifiedHighlighterMTQ extends LuceneTestCase { UnifiedHighlighter highlighter = randomUnifiedHighlighter(searcher, indexAnalyzer); Query query = new RegexpQuery(new Term("body", "te.*")); TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); String snippets[] = highlighter.highlight("body", query, topDocs); assertEquals(2, snippets.length); assertEquals("This is a test.", snippets[0]); @@ -231,7 +231,7 @@ public class TestUnifiedHighlighterMTQ extends LuceneTestCase { .add(new RegexpQuery(new Term("bogus", "te.*")), BooleanClause.Occur.SHOULD) .build(); topDocs = searcher.search(bq, 10, Sort.INDEXORDER); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); snippets = highlighter.highlight("body", bq, topDocs); assertEquals(2, snippets.length); assertEquals("This is a test.", snippets[0]); @@ -259,7 +259,7 @@ public class TestUnifiedHighlighterMTQ extends LuceneTestCase { UnifiedHighlighter highlighter = randomUnifiedHighlighter(searcher, indexAnalyzer); Query query = new FuzzyQuery(new Term("body", "tets"), 1); TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); String snippets[] = highlighter.highlight("body", query, topDocs); assertEquals(2, snippets.length); assertEquals("This is a test.", snippets[0]); @@ -268,7 +268,7 @@ public class TestUnifiedHighlighterMTQ extends LuceneTestCase { // with prefix query = new FuzzyQuery(new Term("body", "tets"), 1, 2); topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); snippets = highlighter.highlight("body", query, topDocs); assertEquals(2, snippets.length); assertEquals("This is a test.", snippets[0]); @@ -281,7 +281,7 @@ public class TestUnifiedHighlighterMTQ extends LuceneTestCase { .add(new FuzzyQuery(new Term("bogus", "tets"), 1), BooleanClause.Occur.SHOULD) .build(); topDocs = searcher.search(bq, 10, Sort.INDEXORDER); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); snippets = highlighter.highlight("body", bq, topDocs); assertEquals(2, snippets.length); assertEquals("This is a test.", snippets[0]); @@ -309,7 +309,7 @@ public class TestUnifiedHighlighterMTQ extends LuceneTestCase { UnifiedHighlighter highlighter = randomUnifiedHighlighter(searcher, indexAnalyzer); Query query = TermRangeQuery.newStringRange("body", "ta", "tf", true, true); TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); String snippets[] = highlighter.highlight("body", query, topDocs); assertEquals(2, snippets.length); assertEquals("This is a test.", snippets[0]); @@ -318,7 +318,7 @@ public class TestUnifiedHighlighterMTQ extends LuceneTestCase { // null start query = TermRangeQuery.newStringRange("body", null, "tf", true, true); topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); snippets = highlighter.highlight("body", query, topDocs); assertEquals(2, snippets.length); assertEquals("This is a test.", snippets[0]); @@ -327,7 +327,7 @@ public class TestUnifiedHighlighterMTQ extends LuceneTestCase { // null end query = TermRangeQuery.newStringRange("body", "ta", null, true, true); topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); snippets = highlighter.highlight("body", query, topDocs); assertEquals(2, snippets.length); assertEquals("This is a test.", snippets[0]); @@ -336,7 +336,7 @@ public class TestUnifiedHighlighterMTQ extends LuceneTestCase { // exact start inclusive query = TermRangeQuery.newStringRange("body", "test", "tf", true, true); topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); snippets = highlighter.highlight("body", query, topDocs); assertEquals(2, snippets.length); assertEquals("This is a test.", snippets[0]); @@ -345,7 +345,7 @@ public class TestUnifiedHighlighterMTQ extends LuceneTestCase { // exact end inclusive query = TermRangeQuery.newStringRange("body", "ta", "test", true, true); topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); snippets = highlighter.highlight("body", query, topDocs); assertEquals(2, snippets.length); assertEquals("This is a test.", snippets[0]); @@ -357,7 +357,7 @@ public class TestUnifiedHighlighterMTQ extends LuceneTestCase { .add(TermRangeQuery.newStringRange("body", "test", "tf", false, true), BooleanClause.Occur.SHOULD) .build(); topDocs = searcher.search(bq, 10, Sort.INDEXORDER); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); snippets = highlighter.highlight("body", bq, topDocs); assertEquals(2, snippets.length); assertEquals("This is a test.", snippets[0]); @@ -369,7 +369,7 @@ public class TestUnifiedHighlighterMTQ extends LuceneTestCase { .add(TermRangeQuery.newStringRange("body", "ta", "test", true, false), BooleanClause.Occur.SHOULD) .build(); topDocs = searcher.search(bq, 10, Sort.INDEXORDER); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); snippets = highlighter.highlight("body", bq, topDocs); assertEquals(2, snippets.length); assertEquals("This is a test.", snippets[0]); @@ -382,7 +382,7 @@ public class TestUnifiedHighlighterMTQ extends LuceneTestCase { .add(TermRangeQuery.newStringRange("bogus", "ta", "tf", true, true), BooleanClause.Occur.SHOULD) .build(); topDocs = searcher.search(bq, 10, Sort.INDEXORDER); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); snippets = highlighter.highlight("body", bq, topDocs); assertEquals(2, snippets.length); assertEquals("This is a test.", snippets[0]); @@ -412,7 +412,7 @@ public class TestUnifiedHighlighterMTQ extends LuceneTestCase { .add(new WildcardQuery(new Term("body", "te*")), BooleanClause.Occur.SHOULD) .build(); TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); String snippets[] = highlighter.highlight("body", query, topDocs); assertEquals(2, snippets.length); assertEquals("This is a test.", snippets[0]); @@ -424,7 +424,7 @@ public class TestUnifiedHighlighterMTQ extends LuceneTestCase { .add(new WildcardQuery(new Term("bogus", "te*")), BooleanClause.Occur.MUST_NOT) .build(); topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); snippets = highlighter.highlight("body", query, topDocs); assertEquals(2, snippets.length); assertEquals("This is a test.", snippets[0]); @@ -455,7 +455,7 @@ public class TestUnifiedHighlighterMTQ extends LuceneTestCase { .add(new TermQuery(new Term("body", "test")), BooleanClause.Occur.FILTER) .build(); TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); String snippets[] = highlighter.highlight("body", query, topDocs); assertEquals(2, snippets.length); assertEquals("This is a test.", snippets[0]); @@ -483,7 +483,7 @@ public class TestUnifiedHighlighterMTQ extends LuceneTestCase { UnifiedHighlighter highlighter = randomUnifiedHighlighter(searcher, indexAnalyzer); ConstantScoreQuery query = new ConstantScoreQuery(new WildcardQuery(new Term("body", "te*"))); TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); String snippets[] = highlighter.highlight("body", query, topDocs); assertEquals(2, snippets.length); assertEquals("This is a test.", snippets[0]); @@ -512,7 +512,7 @@ public class TestUnifiedHighlighterMTQ extends LuceneTestCase { DisjunctionMaxQuery query = new DisjunctionMaxQuery( Collections.singleton(new WildcardQuery(new Term("body", "te*"))), 0); TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); String snippets[] = highlighter.highlight("body", query, topDocs); assertEquals(2, snippets.length); assertEquals("This is a test.", snippets[0]); @@ -542,7 +542,7 @@ public class TestUnifiedHighlighterMTQ extends LuceneTestCase { Query query = new SpanBoostQuery( new SpanMultiTermQueryWrapper<>(new WildcardQuery(new Term("body", "te*"))), 2.0f); TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); String snippets[] = highlighter.highlight("body", query, topDocs); assertEquals(2, snippets.length); assertEquals("This is a test.", snippets[0]); @@ -571,7 +571,7 @@ public class TestUnifiedHighlighterMTQ extends LuceneTestCase { SpanQuery childQuery = new SpanMultiTermQueryWrapper<>(new WildcardQuery(new Term("body", "te*"))); Query query = new SpanOrQuery(new SpanQuery[]{childQuery}); TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); String snippets[] = highlighter.highlight("body", query, topDocs); assertEquals(2, snippets.length); assertEquals("This is a test.", snippets[0]); @@ -600,7 +600,7 @@ public class TestUnifiedHighlighterMTQ extends LuceneTestCase { SpanQuery childQuery = new SpanMultiTermQueryWrapper<>(new WildcardQuery(new Term("body", "te*"))); Query query = new SpanNearQuery(new SpanQuery[]{childQuery, childQuery}, 0, false); TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); String snippets[] = highlighter.highlight("body", query, topDocs); assertEquals(2, snippets.length); assertEquals("This is a test.", snippets[0]); @@ -630,7 +630,7 @@ public class TestUnifiedHighlighterMTQ extends LuceneTestCase { SpanQuery exclude = new SpanTermQuery(new Term("body", "bogus")); Query query = new SpanNotQuery(include, exclude); TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); String snippets[] = highlighter.highlight("body", query, topDocs); assertEquals(2, snippets.length); assertEquals("This is a test.", snippets[0]); @@ -659,7 +659,7 @@ public class TestUnifiedHighlighterMTQ extends LuceneTestCase { SpanQuery childQuery = new SpanMultiTermQueryWrapper<>(new WildcardQuery(new Term("body", "te*"))); Query query = new SpanFirstQuery(childQuery, 1000000); TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); String snippets[] = highlighter.highlight("body", query, topDocs); assertEquals(2, snippets.length); assertEquals("This is a test.", snippets[0]); @@ -694,7 +694,7 @@ public class TestUnifiedHighlighterMTQ extends LuceneTestCase { .add(new FuzzyQuery(new Term("body", "zentence~")), BooleanClause.Occur.SHOULD) .build(); TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); String snippets[] = highlighter.highlight("body", query, topDocs); assertEquals(1, snippets.length); @@ -748,7 +748,7 @@ public class TestUnifiedHighlighterMTQ extends LuceneTestCase { } }; - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); snippets = highlighter.highlight("body", query, topDocs); assertEquals(1, snippets.length); @@ -1150,7 +1150,7 @@ public class TestUnifiedHighlighterMTQ extends LuceneTestCase { private void highlightAndAssertMatch(IndexSearcher searcher, UnifiedHighlighter highlighter, Query query, String field, String fieldVal) throws IOException { TopDocs topDocs = searcher.search(query, 1); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); String[] snippets = highlighter.highlight(field, query, topDocs); assertEquals("["+fieldVal+"]", Arrays.toString(snippets)); } diff --git a/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighterRanking.java b/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighterRanking.java index a235edd72b0..ac7e9bc90f1 100644 --- a/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighterRanking.java +++ b/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighterRanking.java @@ -281,7 +281,7 @@ public class TestUnifiedHighlighterRanking extends LuceneTestCase { }; Query query = new TermQuery(new Term("body", "test")); TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); String snippets[] = highlighter.highlight("body", query, topDocs, 1); assertEquals(1, snippets.length); assertTrue(snippets[0].startsWith("This test is a better test")); @@ -324,7 +324,7 @@ public class TestUnifiedHighlighterRanking extends LuceneTestCase { .add(new TermQuery(new Term("body", "bar")), BooleanClause.Occur.SHOULD) .build(); TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); String snippets[] = highlighter.highlight("body", query, topDocs, 1); assertEquals(1, snippets.length); assertTrue(snippets[0].startsWith("On the other hand")); diff --git a/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighterStrictPhrases.java b/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighterStrictPhrases.java index 44a8272d1b1..2fefaba26f6 100644 --- a/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighterStrictPhrases.java +++ b/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighterStrictPhrases.java @@ -44,6 +44,7 @@ import org.apache.lucene.search.ScoreMode; import org.apache.lucene.search.Sort; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.TopDocs; +import org.apache.lucene.search.TotalHits; import org.apache.lucene.search.Weight; import org.apache.lucene.search.WildcardQuery; import org.apache.lucene.search.spans.SpanMultiTermQueryWrapper; @@ -378,7 +379,7 @@ public class TestUnifiedHighlighterStrictPhrases extends LuceneTestCase { .add(phraseQuery, BooleanClause.Occur.MUST) // must match and it will .build(); topDocs = searcher.search(query, 10); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); snippets = highlighter.highlight("body", query, topDocs, 2); assertEquals("one bravo three... four bravo six", snippets[0]); } @@ -459,7 +460,7 @@ public class TestUnifiedHighlighterStrictPhrases extends LuceneTestCase { .add(proximityBoostingQuery, BooleanClause.Occur.SHOULD) .build(); TopDocs topDocs = searcher.search(totalQuery, 10, Sort.INDEXORDER); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); String[] snippets = highlighter.highlight("body", totalQuery, topDocs); assertArrayEquals(new String[]{"There is no accord and satisfaction with this - Consideration of the accord is arbitrary."}, snippets); } @@ -540,7 +541,7 @@ public class TestUnifiedHighlighterStrictPhrases extends LuceneTestCase { final String indexedText = "x y z x z x a"; indexWriter.addDocument(newDoc(indexedText)); initReaderSearcherHighlighter(); - TopDocs topDocs = new TopDocs(1, new ScoreDoc[]{new ScoreDoc(0, 1f)}); + TopDocs topDocs = new TopDocs(new TotalHits(1, TotalHits.Relation.EQUAL_TO), new ScoreDoc[]{new ScoreDoc(0, 1f)}); String expected = "x y z x z x a"; Query q = new SpanNearQuery(new SpanQuery[] { diff --git a/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighterTermVec.java b/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighterTermVec.java index 89332e2b018..2d9fb0e18df 100644 --- a/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighterTermVec.java +++ b/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighterTermVec.java @@ -100,7 +100,7 @@ public class TestUnifiedHighlighterTermVec extends LuceneTestCase { } BooleanQuery query = queryBuilder.build(); TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER); - assertEquals(numDocs, topDocs.totalHits); + assertEquals(numDocs, topDocs.totalHits.value); Map fieldToSnippets = highlighter.highlightFields(fields.toArray(new String[numTvFields]), query, topDocs); String[] expectedSnippetsByDoc = new String[numDocs]; diff --git a/lucene/highlighter/src/test/org/apache/lucene/search/vectorhighlight/FastVectorHighlighterTest.java b/lucene/highlighter/src/test/org/apache/lucene/search/vectorhighlight/FastVectorHighlighterTest.java index ddcce5ae877..1dce6d28046 100644 --- a/lucene/highlighter/src/test/org/apache/lucene/search/vectorhighlight/FastVectorHighlighterTest.java +++ b/lucene/highlighter/src/test/org/apache/lucene/search/vectorhighlight/FastVectorHighlighterTest.java @@ -353,7 +353,7 @@ public class FastVectorHighlighterTest extends LuceneTestCase { IndexReader reader = DirectoryReader.open(writer); IndexSearcher searcher = newSearcher(reader); TopDocs hits = searcher.search(query, 10); - assertEquals(2, hits.totalHits); + assertEquals(2, hits.totalHits.value); FieldQuery fieldQuery = highlighter.getFieldQuery(query, reader); String[] bestFragments = highlighter.getBestFragments(fieldQuery, reader, 1, "field", 1000, 1); assertEquals("This piece of text refers to Kennedy at the beginning then has a longer piece of text that is very long in the middle and finally ends with another reference to Kennedy", bestFragments[0]); diff --git a/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java index bcdeb87e0de..bbf73c0c924 100644 --- a/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java +++ b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java @@ -157,19 +157,19 @@ public class TestBlockJoin extends LuceneTestCase { fullQuery.add(new BooleanClause(childJoinQuery, Occur.MUST)); fullQuery.add(new BooleanClause(new MatchAllDocsQuery(), Occur.MUST)); TopDocs topDocs = s.search(fullQuery.build(), 2); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); assertEquals(asSet("Lisa", "Frank"), asSet(s.doc(topDocs.scoreDocs[0].doc).get("name"), s.doc(topDocs.scoreDocs[1].doc).get("name"))); ParentChildrenBlockJoinQuery childrenQuery = new ParentChildrenBlockJoinQuery(parentsFilter, childQuery.build(), topDocs.scoreDocs[0].doc); TopDocs matchingChildren = s.search(childrenQuery, 1); - assertEquals(1, matchingChildren.totalHits); + assertEquals(1, matchingChildren.totalHits.value); assertEquals("java", s.doc(matchingChildren.scoreDocs[0].doc).get("skill")); childrenQuery = new ParentChildrenBlockJoinQuery(parentsFilter, childQuery.build(), topDocs.scoreDocs[1].doc); matchingChildren = s.search(childrenQuery, 1); - assertEquals(1, matchingChildren.totalHits); + assertEquals(1, matchingChildren.totalHits.value); assertEquals("java", s.doc(matchingChildren.scoreDocs[0].doc).get("skill")); r.close(); @@ -221,19 +221,19 @@ public class TestBlockJoin extends LuceneTestCase { fullQuery.add(new BooleanClause(childJoinQuery, Occur.SHOULD)); final TopDocs topDocs = s.search(fullQuery.build(), 2); - assertEquals(2, topDocs.totalHits); + assertEquals(2, topDocs.totalHits.value); assertEquals(asSet("Lisa", "Frank"), asSet(s.doc(topDocs.scoreDocs[0].doc).get("name"), s.doc(topDocs.scoreDocs[1].doc).get("name"))); ParentChildrenBlockJoinQuery childrenQuery = new ParentChildrenBlockJoinQuery(parentsFilter, childQuery.build(), topDocs.scoreDocs[0].doc); TopDocs matchingChildren = s.search(childrenQuery, 1); - assertEquals(1, matchingChildren.totalHits); + assertEquals(1, matchingChildren.totalHits.value); assertEquals("java", s.doc(matchingChildren.scoreDocs[0].doc).get("skill")); childrenQuery = new ParentChildrenBlockJoinQuery(parentsFilter, childQuery.build(), topDocs.scoreDocs[1].doc); matchingChildren = s.search(childrenQuery, 1); - assertEquals(1, matchingChildren.totalHits); + assertEquals(1, matchingChildren.totalHits.value); assertEquals("java", s.doc(matchingChildren.scoreDocs[0].doc).get("skill")); r.close(); @@ -288,14 +288,14 @@ public class TestBlockJoin extends LuceneTestCase { TopDocs topDocs = s.search(fullQuery.build(), 1); //assertEquals(1, results.totalHitCount); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); Document parentDoc = s.doc(topDocs.scoreDocs[0].doc); assertEquals("Lisa", parentDoc.get("name")); ParentChildrenBlockJoinQuery childrenQuery = new ParentChildrenBlockJoinQuery(parentsFilter, childQuery.build(), topDocs.scoreDocs[0].doc); TopDocs matchingChildren = s.search(childrenQuery, 1); - assertEquals(1, matchingChildren.totalHits); + assertEquals(1, matchingChildren.totalHits.value); assertEquals("java", s.doc(matchingChildren.scoreDocs[0].doc).get("skill")); @@ -309,7 +309,7 @@ public class TestBlockJoin extends LuceneTestCase { //System.out.println("FULL: " + fullChildQuery); TopDocs hits = s.search(fullChildQuery.build(), 10); - assertEquals(1, hits.totalHits); + assertEquals(1, hits.totalHits.value); Document childDoc = s.doc(hits.scoreDocs[0].doc); //System.out.println("CHILD = " + childDoc + " docID=" + hits.scoreDocs[0].doc); assertEquals("java", childDoc.get("skill")); @@ -401,7 +401,7 @@ public class TestBlockJoin extends LuceneTestCase { .add(parentQuery, Occur.FILTER) .build(); TopDocs ukOnly = s.search(query, 1); - assertEquals("has filter - single passed", 1, ukOnly.totalHits); + assertEquals("has filter - single passed", 1, ukOnly.totalHits.value); assertEquals( "Lisa", r.document(ukOnly.scoreDocs[0].doc).get("name")); query = new BooleanQuery.Builder() @@ -410,7 +410,7 @@ public class TestBlockJoin extends LuceneTestCase { .build(); // looking for US candidates TopDocs usThen = s.search(query, 1); - assertEquals("has filter - single passed", 1, usThen.totalHits); + assertEquals("has filter - single passed", 1, usThen.totalHits.value); assertEquals("Frank", r.document(usThen.scoreDocs[0].doc).get("name")); @@ -774,7 +774,7 @@ public class TestBlockJoin extends LuceneTestCase { parentAndChildSort); if (VERBOSE) { - System.out.println("\nTEST: normal index gets " + results.totalHits + " hits; sort=" + parentAndChildSort); + System.out.println("\nTEST: normal index gets " + results.totalHits.value + " hits; sort=" + parentAndChildSort); final ScoreDoc[] hits = results.scoreDocs; for(int hitIDX=0;hitIDX joinResults) throws Exception { int currentParentID = -1; int childHitSlot = 0; - TopDocs childHits = new TopDocs(0, new ScoreDoc[0]); + TopDocs childHits = new TopDocs(new TotalHits(0, TotalHits.Relation.EQUAL_TO), new ScoreDoc[0]); for (ScoreDoc controlHit : controlHits.scoreDocs) { Document controlDoc = r.document(controlHit.doc); int parentID = Integer.parseInt(controlDoc.get("parentID")); @@ -1077,19 +1077,19 @@ public class TestBlockJoin extends LuceneTestCase { fullQuery.add(new BooleanClause(childQualificationJoinQuery, Occur.MUST)); final TopDocs topDocs = s.search(fullQuery.build(), 10); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); Document parentDoc = s.doc(topDocs.scoreDocs[0].doc); assertEquals("Lisa", parentDoc.get("name")); ParentChildrenBlockJoinQuery childrenQuery = new ParentChildrenBlockJoinQuery(parentsFilter, childJobQuery.build(), topDocs.scoreDocs[0].doc); TopDocs matchingChildren = s.search(childrenQuery, 1); - assertEquals(1, matchingChildren.totalHits); + assertEquals(1, matchingChildren.totalHits.value); assertEquals("java", s.doc(matchingChildren.scoreDocs[0].doc).get("skill")); childrenQuery = new ParentChildrenBlockJoinQuery(parentsFilter, childQualificationQuery.build(), topDocs.scoreDocs[0].doc); matchingChildren = s.search(childrenQuery, 1); - assertEquals(1, matchingChildren.totalHits); + assertEquals(1, matchingChildren.totalHits.value); assertEquals("maths", s.doc(matchingChildren.scoreDocs[0].doc).get("qualification")); r.close(); @@ -1254,7 +1254,7 @@ public class TestBlockJoin extends LuceneTestCase { ToChildBlockJoinQuery parentJoinQuery = new ToChildBlockJoinQuery(parentQuery, parentsFilter); TopDocs topdocs = s.search(parentJoinQuery, 3); - assertEquals(1, topdocs.totalHits); + assertEquals(1, topdocs.totalHits.value); r.close(); dir.close(); @@ -1505,7 +1505,7 @@ public class TestBlockJoin extends LuceneTestCase { for (ScoreMode scoreMode : ScoreMode.values()) { Query query = new ToParentBlockJoinQuery(new TermQuery(new Term("foo", "bar")), parents, scoreMode); TopDocs topDocs = searcher.search(query, 10); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); assertEquals(3, topDocs.scoreDocs[0].doc); float expectedScore; switch (scoreMode) { diff --git a/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoinSorting.java b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoinSorting.java index a570044aa24..5d530cc1c72 100644 --- a/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoinSorting.java +++ b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoinSorting.java @@ -224,7 +224,7 @@ public class TestBlockJoinSorting extends LuceneTestCase { ); Sort sort = new Sort(sortField); TopFieldDocs topDocs = searcher.search(query, 5, sort); - assertEquals(7, topDocs.totalHits); + assertEquals(7, topDocs.totalHits.value); assertEquals(5, topDocs.scoreDocs.length); assertEquals(3, topDocs.scoreDocs[0].doc); assertEquals("a", ((BytesRef) ((FieldDoc) topDocs.scoreDocs[0]).fields[0]).utf8ToString()); @@ -244,7 +244,7 @@ public class TestBlockJoinSorting extends LuceneTestCase { sort = new Sort(sortField); topDocs = searcher.search(query, 5, sort); - assertEquals(7, topDocs.totalHits); + assertEquals(7, topDocs.totalHits.value); assertEquals(5, topDocs.scoreDocs.length); assertEquals(3, topDocs.scoreDocs[0].doc); assertEquals("c", ((BytesRef) ((FieldDoc) topDocs.scoreDocs[0]).fields[0]).utf8ToString()); @@ -263,7 +263,7 @@ public class TestBlockJoinSorting extends LuceneTestCase { )); sort = new Sort(sortField); topDocs = searcher.search(query, 5, sort); - assertEquals(topDocs.totalHits, 7); + assertEquals(topDocs.totalHits.value, 7); assertEquals(5, topDocs.scoreDocs.length); assertEquals(27, topDocs.scoreDocs[0].doc); assertEquals("o", ((BytesRef) ((FieldDoc) topDocs.scoreDocs[0]).fields[0]).utf8ToString()); @@ -290,7 +290,7 @@ public class TestBlockJoinSorting extends LuceneTestCase { sort = new Sort(sortField); topDocs = searcher.search(query, 5, sort); - assertEquals(6, topDocs.totalHits); + assertEquals(6, topDocs.totalHits.value); assertEquals(5, topDocs.scoreDocs.length); assertEquals(23, topDocs.scoreDocs[0].doc); assertEquals("m", ((BytesRef) ((FieldDoc) topDocs.scoreDocs[0]).fields[0]).utf8ToString()); diff --git a/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java b/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java index 3f3ac7c8f75..123e9980df3 100644 --- a/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java +++ b/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java @@ -153,20 +153,20 @@ public class TestJoinUtil extends LuceneTestCase { JoinUtil.createJoinQuery(idField, false, toField, new TermQuery(new Term("name", "name2")), indexSearcher, ScoreMode.None); TopDocs result = indexSearcher.search(joinQuery, 10); - assertEquals(2, result.totalHits); + assertEquals(2, result.totalHits.value); assertEquals(4, result.scoreDocs[0].doc); assertEquals(5, result.scoreDocs[1].doc); joinQuery = JoinUtil.createJoinQuery(idField, false, toField, new TermQuery(new Term("name", "name1")), indexSearcher, ScoreMode.None); result = indexSearcher.search(joinQuery, 10); - assertEquals(2, result.totalHits); + assertEquals(2, result.totalHits.value); assertEquals(1, result.scoreDocs[0].doc); assertEquals(2, result.scoreDocs[1].doc); // Search for offer joinQuery = JoinUtil.createJoinQuery(toField, false, idField, new TermQuery(new Term("id", "5")), indexSearcher, ScoreMode.None); result = indexSearcher.search(joinQuery, 10); - assertEquals(1, result.totalHits); + assertEquals(1, result.totalHits.value); assertEquals(3, result.scoreDocs[0].doc); indexSearcher.getIndexReader().close(); @@ -257,14 +257,14 @@ public class TestJoinUtil extends LuceneTestCase { // Search for product and return prices Query joinQuery = JoinUtil.createJoinQuery(joinField, fromQuery, toQuery, indexSearcher, ScoreMode.None, ordinalMap); TopDocs result = indexSearcher.search(joinQuery, 10); - assertEquals(2, result.totalHits); + assertEquals(2, result.totalHits.value); assertEquals(4, result.scoreDocs[0].doc); assertEquals(5, result.scoreDocs[1].doc); fromQuery = new TermQuery(new Term("name", "name1")); joinQuery = JoinUtil.createJoinQuery(joinField, fromQuery, toQuery, indexSearcher, ScoreMode.None, ordinalMap); result = indexSearcher.search(joinQuery, 10); - assertEquals(2, result.totalHits); + assertEquals(2, result.totalHits.value); assertEquals(1, result.scoreDocs[0].doc); assertEquals(2, result.scoreDocs[1].doc); @@ -273,7 +273,7 @@ public class TestJoinUtil extends LuceneTestCase { toQuery = new TermQuery(new Term(typeField, "product")); joinQuery = JoinUtil.createJoinQuery(joinField, fromQuery, toQuery, indexSearcher, ScoreMode.None, ordinalMap); result = indexSearcher.search(joinQuery, 10); - assertEquals(2, result.totalHits); + assertEquals(2, result.totalHits.value); assertEquals(0, result.scoreDocs[0].doc); assertEquals(3, result.scoreDocs[1].doc); @@ -363,7 +363,7 @@ public class TestJoinUtil extends LuceneTestCase { for (ScoreMode scoreMode : ScoreMode.values()) { Query joinQuery = JoinUtil.createJoinQuery(joinField, fromQuery, toQuery, indexSearcher, scoreMode, ordinalMap); TopDocs result = indexSearcher.search(joinQuery, 10); - assertEquals(1, result.totalHits); + assertEquals(1, result.totalHits.value); assertEquals(4, result.scoreDocs[0].doc); // doc with price: 5.0 Explanation explanation = indexSearcher.explain(joinQuery, 4); assertTrue(explanation.isMatch()); @@ -489,7 +489,7 @@ public class TestJoinUtil extends LuceneTestCase { Query toQuery = new TermQuery(new Term("type", "to")); Query joinQuery = JoinUtil.createJoinQuery("join_field", fromQuery.build(), toQuery, searcher, ScoreMode.Min, ordinalMap); TopDocs topDocs = searcher.search(joinQuery, numParents); - assertEquals(numParents, topDocs.totalHits); + assertEquals(numParents, topDocs.totalHits.value); for (int i = 0; i < topDocs.scoreDocs.length; i++) { ScoreDoc scoreDoc = topDocs.scoreDocs[i]; String id = searcher.doc(scoreDoc.doc).get("id"); @@ -498,7 +498,7 @@ public class TestJoinUtil extends LuceneTestCase { joinQuery = JoinUtil.createJoinQuery("join_field", fromQuery.build(), toQuery, searcher, ScoreMode.Max, ordinalMap); topDocs = searcher.search(joinQuery, numParents); - assertEquals(numParents, topDocs.totalHits); + assertEquals(numParents, topDocs.totalHits.value); for (int i = 0; i < topDocs.scoreDocs.length; i++) { ScoreDoc scoreDoc = topDocs.scoreDocs[i]; String id = searcher.doc(scoreDoc.doc).get("id"); @@ -711,7 +711,7 @@ public class TestJoinUtil extends LuceneTestCase { JoinUtil.createJoinQuery(toField, multipleValues, idField, new TermQuery(new Term("price", "10.0")), indexSearcher, scoreMode); TopDocs result = indexSearcher.search(joinQuery, 10); - assertEquals(1, result.totalHits); + assertEquals(1, result.totalHits.value); assertEquals(0, result.scoreDocs[0].doc); indexSearcher.getIndexReader().close(); @@ -885,28 +885,28 @@ public class TestJoinUtil extends LuceneTestCase { Query joinQuery = JoinUtil.createJoinQuery(toField, false, idField, new TermQuery(new Term("subtitle", "random")), indexSearcher, ScoreMode.Max); TopDocs result = indexSearcher.search(joinQuery, 10); - assertEquals(2, result.totalHits); + assertEquals(2, result.totalHits.value); assertEquals(0, result.scoreDocs[0].doc); assertEquals(3, result.scoreDocs[1].doc); // Score mode max. joinQuery = JoinUtil.createJoinQuery(toField, false, idField, new TermQuery(new Term("subtitle", "movie")), indexSearcher, ScoreMode.Max); result = indexSearcher.search(joinQuery, 10); - assertEquals(2, result.totalHits); + assertEquals(2, result.totalHits.value); assertEquals(3, result.scoreDocs[0].doc); assertEquals(0, result.scoreDocs[1].doc); // Score mode total joinQuery = JoinUtil.createJoinQuery(toField, false, idField, new TermQuery(new Term("subtitle", "movie")), indexSearcher, ScoreMode.Total); result = indexSearcher.search(joinQuery, 10); - assertEquals(2, result.totalHits); + assertEquals(2, result.totalHits.value); assertEquals(0, result.scoreDocs[0].doc); assertEquals(3, result.scoreDocs[1].doc); //Score mode avg joinQuery = JoinUtil.createJoinQuery(toField, false, idField, new TermQuery(new Term("subtitle", "movie")), indexSearcher, ScoreMode.Avg); result = indexSearcher.search(joinQuery, 10); - assertEquals(2, result.totalHits); + assertEquals(2, result.totalHits.value); assertEquals(3, result.scoreDocs[0].doc); assertEquals(0, result.scoreDocs[1].doc); @@ -1275,7 +1275,7 @@ public class TestJoinUtil extends LuceneTestCase { } private void assertTopDocs(TopDocs expectedTopDocs, TopDocs actualTopDocs, ScoreMode scoreMode, IndexSearcher indexSearcher, Query joinQuery) throws IOException { - assertEquals(expectedTopDocs.totalHits, actualTopDocs.totalHits); + assertEquals(expectedTopDocs.totalHits.value, actualTopDocs.totalHits.value); assertEquals(expectedTopDocs.scoreDocs.length, actualTopDocs.scoreDocs.length); if (scoreMode == ScoreMode.None) { return; @@ -1646,7 +1646,7 @@ public class TestJoinUtil extends LuceneTestCase { Map.Entry hit = hits.get(i); scoreDocs[i] = new ScoreDoc(hit.getKey(), hit.getValue().score(scoreMode)); } - return new TopDocs(hits.size(), scoreDocs); + return new TopDocs(new TotalHits(hits.size(), TotalHits.Relation.EQUAL_TO), scoreDocs); } private BitSet createExpectedResult(String queryValue, boolean from, IndexReader topLevelReader, IndexIterationContext context) throws IOException { diff --git a/lucene/join/src/test/org/apache/lucene/search/join/TestParentChildrenBlockJoinQuery.java b/lucene/join/src/test/org/apache/lucene/search/join/TestParentChildrenBlockJoinQuery.java index f6cc6d98cbb..7bf0911a2a5 100644 --- a/lucene/join/src/test/org/apache/lucene/search/join/TestParentChildrenBlockJoinQuery.java +++ b/lucene/join/src/test/org/apache/lucene/search/join/TestParentChildrenBlockJoinQuery.java @@ -86,7 +86,7 @@ public class TestParentChildrenBlockJoinQuery extends LuceneTestCase { ParentChildrenBlockJoinQuery parentChildrenBlockJoinQuery = new ParentChildrenBlockJoinQuery(parentFilter, childQuery, parentScoreDoc.doc); TopDocs topDocs = searcher.search(parentChildrenBlockJoinQuery, maxChildDocsPerParent); - assertEquals(expectedChildDocs, topDocs.totalHits); + assertEquals(expectedChildDocs, topDocs.totalHits.value); if (expectedChildDocs > 0) { for (int i = 0; i < topDocs.scoreDocs.length; i++) { ScoreDoc childScoreDoc = topDocs.scoreDocs[i]; diff --git a/lucene/memory/src/test/org/apache/lucene/index/memory/TestMemoryIndexAgainstRAMDir.java b/lucene/memory/src/test/org/apache/lucene/index/memory/TestMemoryIndexAgainstRAMDir.java index c911183c7d7..a4215a1d683 100644 --- a/lucene/memory/src/test/org/apache/lucene/index/memory/TestMemoryIndexAgainstRAMDir.java +++ b/lucene/memory/src/test/org/apache/lucene/index/memory/TestMemoryIndexAgainstRAMDir.java @@ -246,7 +246,7 @@ public class TestMemoryIndexAgainstRAMDir extends BaseTokenStreamTestCase { for (String query : queries) { TopDocs ramDocs = ram.search(qp.parse(query), 1); TopDocs memDocs = mem.search(qp.parse(query), 1); - assertEquals(query, ramDocs.totalHits, memDocs.totalHits); + assertEquals(query, ramDocs.totalHits.value, memDocs.totalHits.value); } reader.close(); } @@ -652,7 +652,7 @@ public class TestMemoryIndexAgainstRAMDir extends BaseTokenStreamTestCase { memory.addField("foo", new CannedTokenStream(new Token("", 0, 5))); IndexSearcher searcher = memory.createSearcher(); TopDocs docs = searcher.search(new TermQuery(new Term("foo", "")), 10); - assertEquals(1, docs.totalHits); + assertEquals(1, docs.totalHits.value); TestUtil.checkReader(searcher.getIndexReader()); } diff --git a/lucene/misc/src/java/org/apache/lucene/search/DiversifiedTopDocsCollector.java b/lucene/misc/src/java/org/apache/lucene/search/DiversifiedTopDocsCollector.java index bd4978dc45c..68708afcee6 100644 --- a/lucene/misc/src/java/org/apache/lucene/search/DiversifiedTopDocsCollector.java +++ b/lucene/misc/src/java/org/apache/lucene/search/DiversifiedTopDocsCollector.java @@ -92,7 +92,7 @@ public abstract class DiversifiedTopDocsCollector extends return EMPTY_TOPDOCS; } - return new TopDocs(totalHits, results); + return new TopDocs(new TotalHits(totalHits, TotalHits.Relation.EQUAL_TO), results); } protected ScoreDocKey insert(ScoreDocKey addition, int docBase, diff --git a/lucene/queries/src/test/org/apache/lucene/queries/CommonTermsQueryTest.java b/lucene/queries/src/test/org/apache/lucene/queries/CommonTermsQueryTest.java index 684344e00e0..9b3ab88dfd4 100644 --- a/lucene/queries/src/test/org/apache/lucene/queries/CommonTermsQueryTest.java +++ b/lucene/queries/src/test/org/apache/lucene/queries/CommonTermsQueryTest.java @@ -85,7 +85,7 @@ public class CommonTermsQueryTest extends LuceneTestCase { query.add(new Term("field", "universe")); query.add(new Term("field", "right")); TopDocs search = s.search(query, 10); - assertEquals(search.totalHits, 3); + assertEquals(search.totalHits.value, 3); assertEquals("0", r.document(search.scoreDocs[0].doc).get("id")); assertEquals("2", r.document(search.scoreDocs[1].doc).get("id")); assertEquals("3", r.document(search.scoreDocs[2].doc).get("id")); @@ -98,7 +98,7 @@ public class CommonTermsQueryTest extends LuceneTestCase { query.add(new Term("field", "this")); query.add(new Term("field", "end")); TopDocs search = s.search(query, 10); - assertEquals(search.totalHits, 2); + assertEquals(search.totalHits.value, 2); assertEquals("0", r.document(search.scoreDocs[0].doc).get("id")); assertEquals("2", r.document(search.scoreDocs[1].doc).get("id")); } @@ -112,7 +112,7 @@ public class CommonTermsQueryTest extends LuceneTestCase { query.add(new Term("field", "world")); TopDocs search = s.search(query, 10); - assertEquals(search.totalHits, 1); + assertEquals(search.totalHits.value, 1); assertEquals("0", r.document(search.scoreDocs[0].doc).get("id")); } @@ -123,7 +123,7 @@ public class CommonTermsQueryTest extends LuceneTestCase { query.add(new Term("field", "universe")); TopDocs search = s.search(query, 10); - assertEquals(search.totalHits, 1); + assertEquals(search.totalHits.value, 1); assertEquals("3", r.document(search.scoreDocs[0].doc).get("id")); } @@ -212,7 +212,7 @@ public class CommonTermsQueryTest extends LuceneTestCase { query.add(new Term("field", "right")); query.setLowFreqMinimumNumberShouldMatch(0.5f); TopDocs search = s.search(query, 10); - assertEquals(search.totalHits, 1); + assertEquals(search.totalHits.value, 1); assertEquals("0", r.document(search.scoreDocs[0].doc).get("id")); } { @@ -226,7 +226,7 @@ public class CommonTermsQueryTest extends LuceneTestCase { query.add(new Term("field", "right")); query.setLowFreqMinimumNumberShouldMatch(2.0f); TopDocs search = s.search(query, 10); - assertEquals(search.totalHits, 1); + assertEquals(search.totalHits.value, 1); assertEquals("0", r.document(search.scoreDocs[0].doc).get("id")); } @@ -241,7 +241,7 @@ public class CommonTermsQueryTest extends LuceneTestCase { query.add(new Term("field", "right")); query.setLowFreqMinimumNumberShouldMatch(0.49f); TopDocs search = s.search(query, 10); - assertEquals(search.totalHits, 3); + assertEquals(search.totalHits.value, 3); assertEquals("0", r.document(search.scoreDocs[0].doc).get("id")); assertEquals("2", r.document(search.scoreDocs[1].doc).get("id")); assertEquals("3", r.document(search.scoreDocs[2].doc).get("id")); @@ -258,7 +258,7 @@ public class CommonTermsQueryTest extends LuceneTestCase { query.add(new Term("field", "right")); query.setLowFreqMinimumNumberShouldMatch(1.0f); TopDocs search = s.search(query, 10); - assertEquals(search.totalHits, 3); + assertEquals(search.totalHits.value, 3); assertEquals("0", r.document(search.scoreDocs[0].doc).get("id")); assertEquals("2", r.document(search.scoreDocs[1].doc).get("id")); assertEquals("3", r.document(search.scoreDocs[2].doc).get("id")); @@ -277,7 +277,7 @@ public class CommonTermsQueryTest extends LuceneTestCase { query.setLowFreqMinimumNumberShouldMatch(1.0f); query.setHighFreqMinimumNumberShouldMatch(4.0f); TopDocs search = s.search(query, 10); - assertEquals(search.totalHits, 3); + assertEquals(search.totalHits.value, 3); assertEquals(search.scoreDocs[1].score, search.scoreDocs[2].score, 0.0f); assertEquals("0", r.document(search.scoreDocs[0].doc).get("id")); // doc 2 and 3 only get a score from low freq terms @@ -298,7 +298,7 @@ public class CommonTermsQueryTest extends LuceneTestCase { query.setLowFreqMinimumNumberShouldMatch(1.0f); query.setHighFreqMinimumNumberShouldMatch(2.0f); TopDocs search = s.search(query, 10); - assertEquals(search.totalHits, 4); + assertEquals(search.totalHits.value, 4); } { @@ -311,7 +311,7 @@ public class CommonTermsQueryTest extends LuceneTestCase { query.setLowFreqMinimumNumberShouldMatch(1.0f); query.setHighFreqMinimumNumberShouldMatch(2.0f); TopDocs search = s.search(query, 10); - assertEquals(search.totalHits, 2); + assertEquals(search.totalHits.value, 2); assertEquals( new HashSet<>(Arrays.asList("0", "2")), new HashSet<>(Arrays.asList( @@ -367,7 +367,7 @@ public class CommonTermsQueryTest extends LuceneTestCase { query.add(new Term("field", "universe")); query.add(new Term("field", "right")); TopDocs search = s.search(query, 10); - assertEquals(search.totalHits, 3); + assertEquals(search.totalHits.value, 3); assertEquals("0", r.document(search.scoreDocs[0].doc).get("id")); assertEquals("2", r.document(search.scoreDocs[1].doc).get("id")); assertEquals("3", r.document(search.scoreDocs[2].doc).get("id")); @@ -384,7 +384,7 @@ public class CommonTermsQueryTest extends LuceneTestCase { query.add(new Term("field", "universe")); query.add(new Term("field", "right")); TopDocs search = s.search(query, 10); - assertEquals(search.totalHits, 3); + assertEquals(search.totalHits.value, 3); assertEquals("2", r.document(search.scoreDocs[0].doc).get("id")); assertEquals("3", r.document(search.scoreDocs[1].doc).get("id")); assertEquals("0", r.document(search.scoreDocs[2].doc).get("id")); @@ -466,7 +466,7 @@ public class CommonTermsQueryTest extends LuceneTestCase { TopDocs cqSearch = searcher.search(cq, reader.maxDoc()); TopDocs verifySearch = searcher.search(verifyQuery.build(), reader.maxDoc()); - assertEquals(verifySearch.totalHits, cqSearch.totalHits); + assertEquals(verifySearch.totalHits.value, cqSearch.totalHits.value); Set hits = new HashSet<>(); for (ScoreDoc doc : verifySearch.scoreDocs) { hits.add(doc.doc); diff --git a/lucene/queries/src/test/org/apache/lucene/queries/function/TestFieldScoreQuery.java b/lucene/queries/src/test/org/apache/lucene/queries/function/TestFieldScoreQuery.java index 977d801049a..88a8e028518 100644 --- a/lucene/queries/src/test/org/apache/lucene/queries/function/TestFieldScoreQuery.java +++ b/lucene/queries/src/test/org/apache/lucene/queries/function/TestFieldScoreQuery.java @@ -122,7 +122,7 @@ public class TestFieldScoreQuery extends FunctionTestSetup { IndexReader r = DirectoryReader.open(dir); IndexSearcher s = newSearcher(r); TopDocs td = s.search(functionQuery,1000); - assertEquals("All docs should be matched!",N_DOCS,td.totalHits); + assertEquals("All docs should be matched!",N_DOCS,td.totalHits.value); ScoreDoc sd[] = td.scoreDocs; for (ScoreDoc aSd : sd) { float score = aSd.score; diff --git a/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionMatchQuery.java b/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionMatchQuery.java index 61faa151fc1..38d8d8ac388 100644 --- a/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionMatchQuery.java +++ b/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionMatchQuery.java @@ -50,7 +50,7 @@ public class TestFunctionMatchQuery extends FunctionTestSetup { FunctionMatchQuery fmq = new FunctionMatchQuery(in, d -> d >= 2 && d < 4); TopDocs docs = searcher.search(fmq, 10); - assertEquals(2, docs.totalHits); + assertEquals(2, docs.totalHits.value); assertEquals(9, docs.scoreDocs[0].doc); assertEquals(13, docs.scoreDocs[1].doc); diff --git a/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionScoreQuery.java b/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionScoreQuery.java index d97d5adbd80..3d3f54e4931 100644 --- a/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionScoreQuery.java +++ b/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionScoreQuery.java @@ -109,7 +109,7 @@ public class TestFunctionScoreQuery extends FunctionTestSetup { int expectedDocs[] = new int[]{ 4, 7, 9 }; TopDocs docs = searcher.search(q, 4); - assertEquals(expectedDocs.length, docs.totalHits); + assertEquals(expectedDocs.length, docs.totalHits.value); for (int i = 0; i < expectedDocs.length; i++) { assertEquals(docs.scoreDocs[i].doc, expectedDocs[i]); } @@ -131,7 +131,7 @@ public class TestFunctionScoreQuery extends FunctionTestSetup { int[] expectedDocs = new int[]{ 4, 7, 9, 8, 12 }; TopDocs docs = searcher.search(fq, 5); - assertEquals(plain.totalHits, docs.totalHits); + assertEquals(plain.totalHits.value, docs.totalHits.value); for (int i = 0; i < expectedDocs.length; i++) { assertEquals(expectedDocs[i], docs.scoreDocs[i].doc); } @@ -155,7 +155,7 @@ public class TestFunctionScoreQuery extends FunctionTestSetup { int[] expectedDocs = new int[]{ 6, 1, 0, 2, 8 }; TopDocs docs = searcher.search(fq, 20); - assertEquals(plain.totalHits, docs.totalHits); + assertEquals(plain.totalHits.value, docs.totalHits.value); for (int i = 0; i < expectedDocs.length; i++) { assertEquals(expectedDocs[i], docs.scoreDocs[i].doc); } @@ -177,7 +177,7 @@ public class TestFunctionScoreQuery extends FunctionTestSetup { Query boosted = new BoostQuery(q1, 2); TopDocs afterboost = searcher.search(boosted, 5); - assertEquals(plain.totalHits, afterboost.totalHits); + assertEquals(plain.totalHits.value, afterboost.totalHits.value); for (int i = 0; i < 5; i++) { assertEquals(plain.scoreDocs[i].doc, afterboost.scoreDocs[i].doc); assertEquals(plain.scoreDocs[i].score, afterboost.scoreDocs[i].score / 2, 0.0001); diff --git a/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadTermQuery.java b/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadTermQuery.java index f22793c8d21..85c7ea24927 100644 --- a/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadTermQuery.java +++ b/lucene/queries/src/test/org/apache/lucene/queries/payloads/TestPayloadTermQuery.java @@ -153,7 +153,7 @@ public class TestPayloadTermQuery extends LuceneTestCase { new MaxPayloadFunction(), PayloadDecoder.FLOAT_DECODER); TopDocs hits = searcher.search(query, 100); assertTrue("hits is null and it shouldn't be", hits != null); - assertTrue("hits Size: " + hits.totalHits + " is not: " + 100, hits.totalHits == 100); + assertTrue("hits Size: " + hits.totalHits.value + " is not: " + 100, hits.totalHits.value == 100); //they should all have the exact same score, because they all contain seventy once, and we set //all the other similarity factors to be 1 @@ -193,7 +193,7 @@ public class TestPayloadTermQuery extends LuceneTestCase { new MaxPayloadFunction(), PayloadDecoder.FLOAT_DECODER); TopDocs hits = searcher.search(query, 100); assertTrue("hits is null and it shouldn't be", hits != null); - assertTrue("hits Size: " + hits.totalHits + " is not: " + 100, hits.totalHits == 100); + assertTrue("hits Size: " + hits.totalHits.value + " is not: " + 100, hits.totalHits.value == 100); //they should all have the exact same score, because they all contain seventy once, and we set //all the other similarity factors to be 1 @@ -231,7 +231,7 @@ public class TestPayloadTermQuery extends LuceneTestCase { new MaxPayloadFunction(), PayloadDecoder.FLOAT_DECODER); TopDocs hits = searcher.search(query, 100); assertTrue("hits is null and it shouldn't be", hits != null); - assertTrue("hits Size: " + hits.totalHits + " is not: " + 0, hits.totalHits == 0); + assertTrue("hits Size: " + hits.totalHits.value + " is not: " + 0, hits.totalHits.value == 0); } @@ -247,7 +247,7 @@ public class TestPayloadTermQuery extends LuceneTestCase { query.add(c2); TopDocs hits = searcher.search(query.build(), 100); assertTrue("hits is null and it shouldn't be", hits != null); - assertTrue("hits Size: " + hits.totalHits + " is not: " + 1, hits.totalHits == 1); + assertTrue("hits Size: " + hits.totalHits.value + " is not: " + 1, hits.totalHits.value == 1); int[] results = new int[1]; results[0] = 0;//hits.scoreDocs[0].doc; CheckHits.checkHitCollector(random(), query.build(), PayloadHelper.NO_PAYLOAD_FIELD, searcher, results); 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.java index 6b1a6aad61b..b759e370b2a 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); - long hits = is.search(q, 10).totalHits; + long hits = is.count(q); ir.close(); ramDir.close(); if (hits == 1){ diff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestQPHelper.java b/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestQPHelper.java index 2aa96beaaaf..b87dc8a1fda 100644 --- a/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestQPHelper.java +++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestQPHelper.java @@ -1309,7 +1309,7 @@ public class TestQPHelper extends LuceneTestCase { Query q = new StandardQueryParser(new CannedAnalyzer()).parse("\"a\"", "field"); assertTrue(q instanceof MultiPhraseQuery); - assertEquals(1, s.search(q, 10).totalHits); + assertEquals(1, s.search(q, 10).totalHits.value); r.close(); w.close(); dir.close(); diff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/util/QueryParserTestBase.java b/lucene/queryparser/src/test/org/apache/lucene/queryparser/util/QueryParserTestBase.java index b49f5765dd2..b87ba3736cf 100644 --- a/lucene/queryparser/src/test/org/apache/lucene/queryparser/util/QueryParserTestBase.java +++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/util/QueryParserTestBase.java @@ -1140,7 +1140,7 @@ public abstract class QueryParserTestBase extends LuceneTestCase { IndexSearcher s = newSearcher(r); Query q = getQuery("\"wizard of ozzy\"",a); - assertEquals(1, s.search(q, 1).totalHits); + assertEquals(1, s.search(q, 1).totalHits.value); r.close(); dir.close(); } 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.java index b9e44c1ba37..1b434bb3d15 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 @@ -118,7 +118,7 @@ public class TestCoreParser extends LuceneTestCase { public void testCustomFieldUserQueryXML() throws ParserException, IOException { Query q = parse("UserInputQueryCustomField.xml"); - long h = searcher().search(q, 1000).totalHits; + long h = searcher().search(q, 1000).totalHits.value; assertEquals("UserInputQueryCustomField should produce 0 result ", 0, h); } @@ -252,13 +252,13 @@ public class TestCoreParser extends LuceneTestCase { } final IndexSearcher searcher = searcher(); TopDocs hits = searcher.search(q, numDocs); - final boolean producedResults = (hits.totalHits > 0); + final boolean producedResults = (hits.totalHits.value > 0); if (!producedResults) { System.out.println("TEST: qType=" + qType + " numDocs=" + numDocs + " " + q.getClass().getCanonicalName() + " query=" + q); } if (VERBOSE) { ScoreDoc[] scoreDocs = hits.scoreDocs; - for (int i = 0; i < Math.min(numDocs, hits.totalHits); i++) { + for (int i = 0; i < Math.min(numDocs, hits.totalHits.value); i++) { Document ldoc = searcher.doc(scoreDocs[i].doc); System.out.println("[" + ldoc.get("date") + "]" + ldoc.get("contents")); } diff --git a/lucene/replicator/src/test/org/apache/lucene/replicator/IndexAndTaxonomyReplicationClientTest.java b/lucene/replicator/src/test/org/apache/lucene/replicator/IndexAndTaxonomyReplicationClientTest.java index 9ccb2c7a776..7b4a28b7406 100644 --- a/lucene/replicator/src/test/org/apache/lucene/replicator/IndexAndTaxonomyReplicationClientTest.java +++ b/lucene/replicator/src/test/org/apache/lucene/replicator/IndexAndTaxonomyReplicationClientTest.java @@ -115,7 +115,7 @@ public class IndexAndTaxonomyReplicationClientTest extends ReplicatorTestCase { DrillDownQuery drillDown = new DrillDownQuery(config); drillDown.add("A", Integer.toString(id, 16)); TopDocs docs = searcher.search(drillDown, 10); - assertEquals(1, docs.totalHits); + assertEquals(1, docs.totalHits.value); } return null; } diff --git a/lucene/sandbox/src/java/org/apache/lucene/document/FloatPointNearestNeighbor.java b/lucene/sandbox/src/java/org/apache/lucene/document/FloatPointNearestNeighbor.java index 80a5e7d317a..8458746b86f 100644 --- a/lucene/sandbox/src/java/org/apache/lucene/document/FloatPointNearestNeighbor.java +++ b/lucene/sandbox/src/java/org/apache/lucene/document/FloatPointNearestNeighbor.java @@ -29,6 +29,7 @@ import org.apache.lucene.search.FieldDoc; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.TopFieldDocs; +import org.apache.lucene.search.TotalHits; import org.apache.lucene.util.Bits; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.bkd.BKDReader; @@ -378,6 +379,6 @@ public class FloatPointNearestNeighbor { NearestHit hit = hits[i]; scoreDocs[i] = new FieldDoc(hit.docID, 0.0f, new Object[] { (float)Math.sqrt(hit.distanceSquared) }); } - return new TopFieldDocs(totalHits, scoreDocs, null); + return new TopFieldDocs(new TotalHits(totalHits, TotalHits.Relation.EQUAL_TO), scoreDocs, null); } } diff --git a/lucene/sandbox/src/java/org/apache/lucene/search/LatLonPointPrototypeQueries.java b/lucene/sandbox/src/java/org/apache/lucene/search/LatLonPointPrototypeQueries.java index ee0f0767786..73cbbb87fe4 100644 --- a/lucene/sandbox/src/java/org/apache/lucene/search/LatLonPointPrototypeQueries.java +++ b/lucene/sandbox/src/java/org/apache/lucene/search/LatLonPointPrototypeQueries.java @@ -106,6 +106,6 @@ public class LatLonPointPrototypeQueries { NearestNeighbor.NearestHit hit = hits[i]; scoreDocs[i] = new FieldDoc(hit.docID, 0.0f, new Object[] {Double.valueOf(hit.distanceMeters)}); } - return new TopFieldDocs(totalHits, scoreDocs, null); + return new TopFieldDocs(new TotalHits(totalHits, TotalHits.Relation.EQUAL_TO), scoreDocs, null); } } diff --git a/lucene/sandbox/src/test/org/apache/lucene/search/TestDocValuesNumbersQuery.java b/lucene/sandbox/src/test/org/apache/lucene/search/TestDocValuesNumbersQuery.java index 06c2d236e68..af077215312 100644 --- a/lucene/sandbox/src/test/org/apache/lucene/search/TestDocValuesNumbersQuery.java +++ b/lucene/sandbox/src/test/org/apache/lucene/search/TestDocValuesNumbersQuery.java @@ -176,7 +176,7 @@ public class TestDocValuesNumbersQuery extends LuceneTestCase { final int maxDoc = searcher.getIndexReader().maxDoc(); final TopDocs td1 = searcher.search(q1, maxDoc, scores ? Sort.RELEVANCE : Sort.INDEXORDER); final TopDocs td2 = searcher.search(q2, maxDoc, scores ? Sort.RELEVANCE : Sort.INDEXORDER); - assertEquals(td1.totalHits, td2.totalHits); + assertEquals(td1.totalHits.value, td2.totalHits.value); for (int i = 0; i < td1.scoreDocs.length; ++i) { assertEquals(td1.scoreDocs[i].doc, td2.scoreDocs[i].doc); if (scores) { diff --git a/lucene/sandbox/src/test/org/apache/lucene/search/TestDocValuesTermsQuery.java b/lucene/sandbox/src/test/org/apache/lucene/search/TestDocValuesTermsQuery.java index 187f172b9f9..04383fb70d9 100644 --- a/lucene/sandbox/src/test/org/apache/lucene/search/TestDocValuesTermsQuery.java +++ b/lucene/sandbox/src/test/org/apache/lucene/search/TestDocValuesTermsQuery.java @@ -173,7 +173,7 @@ public class TestDocValuesTermsQuery extends LuceneTestCase { final int maxDoc = searcher.getIndexReader().maxDoc(); final TopDocs td1 = searcher.search(q1, maxDoc, scores ? Sort.RELEVANCE : Sort.INDEXORDER); final TopDocs td2 = searcher.search(q2, maxDoc, scores ? Sort.RELEVANCE : Sort.INDEXORDER); - assertEquals(td1.totalHits, td2.totalHits); + assertEquals(td1.totalHits.value, td2.totalHits.value); for (int i = 0; i < td1.scoreDocs.length; ++i) { assertEquals(td1.scoreDocs[i].doc, td2.scoreDocs[i].doc); if (scores) { diff --git a/lucene/sandbox/src/test/org/apache/lucene/search/TestTermAutomatonQuery.java b/lucene/sandbox/src/test/org/apache/lucene/search/TestTermAutomatonQuery.java index d6bf90dfcbe..dab78f96f98 100644 --- a/lucene/sandbox/src/test/org/apache/lucene/search/TestTermAutomatonQuery.java +++ b/lucene/sandbox/src/test/org/apache/lucene/search/TestTermAutomatonQuery.java @@ -84,7 +84,7 @@ public class TestTermAutomatonQuery extends LuceneTestCase { q.addTransition(s2, s3, "sun"); q.finish(); - assertEquals(1, s.search(q, 1).totalHits); + assertEquals(1, s.search(q, 1).totalHits.value); w.close(); r.close(); @@ -117,7 +117,7 @@ public class TestTermAutomatonQuery extends LuceneTestCase { q.addTransition(s2, s3, "moon"); q.finish(); - assertEquals(2, s.search(q, 1).totalHits); + assertEquals(2, s.search(q, 1).totalHits.value); w.close(); r.close(); @@ -154,7 +154,7 @@ public class TestTermAutomatonQuery extends LuceneTestCase { q.addTransition(s2, s3, "sun"); q.finish(); - assertEquals(2, s.search(q, 1).totalHits); + assertEquals(2, s.search(q, 1).totalHits.value); w.close(); r.close(); @@ -210,7 +210,7 @@ public class TestTermAutomatonQuery extends LuceneTestCase { // System.out.println("DOT:\n" + q.toDot()); - assertEquals(4, s.search(q, 1).totalHits); + assertEquals(4, s.search(q, 1).totalHits.value); w.close(); r.close(); @@ -255,7 +255,7 @@ public class TestTermAutomatonQuery extends LuceneTestCase { TermAutomatonQuery q = new TokenStreamToTermAutomatonQuery().toQuery("field", ts); // System.out.println("DOT: " + q.toDot()); - assertEquals(4, s.search(q, 1).totalHits); + assertEquals(4, s.search(q, 1).totalHits.value); w.close(); r.close(); @@ -288,7 +288,7 @@ public class TestTermAutomatonQuery extends LuceneTestCase { q.addTransition(s2, s3, "moon"); q.finish(); - assertEquals(2, s.search(q, 1).totalHits); + assertEquals(2, s.search(q, 1).totalHits.value); w.close(); r.close(); dir.close(); @@ -353,7 +353,7 @@ public class TestTermAutomatonQuery extends LuceneTestCase { TermAutomatonQuery q = new TokenStreamToTermAutomatonQuery().toQuery("field", ts); // System.out.println("DOT: " + q.toDot()); - assertEquals(3, s.search(q, 1).totalHits); + assertEquals(3, s.search(q, 1).totalHits.value); w.close(); r.close(); @@ -542,7 +542,7 @@ public class TestTermAutomatonQuery extends LuceneTestCase { Set hits2Docs = toDocIDs(s, hits2); try { - assertEquals(hits2.totalHits, hits1.totalHits); + assertEquals(hits2.totalHits.value, hits1.totalHits.value); assertEquals(hits2Docs, hits1Docs); } catch (AssertionError ae) { System.out.println("FAILED:"); @@ -652,7 +652,7 @@ public class TestTermAutomatonQuery extends LuceneTestCase { q.setAccept(s1, true); q.finish(); - assertEquals(1, s.search(q, 1).totalHits); + assertEquals(1, s.search(q, 1).totalHits.value); w.close(); r.close(); dir.close(); @@ -687,7 +687,7 @@ public class TestTermAutomatonQuery extends LuceneTestCase { q.setAccept(s4, true); q.finish(); - assertEquals(1, s.search(q, 1).totalHits); + assertEquals(1, s.search(q, 1).totalHits.value); w.close(); r.close(); dir.close(); @@ -709,7 +709,7 @@ public class TestTermAutomatonQuery extends LuceneTestCase { TermAutomatonQuery q = new TokenStreamToTermAutomatonQuery().toQuery("field", ts); // System.out.println("DOT: " + q.toDot()); - assertEquals(0, s.search(q, 1).totalHits); + assertEquals(0, s.search(q, 1).totalHits.value); w.close(); r.close(); @@ -733,7 +733,7 @@ public class TestTermAutomatonQuery extends LuceneTestCase { TermAutomatonQuery q = new TokenStreamToTermAutomatonQuery().toQuery("field", ts); // System.out.println("DOT: " + q.toDot()); - assertEquals(0, s.search(q, 1).totalHits); + assertEquals(0, s.search(q, 1).totalHits.value); IOUtils.close(w, r, dir); } @@ -941,7 +941,7 @@ public class TestTermAutomatonQuery extends LuceneTestCase { q.addTransition(s2, s3, "moon"); q.finish(); - assertEquals(1, s.search(q, 1).totalHits); + assertEquals(1, s.search(q, 1).totalHits.value); w.close(); r.close(); @@ -971,7 +971,7 @@ public class TestTermAutomatonQuery extends LuceneTestCase { q.addTransition(s2, s3, "moon"); q.finish(); - assertEquals(0, s.search(q, 1).totalHits); + assertEquals(0, s.search(q, 1).totalHits.value); w.close(); r.close(); 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.java index ed4230f3721..3f1d3febc15 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 @@ -33,6 +33,7 @@ import org.apache.lucene.search.Query; import org.apache.lucene.search.Sort; import org.apache.lucene.search.SortField; import org.apache.lucene.search.TopDocs; +import org.apache.lucene.search.TotalHits.Relation; import org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy; import org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree; import org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree; @@ -190,7 +191,8 @@ public class SpatialExample extends LuceneTestCase { } private void assertDocMatchedIds(IndexSearcher indexSearcher, TopDocs docs, int... ids) throws IOException { - int[] gotIds = new int[Math.toIntExact(docs.totalHits)]; + assert docs.totalHits.relation == Relation.EQUAL_TO; + int[] gotIds = new int[Math.toIntExact(docs.totalHits.value)]; 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.java index 0b268d9f6e7..55ad1d7e466 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 @@ -113,7 +113,7 @@ public abstract class SpatialTestCase extends LuceneTestCase { for (ScoreDoc scoreDoc : topDocs.scoreDocs) { results.add(new SearchResult(scoreDoc.score, indexSearcher.doc(scoreDoc.doc))); } - return new SearchResults(topDocs.totalHits, results); + return new SearchResults(topDocs.totalHits.value, results); } catch (IOException ioe) { throw new RuntimeException("IOException thrown while executing query", ioe); } diff --git a/lucene/spatial-extras/src/test/org/apache/lucene/spatial/prefix/JtsPolygonTest.java b/lucene/spatial-extras/src/test/org/apache/lucene/spatial/prefix/JtsPolygonTest.java index 3f1684f58b5..7d029f10e97 100644 --- a/lucene/spatial-extras/src/test/org/apache/lucene/spatial/prefix/JtsPolygonTest.java +++ b/lucene/spatial-extras/src/test/org/apache/lucene/spatial/prefix/JtsPolygonTest.java @@ -111,7 +111,7 @@ public class JtsPolygonTest extends StrategyTestCase { System.out.println(indexSearcher.doc(scoreDoc.doc)); } - assertEquals(1, search.totalHits); + assertEquals(1, search.totalHits.value); } } diff --git a/lucene/spatial-extras/src/test/org/apache/lucene/spatial/prefix/tree/SpatialPrefixTreeTest.java b/lucene/spatial-extras/src/test/org/apache/lucene/spatial/prefix/tree/SpatialPrefixTreeTest.java index 8a3d79c3b29..cc63b5e17ca 100644 --- a/lucene/spatial-extras/src/test/org/apache/lucene/spatial/prefix/tree/SpatialPrefixTreeTest.java +++ b/lucene/spatial-extras/src/test/org/apache/lucene/spatial/prefix/tree/SpatialPrefixTreeTest.java @@ -108,7 +108,7 @@ public class SpatialPrefixTreeTest extends SpatialTestCase { System.out.println(indexSearcher.doc(scoreDoc.doc)); } - assertEquals(1, search.totalHits); + assertEquals(1, search.totalHits.value); } } \ No newline at end of file diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.java index 861e26ea0a1..7e26dfa40ed 100644 --- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.java +++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.java @@ -126,7 +126,7 @@ public class TestGeo3DPoint extends LuceneTestCase { // We can't wrap with "exotic" readers because the query must see the BKD3DDVFormat: IndexSearcher s = newSearcher(r, false); assertEquals(1, s.search(Geo3DPoint.newShapeQuery("field", - GeoCircleFactory.makeGeoCircle(PlanetModel.WGS84, toRadians(50), toRadians(-97), Math.PI/180.)), 1).totalHits); + GeoCircleFactory.makeGeoCircle(PlanetModel.WGS84, toRadians(50), toRadians(-97), Math.PI/180.)), 1).totalHits.value); w.close(); r.close(); dir.close(); diff --git a/lucene/suggest/src/java/org/apache/lucene/search/suggest/document/TopSuggestDocs.java b/lucene/suggest/src/java/org/apache/lucene/search/suggest/document/TopSuggestDocs.java index ec76ce02dab..f05e32a8b69 100644 --- a/lucene/suggest/src/java/org/apache/lucene/search/suggest/document/TopSuggestDocs.java +++ b/lucene/suggest/src/java/org/apache/lucene/search/suggest/document/TopSuggestDocs.java @@ -18,6 +18,7 @@ package org.apache.lucene.search.suggest.document; import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.TopDocs; +import org.apache.lucene.search.TotalHits; import org.apache.lucene.search.suggest.Lookup; /** @@ -31,7 +32,7 @@ public class TopSuggestDocs extends TopDocs { /** * Singleton for empty {@link TopSuggestDocs} */ - public final static TopSuggestDocs EMPTY = new TopSuggestDocs(0, new SuggestScoreDoc[0]); + public final static TopSuggestDocs EMPTY = new TopSuggestDocs(new TotalHits(0, TotalHits.Relation.EQUAL_TO), new SuggestScoreDoc[0]); /** * {@link org.apache.lucene.search.ScoreDoc} with an @@ -92,7 +93,7 @@ public class TopSuggestDocs extends TopDocs { * {@link TopSuggestDocs.SuggestScoreDoc} * instead of {@link org.apache.lucene.search.ScoreDoc} */ - public TopSuggestDocs(int totalHits, SuggestScoreDoc[] scoreDocs) { + public TopSuggestDocs(TotalHits totalHits, SuggestScoreDoc[] scoreDocs) { super(totalHits, scoreDocs); } @@ -124,7 +125,7 @@ public class TopSuggestDocs extends TopDocs { } SuggestScoreDoc[] topNResults = priorityQueue.getResults(); if (topNResults.length > 0) { - return new TopSuggestDocs(topNResults.length, topNResults); + return new TopSuggestDocs(new TotalHits(topNResults.length, TotalHits.Relation.EQUAL_TO), topNResults); } else { return TopSuggestDocs.EMPTY; } diff --git a/lucene/suggest/src/java/org/apache/lucene/search/suggest/document/TopSuggestDocsCollector.java b/lucene/suggest/src/java/org/apache/lucene/search/suggest/document/TopSuggestDocsCollector.java index 1eae0187294..ac79fa4d8b8 100644 --- a/lucene/suggest/src/java/org/apache/lucene/search/suggest/document/TopSuggestDocsCollector.java +++ b/lucene/suggest/src/java/org/apache/lucene/search/suggest/document/TopSuggestDocsCollector.java @@ -27,6 +27,7 @@ import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.search.CollectionTerminatedException; import org.apache.lucene.search.ScoreMode; import org.apache.lucene.search.SimpleCollector; +import org.apache.lucene.search.TotalHits; import static org.apache.lucene.search.suggest.document.TopSuggestDocs.SuggestScoreDoc; @@ -177,7 +178,7 @@ public class TopSuggestDocsCollector extends SimpleCollector { } if (suggestScoreDocs.length > 0) { - return new TopSuggestDocs(suggestScoreDocs.length, suggestScoreDocs); + return new TopSuggestDocs(new TotalHits(suggestScoreDocs.length, TotalHits.Relation.EQUAL_TO), suggestScoreDocs); } else { return TopSuggestDocs.EMPTY; } diff --git a/lucene/suggest/src/test/org/apache/lucene/search/suggest/document/TestPrefixCompletionQuery.java b/lucene/suggest/src/test/org/apache/lucene/search/suggest/document/TestPrefixCompletionQuery.java index 40de8f4167c..baf6d3d343a 100644 --- a/lucene/suggest/src/test/org/apache/lucene/search/suggest/document/TestPrefixCompletionQuery.java +++ b/lucene/suggest/src/test/org/apache/lucene/search/suggest/document/TestPrefixCompletionQuery.java @@ -190,7 +190,7 @@ public class TestPrefixCompletionQuery extends LuceneTestCase { // if at most half of the top scoring documents have been filtered out // the search should be admissible for a single segment TopSuggestDocs suggest = indexSearcher.suggest(query, num, false); - assertTrue(suggest.totalHits >= 1); + assertTrue(suggest.totalHits.value >= 1); assertThat(suggest.scoreLookupDocs()[0].key.toString(), equalTo("abc_" + topScore)); assertThat(suggest.scoreLookupDocs()[0].score, equalTo((float) topScore)); @@ -407,7 +407,7 @@ public class TestPrefixCompletionQuery extends LuceneTestCase { SuggestIndexSearcher indexSearcher = new SuggestIndexSearcher(reader); PrefixCompletionQuery query = new PrefixCompletionQuery(analyzer, new Term("suggest_field", "app")); - assertEquals(0, indexSearcher.suggest(query, 3, false).totalHits); + assertEquals(0, indexSearcher.suggest(query, 3, false).totalHits.value); query = new PrefixCompletionQuery(analyzer, new Term("suggest_field2", "app")); assertSuggestions(indexSearcher.suggest(query, 3, false), new Entry("apples", 3)); 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.java index e6d7062c925..2bb4f7170ff 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 @@ -130,7 +130,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(0L)); + assertThat(lookupDocs.totalHits.value, equalTo(0L)); reader.close(); iw.close(); } @@ -474,7 +474,7 @@ public class TestSuggestField extends LuceneTestCase { // calling suggest with filter that does not match any documents should early terminate PrefixCompletionQuery query = new PrefixCompletionQuery(analyzer, new Term("suggest_field", "abc_"), filter); TopSuggestDocs suggest = indexSearcher.suggest(query, num, false); - assertThat(suggest.totalHits, equalTo(0L)); + assertThat(suggest.totalHits.value, equalTo(0L)); reader.close(); iw.close(); } @@ -502,7 +502,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(0L)); + assertThat(suggest.totalHits.value, equalTo(0L)); reader.close(); iw.close(); @@ -656,7 +656,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); - assertEquals(num, suggest.totalHits); + assertEquals(num, suggest.totalHits.value); for (SuggestScoreDoc suggestScoreDoc : suggest.scoreLookupDocs()) { String key = suggestScoreDoc.key.toString(); assertTrue(key.startsWith("abc_")); @@ -696,7 +696,7 @@ public class TestSuggestField extends LuceneTestCase { for (String prefix : prefixes) { PrefixCompletionQuery query = new PrefixCompletionQuery(analyzer, new Term("suggest_field", prefix)); TopSuggestDocs suggest = indexSearcher.suggest(query, num, false); - assertTrue(suggest.totalHits > 0); + assertTrue(suggest.totalHits.value > 0); float topScore = -1; for (SuggestScoreDoc scoreDoc : suggest.scoreLookupDocs()) { if (topScore != -1) { @@ -747,7 +747,7 @@ public class TestSuggestField extends LuceneTestCase { PrefixCompletionQuery query = new PrefixCompletionQuery(analyzer, new Term("suggest_field", title)); TopSuggestDocs suggest = indexSearcher.suggest(query, mappings.size(), false); - assertTrue(suggest.totalHits > 0); + assertTrue(suggest.totalHits.value > 0); boolean matched = false; for (ScoreDoc scoreDoc : suggest.scoreDocs) { matched = Float.compare(scoreDoc.score, (float) entry.getValue()) == 0; diff --git a/lucene/test-framework/src/java/org/apache/lucene/geo/BaseGeoPointTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/geo/BaseGeoPointTestCase.java index ea62178bdd1..3334344f4b5 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/geo/BaseGeoPointTestCase.java +++ b/lucene/test-framework/src/java/org/apache/lucene/geo/BaseGeoPointTestCase.java @@ -1431,23 +1431,23 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase { public void testSmallSetRect() throws Exception { TopDocs td = searchSmallSet(newRectQuery("point", 32.778, 32.779, -96.778, -96.777), 5); - assertEquals(4, td.totalHits); + assertEquals(4, td.totalHits.value); } public void testSmallSetDateline() throws Exception { TopDocs td = searchSmallSet(newRectQuery("point", -45.0, -44.0, 179.0, -179.0), 20); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); } public void testSmallSetMultiValued() throws Exception { TopDocs td = searchSmallSet(newRectQuery("point", 32.755, 32.776, -96.454, -96.770), 20); // 3 single valued docs + 2 multi-valued docs - assertEquals(5, td.totalHits); + assertEquals(5, td.totalHits.value); } public void testSmallSetWholeMap() throws Exception { TopDocs td = searchSmallSet(newRectQuery("point", GeoUtils.MIN_LAT_INCL, GeoUtils.MAX_LAT_INCL, GeoUtils.MIN_LON_INCL, GeoUtils.MAX_LON_INCL), 20); - assertEquals(24, td.totalHits); + assertEquals(24, td.totalHits.value); } public void testSmallSetPoly() throws Exception { @@ -1459,7 +1459,7 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase { new double[]{-96.7682647, -96.8280029, -96.6288757, -96.4929199, -96.6041564, -96.7449188, -96.76826477, -96.7682647})), 5); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); } public void testSmallSetPolyWholeMap() throws Exception { @@ -1469,23 +1469,23 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase { new double[] {GeoUtils.MIN_LAT_INCL, GeoUtils.MAX_LAT_INCL, GeoUtils.MAX_LAT_INCL, GeoUtils.MIN_LAT_INCL, GeoUtils.MIN_LAT_INCL}, new double[] {GeoUtils.MIN_LON_INCL, GeoUtils.MIN_LON_INCL, GeoUtils.MAX_LON_INCL, GeoUtils.MAX_LON_INCL, GeoUtils.MIN_LON_INCL})), 20); - assertEquals("testWholeMap failed", 24, td.totalHits); + assertEquals("testWholeMap failed", 24, td.totalHits.value); } public void testSmallSetDistance() throws Exception { TopDocs td = searchSmallSet(newDistanceQuery("point", 32.94823588839368, -96.4538113027811, 6000), 20); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); } public void testSmallSetTinyDistance() throws Exception { TopDocs td = searchSmallSet(newDistanceQuery("point", 40.720611, -73.998776, 1), 20); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); } /** see https://issues.apache.org/jira/browse/LUCENE-6905 */ public void testSmallSetDistanceNotEmpty() throws Exception { TopDocs td = searchSmallSet(newDistanceQuery("point", -88.56029371730983, -177.23537676036358, 7757.999232959935), 20); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); } /** @@ -1493,11 +1493,11 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase { */ public void testSmallSetHugeDistance() throws Exception { TopDocs td = searchSmallSet(newDistanceQuery("point", 32.94823588839368, -96.4538113027811, 6000000), 20); - assertEquals(16, td.totalHits); + assertEquals(16, td.totalHits.value); } public void testSmallSetDistanceDateline() throws Exception { TopDocs td = searchSmallSet(newDistanceQuery("point", 32.94823588839368, -179.9538113027811, 120000), 20); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); } } diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/BaseDocValuesFormatTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/index/BaseDocValuesFormatTestCase.java index 7b902e389e9..bd11b47d48e 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/index/BaseDocValuesFormatTestCase.java +++ b/lucene/test-framework/src/java/org/apache/lucene/index/BaseDocValuesFormatTestCase.java @@ -118,7 +118,7 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes assertEquals(1, isearcher.count(new TermQuery(new Term("fieldname", longTerm)))); Query query = new TermQuery(new Term("fieldname", "text")); TopDocs hits = isearcher.search(query, 1); - assertEquals(1, hits.totalHits); + assertEquals(1, hits.totalHits.value); // Iterate through the results: for (int i = 0; i < hits.scoreDocs.length; i++) { Document hitDoc = isearcher.doc(hits.scoreDocs[i].doc); @@ -152,7 +152,7 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes assertEquals(1, isearcher.count(new TermQuery(new Term("fieldname", longTerm)))); Query query = new TermQuery(new Term("fieldname", "text")); TopDocs hits = isearcher.search(query, 1); - assertEquals(1, hits.totalHits); + assertEquals(1, hits.totalHits.value); // Iterate through the results: for (int i = 0; i < hits.scoreDocs.length; i++) { int docID = hits.scoreDocs[i].doc; @@ -188,7 +188,7 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes assertEquals(1, isearcher.count(new TermQuery(new Term("fieldname", longTerm)))); Query query = new TermQuery(new Term("fieldname", "text")); TopDocs hits = isearcher.search(query, 1); - assertEquals(1, hits.totalHits); + assertEquals(1, hits.totalHits.value); // Iterate through the results: for (int i = 0; i < hits.scoreDocs.length; i++) { int docID = hits.scoreDocs[i].doc; @@ -226,7 +226,7 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes assertEquals(1, isearcher.count(new TermQuery(new Term("fieldname", longTerm)))); Query query = new TermQuery(new Term("fieldname", "text")); TopDocs hits = isearcher.search(query, 1); - assertEquals(1, hits.totalHits); + assertEquals(1, hits.totalHits.value); // Iterate through the results: for (int i = 0; i < hits.scoreDocs.length; i++) { int hitDocID = hits.scoreDocs[i].doc; @@ -266,7 +266,7 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes assertEquals(1, isearcher.count(new TermQuery(new Term("fieldname", longTerm)))); Query query = new TermQuery(new Term("fieldname", "text")); TopDocs hits = isearcher.search(query, 1); - assertEquals(1, hits.totalHits); + assertEquals(1, hits.totalHits.value); // Iterate through the results: for (int i = 0; i < hits.scoreDocs.length; i++) { int docID = hits.scoreDocs[i].doc; @@ -305,7 +305,7 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes assertEquals(1, isearcher.count(new TermQuery(new Term("fieldname", longTerm)))); Query query = new TermQuery(new Term("fieldname", "text")); TopDocs hits = isearcher.search(query, 1); - assertEquals(1, hits.totalHits); + assertEquals(1, hits.totalHits.value); // Iterate through the results: for (int i = 0; i < hits.scoreDocs.length; i++) { int docID = hits.scoreDocs[i].doc; @@ -349,7 +349,7 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes assertEquals(1, isearcher.count(new TermQuery(new Term("fieldname", longTerm)))); Query query = new TermQuery(new Term("fieldname", "text")); TopDocs hits = isearcher.search(query, 1); - assertEquals(1, hits.totalHits); + assertEquals(1, hits.totalHits.value); BytesRef scratch = new BytesRef(); // Iterate through the results: for (int i = 0; i < hits.scoreDocs.length; i++) { @@ -521,7 +521,7 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes assertEquals(1, isearcher.count(new TermQuery(new Term("fieldname", longTerm)))); Query query = new TermQuery(new Term("fieldname", "text")); TopDocs hits = isearcher.search(query, 1); - assertEquals(1, hits.totalHits); + assertEquals(1, hits.totalHits.value); // Iterate through the results: for (int i = 0; i < hits.scoreDocs.length; i++) { int hitDocID = hits.scoreDocs[i].doc; @@ -625,7 +625,7 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes assertEquals(1, isearcher.count(new TermQuery(new Term("fieldname", longTerm)))); Query query = new TermQuery(new Term("fieldname", "text")); TopDocs hits = isearcher.search(query, 1); - assertEquals(1, hits.totalHits); + assertEquals(1, hits.totalHits.value); BytesRef scratch = new BytesRef(); // Iterate through the results: for (int i = 0; i < hits.scoreDocs.length; i++) { @@ -1119,7 +1119,7 @@ public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTes query.add(new TermQuery(new Term("docId", "4")), BooleanClause.Occur.SHOULD); TopDocs search = searcher.search(query.build(), 10); - assertEquals(5, search.totalHits); + assertEquals(5, search.totalHits.value); ScoreDoc[] scoreDocs = search.scoreDocs; NumericDocValues docValues = getOnlyLeafReader(reader).getNumericDocValues("docId"); for (int i = 0; i < scoreDocs.length; i++) { diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/BaseStoredFieldsFormatTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/index/BaseStoredFieldsFormatTestCase.java index 82d8adb08e4..242abf73684 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/index/BaseStoredFieldsFormatTestCase.java +++ b/lucene/test-framework/src/java/org/apache/lucene/index/BaseStoredFieldsFormatTestCase.java @@ -154,7 +154,7 @@ public abstract class BaseStoredFieldsFormatTestCase extends BaseIndexFileFormat System.out.println("TEST: test id=" + testID); } TopDocs hits = s.search(new TermQuery(new Term("id", testID)), 1); - assertEquals(1, hits.totalHits); + assertEquals(1, hits.totalHits.value); Document doc = r.document(hits.scoreDocs[0].doc); Document docExp = docs.get(testID); for(int i=0;i " + td2.totalHits, td1.totalHits <= td2.totalHits); + assertTrue("too many hits: " + td1.totalHits.value + " > " + td2.totalHits.value, td1.totalHits.value <= td2.totalHits.value); // fill the superset into a bitset BitSet bitset = new BitSet(); @@ -250,7 +250,7 @@ public abstract class SearchEquivalenceTestBase extends LuceneTestCase { } TopDocs td1 = s1.search(q1, reader.maxDoc()); TopDocs td2 = s2.search(q2, reader.maxDoc()); - assertEquals(td1.totalHits, td2.totalHits); + assertEquals(td1.totalHits.value, td2.totalHits.value); for (int i = 0; i < td1.scoreDocs.length; ++i) { assertEquals(td1.scoreDocs[i].doc, td2.scoreDocs[i].doc); assertEquals(td1.scoreDocs[i].score, td2.scoreDocs[i].score, 10e-5); diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java b/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java index 537731e7054..bc31b4443a3 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java +++ b/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java @@ -1041,7 +1041,8 @@ public final class TestUtil { } public static void assertEquals(TopDocs expected, TopDocs actual) { - Assert.assertEquals("wrong total hits", expected.totalHits, actual.totalHits); + Assert.assertEquals("wrong total hits", expected.totalHits.value, actual.totalHits.value); + Assert.assertEquals("wrong total hits", expected.totalHits.relation, actual.totalHits.relation); Assert.assertEquals("wrong hit count", expected.scoreDocs.length, actual.scoreDocs.length); for(int hitIDX=0;hitIDX actualValues = new ArrayList(); for (int index = 0; index < values.length; ++index) { Document doc = searcher.doc(result.scoreDocs[index].doc); 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.java index 8b8159e0e97..5412715518e 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 @@ -29,6 +29,7 @@ import org.apache.lucene.search.Rescorer; import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.ScoreMode; import org.apache.lucene.search.TopDocs; +import org.apache.lucene.search.TotalHits; import org.apache.lucene.search.Weight; import org.apache.solr.search.SolrIndexSearcher; @@ -100,7 +101,7 @@ public class LTRRescorer extends Rescorer { @Override public TopDocs rescore(IndexSearcher searcher, TopDocs firstPassTopDocs, int topN) throws IOException { - if ((topN == 0) || (firstPassTopDocs.totalHits == 0)) { + if ((topN == 0) || (firstPassTopDocs.scoreDocs.length == 0)) { return firstPassTopDocs; } final ScoreDoc[] hits = firstPassTopDocs.scoreDocs; @@ -111,7 +112,8 @@ public class LTRRescorer extends Rescorer { } }); - topN = Math.toIntExact(Math.min(topN, firstPassTopDocs.totalHits)); + assert firstPassTopDocs.totalHits.relation == TotalHits.Relation.EQUAL_TO; + topN = Math.toIntExact(Math.min(topN, firstPassTopDocs.totalHits.value)); final ScoreDoc[] reranked = new ScoreDoc[topN]; final List leaves = searcher.getIndexReader().leaves(); final LTRScoringQuery.ModelWeight modelWeight = (LTRScoringQuery.ModelWeight) searcher diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRReRankingPipeline.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRReRankingPipeline.java index 89067e9ae72..a847fe79ab6 100644 --- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRReRankingPipeline.java +++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRReRankingPipeline.java @@ -137,7 +137,7 @@ public class TestLTRReRankingPipeline extends LuceneTestCase { final IndexSearcher searcher = getSearcher(r); // first run the standard query TopDocs hits = searcher.search(bqBuilder.build(), 10); - assertEquals(2, hits.totalHits); + assertEquals(2, hits.totalHits.value); assertEquals("0", searcher.doc(hits.scoreDocs[0].doc).get("id")); assertEquals("1", searcher.doc(hits.scoreDocs[1].doc).get("id")); @@ -209,7 +209,7 @@ public class TestLTRReRankingPipeline extends LuceneTestCase { // first run the standard query TopDocs hits = searcher.search(bqBuilder.build(), 10); - assertEquals(5, hits.totalHits); + assertEquals(5, hits.totalHits.value); assertEquals("0", searcher.doc(hits.scoreDocs[0].doc).get("id")); assertEquals("1", searcher.doc(hits.scoreDocs[1].doc).get("id")); diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRScoringQuery.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRScoringQuery.java index 27978946b28..e9e44114357 100644 --- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRScoringQuery.java +++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRScoringQuery.java @@ -201,7 +201,7 @@ public class TestLTRScoringQuery extends LuceneTestCase { final IndexSearcher searcher = getSearcher(r); // first run the standard query final TopDocs hits = searcher.search(bqBuilder.build(), 10); - assertEquals(2, hits.totalHits); + assertEquals(2, hits.totalHits.value); assertEquals("0", searcher.doc(hits.scoreDocs[0].doc).get("id")); assertEquals("1", searcher.doc(hits.scoreDocs[1].doc).get("id")); diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestSelectiveWeightCreation.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestSelectiveWeightCreation.java index 3591ce23569..d98addab173 100644 --- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestSelectiveWeightCreation.java +++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestSelectiveWeightCreation.java @@ -144,7 +144,7 @@ public class TestSelectiveWeightCreation extends TestRerankBase { final IndexSearcher searcher = getSearcher(r); // first run the standard query final TopDocs hits = searcher.search(bqBuilder.build(), 10); - assertEquals(2, hits.totalHits); + assertEquals(2, hits.totalHits.value); assertEquals("10", searcher.doc(hits.scoreDocs[0].doc).get("id")); assertEquals("11", searcher.doc(hits.scoreDocs[1].doc).get("id")); diff --git a/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java b/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java index 5ee5bdd2c5f..8d7012a1387 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java +++ b/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java @@ -437,7 +437,7 @@ final class ShardLeaderElectionContext extends ShardLeaderElectionContextBase { SolrIndexSearcher searcher = searchHolder.get(); try { log.debug(core.getCoreContainer().getZkController().getNodeName() + " synched " - + searcher.search(new MatchAllDocsQuery(), 1).totalHits); + + searcher.count(new MatchAllDocsQuery())); } finally { searchHolder.decref(); } diff --git a/solr/core/src/java/org/apache/solr/handler/BlobHandler.java b/solr/core/src/java/org/apache/solr/handler/BlobHandler.java index 30301c0a46e..ee3adaee52a 100644 --- a/solr/core/src/java/org/apache/solr/handler/BlobHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/BlobHandler.java @@ -116,8 +116,8 @@ public class BlobHandler extends RequestHandlerBase implements PluginInfoInitial m.update(payload.array(), payload.position(), payload.limit()); String md5 = new BigInteger(1, m.digest()).toString(16); - TopDocs duplicate = req.getSearcher().search(new TermQuery(new Term("md5", md5)), 1); - if (duplicate.totalHits > 0) { + int duplicateCount = req.getSearcher().count(new TermQuery(new Term("md5", md5))); + if (duplicateCount > 0) { rsp.add("error", "duplicate entry"); forward(req, null, new MapSolrParams((Map) makeMap( @@ -132,7 +132,7 @@ public class BlobHandler extends RequestHandlerBase implements PluginInfoInitial 1, new Sort(new SortField("version", SortField.Type.LONG, true))); long version = 0; - if (docs.totalHits > 0) { + if (docs.totalHits.value > 0) { Document doc = req.getSearcher().doc(docs.scoreDocs[0].doc); Number n = doc.getField("version").numericValue(); version = n.longValue(); @@ -175,7 +175,7 @@ public class BlobHandler extends RequestHandlerBase implements PluginInfoInitial if (version != -1) q = "id:{0}/{1}"; QParser qparser = QParser.getParser(StrUtils.formatString(q, blobName, version), req); final TopDocs docs = req.getSearcher().search(qparser.parse(), 1, new Sort(new SortField("version", SortField.Type.LONG, true))); - if (docs.totalHits > 0) { + if (docs.totalHits.value > 0) { rsp.add(ReplicationHandler.FILE_STREAM, new SolrCore.RawWriter() { @Override diff --git a/solr/core/src/java/org/apache/solr/handler/admin/RequestSyncShardOp.java b/solr/core/src/java/org/apache/solr/handler/admin/RequestSyncShardOp.java index a4216516a26..55eb70a34ad 100644 --- a/solr/core/src/java/org/apache/solr/handler/admin/RequestSyncShardOp.java +++ b/solr/core/src/java/org/apache/solr/handler/admin/RequestSyncShardOp.java @@ -74,7 +74,7 @@ class RequestSyncShardOp implements CoreAdminHandler.CoreAdminOp { log.debug(core.getCoreContainer() .getZkController().getNodeName() + " synched " - + searcher.search(new MatchAllDocsQuery(), 1).totalHits); + + searcher.count(new MatchAllDocsQuery())); } finally { searchHolder.decref(); } diff --git a/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java b/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java index 1354ea8e04e..5b5add911f5 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java +++ b/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java @@ -59,6 +59,7 @@ import org.apache.lucene.search.TopDocs; import org.apache.lucene.search.TopDocsCollector; import org.apache.lucene.search.TopFieldCollector; import org.apache.lucene.search.TopScoreDocCollector; +import org.apache.lucene.search.TotalHits; import org.apache.lucene.util.BitSetIterator; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRefBuilder; @@ -437,7 +438,8 @@ public class ExpandComponent extends SearchComponent implements PluginInfoInitia docs[i] = scoreDoc.doc; scores[i] = scoreDoc.score; } - DocSlice slice = new DocSlice(0, docs.length, docs, scores, topDocs.totalHits, Float.NaN); + assert topDocs.totalHits.relation == TotalHits.Relation.EQUAL_TO; + DocSlice slice = new DocSlice(0, docs.length, docs, scores, topDocs.totalHits.value, Float.NaN); if(fieldType instanceof StrField) { final BytesRef bytesRef = ordBytes.get((int)groupValue); diff --git a/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java b/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java index ff3cdbf1c5b..6ca8ad121cb 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java +++ b/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java @@ -161,7 +161,7 @@ public class RealTimeGetComponent extends SearchComponent log.debug(req.getCore() .getCoreContainer().getZkController().getNodeName() + " min count to sync to (from most recent searcher view) " - + searcher.search(new MatchAllDocsQuery(), 1).totalHits); + + searcher.count(new MatchAllDocsQuery())); } finally { searchHolder.decref(); } diff --git a/solr/core/src/java/org/apache/solr/search/ExportQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/ExportQParserPlugin.java index 64464d4bb56..e52220d2ada 100644 --- a/solr/core/src/java/org/apache/solr/search/ExportQParserPlugin.java +++ b/solr/core/src/java/org/apache/solr/search/ExportQParserPlugin.java @@ -30,6 +30,7 @@ import org.apache.lucene.search.ScoreMode; import org.apache.lucene.search.Scorer; import org.apache.lucene.search.TopDocs; import org.apache.lucene.search.TopDocsCollector; +import org.apache.lucene.search.TotalHits; import org.apache.lucene.search.Weight; import org.apache.lucene.util.FixedBitSet; import org.apache.solr.common.params.SolrParams; @@ -180,7 +181,7 @@ public class ExportQParserPlugin extends QParserPlugin { ScoreDoc[] scoreDocs = getScoreDocs(howMany); assert scoreDocs.length <= totalHits; - return new TopDocs(totalHits, scoreDocs); + return new TopDocs(new TotalHits(totalHits, totalHitsRelation), scoreDocs); } @Override diff --git a/solr/core/src/java/org/apache/solr/search/Grouping.java b/solr/core/src/java/org/apache/solr/search/Grouping.java index cb7dccd26ac..6f40e7291ce 100644 --- a/solr/core/src/java/org/apache/solr/search/Grouping.java +++ b/solr/core/src/java/org/apache/solr/search/Grouping.java @@ -46,6 +46,7 @@ import org.apache.lucene.search.TopDocsCollector; import org.apache.lucene.search.TopFieldCollector; import org.apache.lucene.search.TopScoreDocCollector; import org.apache.lucene.search.TotalHitCountCollector; +import org.apache.lucene.search.TotalHits; import org.apache.lucene.search.grouping.AllGroupHeadsCollector; import org.apache.lucene.search.grouping.AllGroupsCollector; import org.apache.lucene.search.grouping.FirstPassGroupingCollector; @@ -613,7 +614,8 @@ public class Grouping { } protected DocList getDocList(GroupDocs groups) { - int max = Math.toIntExact(groups.totalHits); + assert groups.totalHits.relation == TotalHits.Relation.EQUAL_TO; + int max = Math.toIntExact(groups.totalHits.value); int off = groupOffset; int len = docsPerGroup; if (format == Format.simple) { @@ -635,7 +637,7 @@ public class Grouping { float score = groups.maxScore; maxScore = maxAvoidNaN(score, maxScore); - DocSlice docs = new DocSlice(off, Math.max(0, ids.length - off), ids, scores, groups.totalHits, score); + DocSlice docs = new DocSlice(off, Math.max(0, ids.length - off), ids, scores, groups.totalHits.value, score); if (getDocList) { DocIterator iter = docs.iterator(); diff --git a/solr/core/src/java/org/apache/solr/search/ReRankCollector.java b/solr/core/src/java/org/apache/solr/search/ReRankCollector.java index 0888f79c900..ffadb6e7075 100644 --- a/solr/core/src/java/org/apache/solr/search/ReRankCollector.java +++ b/solr/core/src/java/org/apache/solr/search/ReRankCollector.java @@ -98,7 +98,7 @@ public class ReRankCollector extends TopDocsCollector { TopDocs mainDocs = mainCollector.topDocs(0, Math.max(reRankDocs, length)); - if(mainDocs.totalHits == 0 || mainDocs.scoreDocs.length == 0) { + if(mainDocs.totalHits.value == 0 || mainDocs.scoreDocs.length == 0) { return mainDocs; } diff --git a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java index 6cbcd0d6843..343d7c40f7f 100644 --- a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java +++ b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java @@ -2064,7 +2064,8 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable, SolrI ids[i] = scoreDoc.doc; } - qr.getDocListAndSet().docList = new DocSlice(0, nDocsReturned, ids, null, topDocs.totalHits, 0.0f); + assert topDocs.totalHits.relation == TotalHits.Relation.EQUAL_TO; + qr.getDocListAndSet().docList = new DocSlice(0, nDocsReturned, ids, null, topDocs.totalHits.value, 0.0f); populateNextCursorMarkFromTopDocs(qr, cmd, topDocs); } 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.java index a5ce1fffe68..3327dd7cf44 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 @@ -30,6 +30,7 @@ import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.Sort; import org.apache.lucene.search.TopDocs; import org.apache.lucene.search.TopFieldDocs; +import org.apache.lucene.search.TotalHits; import org.apache.lucene.search.grouping.GroupDocs; import org.apache.lucene.search.grouping.TopGroups; import org.apache.lucene.util.BytesRef; @@ -108,9 +109,9 @@ public class TopGroupsResultTransformer implements ShardResultTransformer(Float.NaN, maxScore, totalGroupHits.longValue(), scoreDocs, groupValueRef, null)); + groupDocs.add(new GroupDocs<>(Float.NaN, maxScore, new TotalHits(totalGroupHits.longValue(), TotalHits.Relation.EQUAL_TO), scoreDocs, groupValueRef, null)); } @SuppressWarnings("unchecked") @@ -193,7 +194,8 @@ public class TopGroupsResultTransformer implements ShardResultTransformer searchGroup : data.groups) { NamedList groupResult = new NamedList<>(); - groupResult.add("totalHits", searchGroup.totalHits); + assert searchGroup.totalHits.relation == TotalHits.Relation.EQUAL_TO; + groupResult.add("totalHits", searchGroup.totalHits.value); if (!Float.isNaN(searchGroup.maxScore)) { groupResult.add("maxScore", searchGroup.maxScore); } @@ -240,7 +242,9 @@ public class TopGroupsResultTransformer implements ShardResultTransformer queryResult = new NamedList<>(); queryResult.add("matches", result.getMatches()); - queryResult.add("totalHits", result.getTopDocs().totalHits); + TopDocs topDocs = result.getTopDocs(); + assert topDocs.totalHits.relation == TotalHits.Relation.EQUAL_TO; + queryResult.add("totalHits", topDocs.totalHits.value); // debug: assert !Float.isNaN(result.getTopDocs().getMaxScore()) == rb.getGroupingSpec().isNeedScore(); if (!Float.isNaN(result.getMaxScore())) { queryResult.add("maxScore", result.getMaxScore()); diff --git a/solr/core/src/java/org/apache/solr/search/grouping/endresulttransformer/GroupedEndResultTransformer.java b/solr/core/src/java/org/apache/solr/search/grouping/endresulttransformer/GroupedEndResultTransformer.java index 6c9372cfbe8..485f724f74c 100644 --- a/solr/core/src/java/org/apache/solr/search/grouping/endresulttransformer/GroupedEndResultTransformer.java +++ b/solr/core/src/java/org/apache/solr/search/grouping/endresulttransformer/GroupedEndResultTransformer.java @@ -17,6 +17,8 @@ package org.apache.solr.search.grouping.endresulttransformer; import org.apache.lucene.search.ScoreDoc; +import org.apache.lucene.search.TopDocs; +import org.apache.lucene.search.TotalHits; import org.apache.lucene.search.grouping.GroupDocs; import org.apache.lucene.search.grouping.TopGroups; import org.apache.lucene.util.BytesRef; @@ -72,7 +74,8 @@ public class GroupedEndResultTransformer implements EndResultTransformer { groupResult.add("groupValue", null); } SolrDocumentList docList = new SolrDocumentList(); - docList.setNumFound(group.totalHits); + assert group.totalHits.relation == TotalHits.Relation.EQUAL_TO; + docList.setNumFound(group.totalHits.value); if (!Float.isNaN(group.maxScore)) { docList.setMaxScore(group.maxScore); } @@ -90,7 +93,9 @@ public class GroupedEndResultTransformer implements EndResultTransformer { NamedList command = new SimpleOrderedMap<>(); command.add("matches", queryCommandResult.getMatches()); SolrDocumentList docList = new SolrDocumentList(); - docList.setNumFound(queryCommandResult.getTopDocs().totalHits); + TopDocs topDocs = queryCommandResult.getTopDocs(); + assert topDocs.totalHits.relation == TotalHits.Relation.EQUAL_TO; + docList.setNumFound(topDocs.totalHits.value); if (!Float.isNaN(queryCommandResult.getMaxScore())) { docList.setMaxScore(queryCommandResult.getMaxScore()); } diff --git a/solr/core/src/java/org/apache/solr/search/mlt/SimpleMLTQParser.java b/solr/core/src/java/org/apache/solr/search/mlt/SimpleMLTQParser.java index 4a3400b70f0..451c6210284 100644 --- a/solr/core/src/java/org/apache/solr/search/mlt/SimpleMLTQParser.java +++ b/solr/core/src/java/org/apache/solr/search/mlt/SimpleMLTQParser.java @@ -63,8 +63,8 @@ public class SimpleMLTQParser extends QParser { Map boostFields = new HashMap<>(); try { - TopDocs td = searcher.search(docIdQuery, 1); - if (td.totalHits != 1) throw new SolrException( + TopDocs td = searcher.search(docIdQuery, 2); + if (td.totalHits.value != 1) throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "Error completing MLT request. Could not fetch " + "document with id [" + uniqueValue + "]"); ScoreDoc[] scoreDocs = td.scoreDocs; diff --git a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java index a51360639ac..11d35e7b4e9 100644 --- a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java +++ b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java @@ -146,7 +146,7 @@ public class TestReplicationHandlerBackup extends SolrJettyTestBase { IndexReader reader = DirectoryReader.open(dir)) { IndexSearcher searcher = new IndexSearcher(reader); TopDocs hits = searcher.search(new MatchAllDocsQuery(), 1); - assertEquals(nDocs, hits.totalHits); + assertEquals(nDocs, hits.totalHits.value); } } diff --git a/solr/core/src/test/org/apache/solr/legacy/TestMultiValuedNumericRangeQuery.java b/solr/core/src/test/org/apache/solr/legacy/TestMultiValuedNumericRangeQuery.java index 80b15245c0b..5c6392da927 100644 --- a/solr/core/src/test/org/apache/solr/legacy/TestMultiValuedNumericRangeQuery.java +++ b/solr/core/src/test/org/apache/solr/legacy/TestMultiValuedNumericRangeQuery.java @@ -75,7 +75,7 @@ public class TestMultiValuedNumericRangeQuery extends LuceneTestCase { LegacyNumericRangeQuery tq= LegacyNumericRangeQuery.newIntRange("trie", lower, upper, true, true); TopDocs trTopDocs = searcher.search(cq, 1); TopDocs nrTopDocs = searcher.search(tq, 1); - assertEquals("Returned count for LegacyNumericRangeQuery and TermRangeQuery must be equal", trTopDocs.totalHits, nrTopDocs.totalHits ); + assertEquals("Returned count for LegacyNumericRangeQuery and TermRangeQuery must be equal", trTopDocs.totalHits.value, nrTopDocs.totalHits.value ); } reader.close(); directory.close(); diff --git a/solr/core/src/test/org/apache/solr/legacy/TestNumericRangeQuery32.java b/solr/core/src/test/org/apache/solr/legacy/TestNumericRangeQuery32.java index 5c029137a7a..74ce2fe364a 100644 --- a/solr/core/src/test/org/apache/solr/legacy/TestNumericRangeQuery32.java +++ b/solr/core/src/test/org/apache/solr/legacy/TestNumericRangeQuery32.java @@ -361,19 +361,19 @@ public class TestNumericRangeQuery32 extends LuceneTestCase { // test inclusive range Query tq= LegacyNumericRangeQuery.newIntRange(field, precisionStep, lower, upper, true, true); TopDocs tTopDocs = searcher.search(tq, 1); - assertEquals("Returned count of range query must be equal to inclusive range length", upper-lower+1, tTopDocs.totalHits ); + assertEquals("Returned count of range query must be equal to inclusive range length", upper-lower+1, tTopDocs.totalHits.value ); // test exclusive range tq= LegacyNumericRangeQuery.newIntRange(field, precisionStep, lower, upper, false, false); tTopDocs = searcher.search(tq, 1); - assertEquals("Returned count of range query must be equal to exclusive range length", Math.max(upper-lower-1, 0), tTopDocs.totalHits ); + assertEquals("Returned count of range query must be equal to exclusive range length", Math.max(upper-lower-1, 0), tTopDocs.totalHits.value ); // test left exclusive range tq= LegacyNumericRangeQuery.newIntRange(field, precisionStep, lower, upper, false, true); tTopDocs = searcher.search(tq, 1); - assertEquals("Returned count of range query must be equal to half exclusive range length", upper-lower, tTopDocs.totalHits ); + assertEquals("Returned count of range query must be equal to half exclusive range length", upper-lower, tTopDocs.totalHits.value ); // test right exclusive range tq= LegacyNumericRangeQuery.newIntRange(field, precisionStep, lower, upper, true, false); tTopDocs = searcher.search(tq, 1); - assertEquals("Returned count of range query must be equal to half exclusive range length", upper-lower, tTopDocs.totalHits ); + assertEquals("Returned count of range query must be equal to half exclusive range length", upper-lower, tTopDocs.totalHits.value ); } } @@ -400,7 +400,7 @@ public class TestNumericRangeQuery32 extends LuceneTestCase { Query tq= LegacyNumericRangeQuery.newFloatRange(field, precisionStep, NumericUtils.sortableIntToFloat(lower), NumericUtils.sortableIntToFloat(upper), true, true); TopDocs tTopDocs = searcher.search(tq, 1); - assertEquals("Returned count of range query must be equal to inclusive range length", upper-lower+1, tTopDocs.totalHits ); + assertEquals("Returned count of range query must be equal to inclusive range length", upper-lower+1, tTopDocs.totalHits.value ); } @Test diff --git a/solr/core/src/test/org/apache/solr/legacy/TestNumericRangeQuery64.java b/solr/core/src/test/org/apache/solr/legacy/TestNumericRangeQuery64.java index 99d4261def4..59db2ebec4f 100644 --- a/solr/core/src/test/org/apache/solr/legacy/TestNumericRangeQuery64.java +++ b/solr/core/src/test/org/apache/solr/legacy/TestNumericRangeQuery64.java @@ -385,19 +385,19 @@ public class TestNumericRangeQuery64 extends LuceneTestCase { // test inclusive range Query tq= LegacyNumericRangeQuery.newLongRange(field, precisionStep, lower, upper, true, true); TopDocs tTopDocs = searcher.search(tq, 1); - assertEquals("Returned count of range query must be equal to inclusive range length", upper-lower+1, tTopDocs.totalHits ); + assertEquals("Returned count of range query must be equal to inclusive range length", upper-lower+1, tTopDocs.totalHits.value ); // test exclusive range tq= LegacyNumericRangeQuery.newLongRange(field, precisionStep, lower, upper, false, false); tTopDocs = searcher.search(tq, 1); - assertEquals("Returned count of range query must be equal to exclusive range length", Math.max(upper-lower-1, 0), tTopDocs.totalHits ); + assertEquals("Returned count of range query must be equal to exclusive range length", Math.max(upper-lower-1, 0), tTopDocs.totalHits.value ); // test left exclusive range tq= LegacyNumericRangeQuery.newLongRange(field, precisionStep, lower, upper, false, true); tTopDocs = searcher.search(tq, 1); - assertEquals("Returned count of range query must be equal to half exclusive range length", upper-lower, tTopDocs.totalHits ); + assertEquals("Returned count of range query must be equal to half exclusive range length", upper-lower, tTopDocs.totalHits.value ); // test right exclusive range tq= LegacyNumericRangeQuery.newLongRange(field, precisionStep, lower, upper, true, false); tTopDocs = searcher.search(tq, 1); - assertEquals("Returned count of range query must be equal to half exclusive range length", upper-lower, tTopDocs.totalHits ); + assertEquals("Returned count of range query must be equal to half exclusive range length", upper-lower, tTopDocs.totalHits.value ); } } @@ -429,7 +429,7 @@ public class TestNumericRangeQuery64 extends LuceneTestCase { Query tq= LegacyNumericRangeQuery.newDoubleRange(field, precisionStep, NumericUtils.sortableLongToDouble(lower), NumericUtils.sortableLongToDouble(upper), true, true); TopDocs tTopDocs = searcher.search(tq, 1); - assertEquals("Returned count of range query must be equal to inclusive range length", upper-lower+1, tTopDocs.totalHits ); + assertEquals("Returned count of range query must be equal to inclusive range length", upper-lower+1, tTopDocs.totalHits.value ); } @Test diff --git a/solr/core/src/test/org/apache/solr/search/TestFilteredDocIdSet.java b/solr/core/src/test/org/apache/solr/search/TestFilteredDocIdSet.java index 88b16ae6666..4a5c80543f4 100644 --- a/solr/core/src/test/org/apache/solr/search/TestFilteredDocIdSet.java +++ b/solr/core/src/test/org/apache/solr/search/TestFilteredDocIdSet.java @@ -125,7 +125,7 @@ public class TestFilteredDocIdSet extends LuceneTestCase { // First verify the document is searchable. IndexSearcher searcher = newSearcher(reader); - Assert.assertEquals(1, searcher.search(new MatchAllDocsQuery(), 10).totalHits); + Assert.assertEquals(1, searcher.search(new MatchAllDocsQuery(), 10).totalHits.value); // Now search w/ a Filter which returns a null DocIdSet Filter f = new Filter() { @@ -169,7 +169,7 @@ public class TestFilteredDocIdSet extends LuceneTestCase { // First verify the document is searchable. IndexSearcher searcher = newSearcher(reader); - Assert.assertEquals(1, searcher.search(new MatchAllDocsQuery(), 10).totalHits); + Assert.assertEquals(1, searcher.search(new MatchAllDocsQuery(), 10).totalHits.value); // Now search w/ a Filter which returns a null DocIdSet Filter f = new Filter() { diff --git a/solr/core/src/test/org/apache/solr/search/TestRankQueryPlugin.java b/solr/core/src/test/org/apache/solr/search/TestRankQueryPlugin.java index f72fd56b98d..b2c396e826a 100644 --- a/solr/core/src/test/org/apache/solr/search/TestRankQueryPlugin.java +++ b/solr/core/src/test/org/apache/solr/search/TestRankQueryPlugin.java @@ -45,6 +45,7 @@ import org.apache.lucene.search.Sort; import org.apache.lucene.search.SortField; import org.apache.lucene.search.TopDocs; import org.apache.lucene.search.TopDocsCollector; +import org.apache.lucene.search.TotalHits; import org.apache.lucene.search.Weight; import org.apache.lucene.util.InPlaceMergeSorter; import org.apache.lucene.util.PriorityQueue; @@ -723,7 +724,7 @@ public class TestRankQueryPlugin extends QParserPlugin { } }); ScoreDoc[] scoreDocs = list.toArray(new ScoreDoc[list.size()]); - return new TopDocs(list.size(), scoreDocs); + return new TopDocs(new TotalHits(list.size(), TotalHits.Relation.EQUAL_TO), scoreDocs); } public TopDocs topDocs(int start, int len) { @@ -785,7 +786,7 @@ public class TestRankQueryPlugin extends QParserPlugin { } }); ScoreDoc[] scoreDocs = list.toArray(new ScoreDoc[list.size()]); - return new TopDocs(list.size(), scoreDocs); + return new TopDocs(new TotalHits(list.size(), TotalHits.Relation.EQUAL_TO), scoreDocs); } public TopDocs topDocs(int start, int len) { diff --git a/solr/core/src/test/org/apache/solr/search/function/TestOrdValues.java b/solr/core/src/test/org/apache/solr/search/function/TestOrdValues.java index f7918d75f64..6b68bf3340f 100644 --- a/solr/core/src/test/org/apache/solr/search/function/TestOrdValues.java +++ b/solr/core/src/test/org/apache/solr/search/function/TestOrdValues.java @@ -145,7 +145,7 @@ public class TestOrdValues extends LuceneTestCase { } Query q = new FunctionQuery(vs); TopDocs td = s.search(q, 1000); - assertEquals("All docs should be matched!", N_DOCS, td.totalHits); + assertEquals("All docs should be matched!", N_DOCS, td.totalHits.value); ScoreDoc sd[] = td.scoreDocs; for (int i = 0; i < sd.length; i++) { float score = sd[i].score; diff --git a/solr/core/src/test/org/apache/solr/search/join/BJQParserTest.java b/solr/core/src/test/org/apache/solr/search/join/BJQParserTest.java index a2f625c849f..48d64d626e6 100644 --- a/solr/core/src/test/org/apache/solr/search/join/BJQParserTest.java +++ b/solr/core/src/test/org/apache/solr/search/join/BJQParserTest.java @@ -459,7 +459,7 @@ public class BJQParserTest extends SolrTestCaseJ4 { QParser parser = QParser.getParser(req.getParams().get("q"), null, req); query = parser.getQuery(); final TopDocs topDocs = req.getSearcher().search(query, 10); - assertEquals(1, topDocs.totalHits); + assertEquals(1, topDocs.totalHits.value); } assertU(adoc("id", "12275", "child_s", "l", "childparent_s", "e")); diff --git a/solr/core/src/test/org/apache/solr/uninverting/TestFieldCacheSort.java b/solr/core/src/test/org/apache/solr/uninverting/TestFieldCacheSort.java index ddf4cc3d20e..ac7bd7f4dbd 100644 --- a/solr/core/src/test/org/apache/solr/uninverting/TestFieldCacheSort.java +++ b/solr/core/src/test/org/apache/solr/uninverting/TestFieldCacheSort.java @@ -88,7 +88,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", sortType)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); // 'bar' comes before 'foo' assertEquals("bar", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("foo", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -127,7 +127,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", sortType)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // null comes first assertNull(searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("bar", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -164,7 +164,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", sortType, true)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); // 'foo' comes after 'bar' in reverse order assertEquals("foo", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("bar", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -204,7 +204,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(sf); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // null comes first assertNull(searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("bar", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -245,7 +245,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(sf); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); assertEquals("foo", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("bar", searcher.doc(td.scoreDocs[1].doc).get("value")); // null comes last @@ -287,7 +287,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(sf); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); assertEquals("bar", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("foo", searcher.doc(td.scoreDocs[1].doc).get("value")); // null comes last @@ -329,7 +329,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(sf); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // null comes first assertNull(searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("foo", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -356,7 +356,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(SortField.FIELD_DOC); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); // docid 0, then docid 1 assertEquals(0, td.scoreDocs[0].doc); assertEquals(1, td.scoreDocs[1].doc); @@ -382,7 +382,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(new SortField(null, SortField.Type.DOC, true)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); // docid 1, then docid 0 assertEquals(1, td.scoreDocs[0].doc); assertEquals(0, td.scoreDocs[1].doc); @@ -408,11 +408,11 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(); TopDocs actual = searcher.search(new TermQuery(new Term("value", "foo")), 10, sort); - assertEquals(2, actual.totalHits); + assertEquals(2, actual.totalHits.value); TopDocs expected = searcher.search(new TermQuery(new Term("value", "foo")), 10); // the two topdocs should be the same - assertEquals(expected.totalHits, actual.totalHits); + assertEquals(expected.totalHits.value, actual.totalHits.value); for (int i = 0; i < actual.scoreDocs.length; i++) { assertEquals(actual.scoreDocs[i].doc, expected.scoreDocs[i].doc); } @@ -440,11 +440,11 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(new SortField(null, SortField.Type.SCORE, true)); TopDocs actual = searcher.search(new TermQuery(new Term("value", "foo")), 10, sort); - assertEquals(2, actual.totalHits); + assertEquals(2, actual.totalHits.value); TopDocs expected = searcher.search(new TermQuery(new Term("value", "foo")), 10); // the two topdocs should be the reverse of each other - assertEquals(expected.totalHits, actual.totalHits); + assertEquals(expected.totalHits.value, actual.totalHits.value); assertEquals(actual.scoreDocs[0].doc, expected.scoreDocs[1].doc); assertEquals(actual.scoreDocs[1].doc, expected.scoreDocs[0].doc); TestUtil.checkReader(ir); @@ -476,7 +476,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.INT)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // numeric order assertEquals("-1", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -508,7 +508,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.INT)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // null is treated as a 0 assertEquals("-1", searcher.doc(td.scoreDocs[0].doc).get("value")); assertNull(searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -542,7 +542,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(sortField); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // null is treated as a Integer.MAX_VALUE assertEquals("-1", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -576,7 +576,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.INT, true)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // reverse numeric order assertEquals("300000", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -607,7 +607,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.INT)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // numeric order assertEquals("-1", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -637,7 +637,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.INT)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // null is treated as a 0 assertEquals("-1", searcher.doc(td.scoreDocs[0].doc).get("value")); assertNull(searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -669,7 +669,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(sortField); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // null is treated as a Integer.MAX_VALUE assertEquals("-1", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -700,7 +700,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.INT, true)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // reverse numeric order assertEquals("300000", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -734,7 +734,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.LONG)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // numeric order assertEquals("-1", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -766,7 +766,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.LONG)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // null is treated as 0 assertEquals("-1", searcher.doc(td.scoreDocs[0].doc).get("value")); assertNull(searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -800,7 +800,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(sortField); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // null is treated as Long.MAX_VALUE assertEquals("-1", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -834,7 +834,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.LONG, true)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // reverse numeric order assertEquals("3000000000", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -865,7 +865,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.LONG)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // numeric order assertEquals("-1", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -895,7 +895,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.LONG)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // null is treated as 0 assertEquals("-1", searcher.doc(td.scoreDocs[0].doc).get("value")); assertNull(searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -927,7 +927,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(sortField); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // null is treated as Long.MAX_VALUE assertEquals("-1", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -958,7 +958,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.LONG, true)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // reverse numeric order assertEquals("3000000000", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -992,7 +992,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.FLOAT)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // numeric order assertEquals("-1.3", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4.2", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -1024,7 +1024,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.FLOAT)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // null is treated as 0 assertEquals("-1.3", searcher.doc(td.scoreDocs[0].doc).get("value")); assertNull(searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -1058,7 +1058,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(sortField); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // null is treated as Float.MAX_VALUE assertEquals("-1.3", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4.2", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -1092,7 +1092,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.FLOAT, true)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // reverse numeric order assertEquals("30.1", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4.2", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -1123,7 +1123,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.FLOAT)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // numeric order assertEquals("-1.3", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4.2", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -1153,7 +1153,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.FLOAT)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // null is treated as 0 assertEquals("-1.3", searcher.doc(td.scoreDocs[0].doc).get("value")); assertNull(searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -1185,7 +1185,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(sortField); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // null is treated as Float.MAX_VALUE assertEquals("-1.3", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4.2", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -1216,7 +1216,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.FLOAT, true)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(3, td.totalHits); + assertEquals(3, td.totalHits.value); // reverse numeric order assertEquals("30.1", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4.2", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -1254,7 +1254,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.DOUBLE)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(4, td.totalHits); + assertEquals(4, td.totalHits.value); // numeric order assertEquals("-1.3", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4.2333333333332", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -1286,7 +1286,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.DOUBLE)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); // numeric order double v0 = searcher.doc(td.scoreDocs[0].doc).getField("value").numericValue().doubleValue(); double v1 = searcher.doc(td.scoreDocs[1].doc).getField("value").numericValue().doubleValue(); @@ -1326,7 +1326,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.DOUBLE)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(4, td.totalHits); + assertEquals(4, td.totalHits.value); // null treated as a 0 assertEquals("-1.3", searcher.doc(td.scoreDocs[0].doc).get("value")); assertNull(searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -1365,7 +1365,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(sortField); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(4, td.totalHits); + assertEquals(4, td.totalHits.value); // null treated as Double.MAX_VALUE assertEquals("-1.3", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4.2333333333332", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -1404,7 +1404,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.DOUBLE, true)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(4, td.totalHits); + assertEquals(4, td.totalHits.value); // numeric order assertEquals("30.1", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4.2333333333333", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -1439,7 +1439,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.DOUBLE)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(4, td.totalHits); + assertEquals(4, td.totalHits.value); // numeric order assertEquals("-1.3", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4.2333333333332", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -1469,7 +1469,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.DOUBLE)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); // numeric order double v0 = searcher.doc(td.scoreDocs[0].doc).getField("value").numericValue().doubleValue(); double v1 = searcher.doc(td.scoreDocs[1].doc).getField("value").numericValue().doubleValue(); @@ -1506,7 +1506,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.DOUBLE)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(4, td.totalHits); + assertEquals(4, td.totalHits.value); // null treated as a 0 assertEquals("-1.3", searcher.doc(td.scoreDocs[0].doc).get("value")); assertNull(searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -1542,7 +1542,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(sortField); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(4, td.totalHits); + assertEquals(4, td.totalHits.value); // null treated as Double.MAX_VALUE assertEquals("-1.3", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4.2333333333332", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -1577,7 +1577,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.DOUBLE, true)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(4, td.totalHits); + assertEquals(4, td.totalHits.value); // numeric order assertEquals("30.1", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("4.2333333333333", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -1605,7 +1605,7 @@ public class TestFieldCacheSort extends LuceneTestCase { w.close(); IndexSearcher s = newSearcher(r); TopDocs hits = s.search(new TermQuery(new Term("t", "1")), 10, new Sort(new SortField("f", SortField.Type.STRING))); - assertEquals(2, hits.totalHits); + assertEquals(2, hits.totalHits.value); // null sorts first assertEquals(1, hits.scoreDocs[0].doc); assertEquals(0, hits.scoreDocs[1].doc); @@ -1676,27 +1676,27 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(); TopDocs td = empty.search(query, 10, sort, true); - assertEquals(0, td.totalHits); + assertEquals(0, td.totalHits.value); sort.setSort(SortField.FIELD_DOC); td = empty.search(query, 10, sort, true); - assertEquals(0, td.totalHits); + assertEquals(0, td.totalHits.value); sort.setSort(new SortField("int", SortField.Type.INT), SortField.FIELD_DOC); td = empty.search(query, 10, sort, true); - assertEquals(0, td.totalHits); + assertEquals(0, td.totalHits.value); sort.setSort(new SortField("string", SortField.Type.STRING, true), SortField.FIELD_DOC); td = empty.search(query, 10, sort, true); - assertEquals(0, td.totalHits); + assertEquals(0, td.totalHits.value); sort.setSort(new SortField("string_val", SortField.Type.STRING_VAL, true), SortField.FIELD_DOC); td = empty.search(query, 10, sort, true); - assertEquals(0, td.totalHits); + assertEquals(0, td.totalHits.value); sort.setSort(new SortField("float", SortField.Type.FLOAT), new SortField("string", SortField.Type.STRING)); td = empty.search(query, 10, sort, true); - assertEquals(0, td.totalHits); + assertEquals(0, td.totalHits.value); } /** Tests sorting a single document */ @@ -1714,7 +1714,7 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.STRING)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(1, td.totalHits); + assertEquals(1, td.totalHits.value); assertEquals("foo", searcher.doc(td.scoreDocs[0].doc).get("value")); TestUtil.checkReader(ir); ir.close(); @@ -1736,10 +1736,10 @@ public class TestFieldCacheSort extends LuceneTestCase { Sort sort = new Sort(new SortField("value", SortField.Type.STRING)); TopDocs expected = searcher.search(new TermQuery(new Term("value", "foo")), 10); - assertEquals(1, expected.totalHits); + assertEquals(1, expected.totalHits.value); TopDocs actual = searcher.search(new TermQuery(new Term("value", "foo")), 10, sort, true); - assertEquals(expected.totalHits, actual.totalHits); + assertEquals(expected.totalHits.value, actual.totalHits.value); assertEquals(expected.scoreDocs[0].score, actual.scoreDocs[0].score, 0F); TestUtil.checkReader(ir); ir.close(); @@ -1771,7 +1771,7 @@ public class TestFieldCacheSort extends LuceneTestCase { new SortField("value", SortField.Type.STRING)); TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); // 'bar' comes before 'foo' assertEquals("bar", searcher.doc(td.scoreDocs[0].doc).get("value")); assertEquals("foo", searcher.doc(td.scoreDocs[1].doc).get("value")); @@ -1799,7 +1799,7 @@ public class TestFieldCacheSort extends LuceneTestCase { bq.add(new TermQuery(new Term("value", "foo")), Occur.SHOULD); bq.add(new MatchAllDocsQuery(), Occur.SHOULD); TopDocs td = searcher.search(bq.build(), 10, sort); - assertEquals(2, td.totalHits); + assertEquals(2, td.totalHits.value); if (Float.isNaN(td.scoreDocs[0].score) == false && Float.isNaN(td.scoreDocs[1].score) == false) { assertEquals(1, td.scoreDocs[0].doc); assertEquals(0, td.scoreDocs[1].doc); diff --git a/solr/core/src/test/org/apache/solr/uninverting/TestFieldCacheSortRandom.java b/solr/core/src/test/org/apache/solr/uninverting/TestFieldCacheSortRandom.java index 4ca56e9ae80..85eea60626d 100644 --- a/solr/core/src/test/org/apache/solr/uninverting/TestFieldCacheSortRandom.java +++ b/solr/core/src/test/org/apache/solr/uninverting/TestFieldCacheSortRandom.java @@ -174,7 +174,7 @@ public class TestFieldCacheSortRandom extends LuceneTestCase { } if (VERBOSE) { - System.out.println("\nTEST: iter=" + iter + " " + hits.totalHits + " hits; topN=" + hitCount + "; reverse=" + reverse + "; sortMissingLast=" + sortMissingLast + " sort=" + sort); + System.out.println("\nTEST: iter=" + iter + " " + hits.totalHits + " ; topN=" + hitCount + "; reverse=" + reverse + "; sortMissingLast=" + sortMissingLast + " sort=" + sort); } // Compute expected results: diff --git a/solr/core/src/test/org/apache/solr/uninverting/TestNumericTerms32.java b/solr/core/src/test/org/apache/solr/uninverting/TestNumericTerms32.java index b9392b72c27..cc80867b0c1 100644 --- a/solr/core/src/test/org/apache/solr/uninverting/TestNumericTerms32.java +++ b/solr/core/src/test/org/apache/solr/uninverting/TestNumericTerms32.java @@ -127,7 +127,7 @@ public class TestNumericTerms32 extends LuceneTestCase { } Query tq= LegacyNumericRangeQuery.newIntRange(field, precisionStep, lower, upper, true, true); TopDocs topDocs = searcher.search(tq, noDocs, new Sort(new SortField(field, SortField.Type.INT, true))); - if (topDocs.totalHits==0) continue; + if (topDocs.totalHits.value==0) continue; ScoreDoc[] sd = topDocs.scoreDocs; assertNotNull(sd); int last = searcher.doc(sd[0].doc).getField(field).numericValue().intValue(); diff --git a/solr/core/src/test/org/apache/solr/uninverting/TestNumericTerms64.java b/solr/core/src/test/org/apache/solr/uninverting/TestNumericTerms64.java index 61a357990a3..7de523b8a84 100644 --- a/solr/core/src/test/org/apache/solr/uninverting/TestNumericTerms64.java +++ b/solr/core/src/test/org/apache/solr/uninverting/TestNumericTerms64.java @@ -132,7 +132,7 @@ public class TestNumericTerms64 extends LuceneTestCase { } Query tq= LegacyNumericRangeQuery.newLongRange(field, precisionStep, lower, upper, true, true); TopDocs topDocs = searcher.search(tq, noDocs, new Sort(new SortField(field, SortField.Type.LONG, true))); - if (topDocs.totalHits==0) continue; + if (topDocs.totalHits.value==0) continue; ScoreDoc[] sd = topDocs.scoreDocs; assertNotNull(sd); long last=searcher.doc(sd[0].doc).getField(field).numericValue().longValue(); diff --git a/solr/core/src/test/org/apache/solr/update/AddBlockUpdateTest.java b/solr/core/src/test/org/apache/solr/update/AddBlockUpdateTest.java index 19131663950..a302d585305 100644 --- a/solr/core/src/test/org/apache/solr/update/AddBlockUpdateTest.java +++ b/solr/core/src/test/org/apache/solr/update/AddBlockUpdateTest.java @@ -178,7 +178,7 @@ public class AddBlockUpdateTest extends SolrTestCaseJ4 { assertSingleParentOf(searcher, one("ab"), dubbed); final TopDocs docs = searcher.search(join(one("cd")), 10); - assertEquals(2, docs.totalHits); + assertEquals(2, docs.totalHits.value); final String pAct = searcher.doc(docs.scoreDocs[0].doc).get(parent)+ searcher.doc(docs.scoreDocs[1].doc).get(parent); assertTrue(pAct.contains(dubbed) && pAct.contains(overwritten) && pAct.length()==2); @@ -704,7 +704,7 @@ public class AddBlockUpdateTest extends SolrTestCaseJ4 { protected void assertSingleParentOf(final SolrIndexSearcher searcher, final String childTerm, String parentExp) throws IOException { final TopDocs docs = searcher.search(join(childTerm), 10); - assertEquals(1, docs.totalHits); + assertEquals(1, docs.totalHits.value); final String pAct = searcher.doc(docs.scoreDocs[0].doc).get(parent); assertEquals(parentExp, pAct); }