5555import org .apache .lucene .search .SortedSetSortField ;
5656import org .apache .lucene .search .TermQuery ;
5757import org .apache .lucene .search .TopDocs ;
58- import org .apache .lucene .search .TotalHitCountCollector ;
58+ import org .apache .lucene .search .TotalHitCountCollectorManager ;
5959import org .apache .lucene .store .AlreadyClosedException ;
6060import org .apache .lucene .store .Directory ;
6161import org .apache .lucene .store .Lock ;
@@ -641,9 +641,8 @@ public void testTranslogMultipleOperationsSameDocument() throws IOException {
641641 recoverFromTranslog (recoveringEngine , translogHandler , Long .MAX_VALUE );
642642 recoveringEngine .refresh ("test" );
643643 try (Engine .Searcher searcher = recoveringEngine .acquireSearcher ("test" )) {
644- final TotalHitCountCollector collector = new TotalHitCountCollector ();
645- searcher .search (new MatchAllDocsQuery (), collector );
646- assertThat (collector .getTotalHits (), equalTo (operations .get (operations .size () - 1 ) instanceof Engine .Delete ? 0 : 1 ));
644+ Integer totalHits = searcher .search (new MatchAllDocsQuery (), new TotalHitCountCollectorManager ());
645+ assertThat (totalHits , equalTo (operations .get (operations .size () - 1 ) instanceof Engine .Delete ? 0 : 1 ));
647646 }
648647 }
649648 }
@@ -2010,16 +2009,20 @@ public void testConcurrentOutOfOrderDocsOnReplica() throws IOException, Interrup
20102009
20112010 if (lastFieldValueDoc1 != null ) {
20122011 try (Engine .Searcher searcher = engine .acquireSearcher ("test" )) {
2013- final TotalHitCountCollector collector = new TotalHitCountCollector ();
2014- searcher .search (new TermQuery (new Term ("value" , lastFieldValueDoc1 )), collector );
2015- assertThat (collector .getTotalHits (), equalTo (1 ));
2012+ Integer totalHits = searcher .search (
2013+ new TermQuery (new Term ("value" , lastFieldValueDoc1 )),
2014+ new TotalHitCountCollectorManager ()
2015+ );
2016+ assertThat (totalHits , equalTo (1 ));
20162017 }
20172018 }
20182019 if (lastFieldValueDoc2 != null ) {
20192020 try (Engine .Searcher searcher = engine .acquireSearcher ("test" )) {
2020- final TotalHitCountCollector collector = new TotalHitCountCollector ();
2021- searcher .search (new TermQuery (new Term ("value" , lastFieldValueDoc2 )), collector );
2022- assertThat (collector .getTotalHits (), equalTo (1 ));
2021+ Integer totalHits = searcher .search (
2022+ new TermQuery (new Term ("value" , lastFieldValueDoc2 )),
2023+ new TotalHitCountCollectorManager ()
2024+ );
2025+ assertThat (totalHits , equalTo (1 ));
20232026 }
20242027 }
20252028
@@ -2245,9 +2248,11 @@ private int assertOpsOnPrimary(List<Engine.Operation> ops, long currentOpVersion
22452248 // first op and it failed.
22462249 if (docDeleted == false && lastFieldValue != null ) {
22472250 try (Engine .Searcher searcher = engine .acquireSearcher ("test" )) {
2248- final TotalHitCountCollector collector = new TotalHitCountCollector ();
2249- searcher .search (new TermQuery (new Term ("value" , lastFieldValue )), collector );
2250- assertThat (collector .getTotalHits (), equalTo (1 ));
2251+ Integer totalHits = searcher .search (
2252+ new TermQuery (new Term ("value" , lastFieldValue )),
2253+ new TotalHitCountCollectorManager ()
2254+ );
2255+ assertThat (totalHits , equalTo (1 ));
22512256 }
22522257 }
22532258 }
@@ -2271,9 +2276,8 @@ private int assertOpsOnPrimary(List<Engine.Operation> ops, long currentOpVersion
22712276 assertVisibleCount (engine , docDeleted ? 0 : 1 );
22722277 if (docDeleted == false ) {
22732278 try (Engine .Searcher searcher = engine .acquireSearcher ("test" )) {
2274- final TotalHitCountCollector collector = new TotalHitCountCollector ();
2275- searcher .search (new TermQuery (new Term ("value" , lastFieldValue )), collector );
2276- assertThat (collector .getTotalHits (), equalTo (1 ));
2279+ Integer totalHits = searcher .search (new TermQuery (new Term ("value" , lastFieldValue )), new TotalHitCountCollectorManager ());
2280+ assertThat (totalHits , equalTo (1 ));
22772281 }
22782282 }
22792283 return opsPerformed ;
@@ -2358,9 +2362,8 @@ public void testNonInternalVersioningOnPrimary() throws IOException {
23582362 if (docDeleted == false ) {
23592363 logger .info ("searching for [{}]" , lastFieldValue );
23602364 try (Engine .Searcher searcher = engine .acquireSearcher ("test" )) {
2361- final TotalHitCountCollector collector = new TotalHitCountCollector ();
2362- searcher .search (new TermQuery (new Term ("value" , lastFieldValue )), collector );
2363- assertThat (collector .getTotalHits (), equalTo (1 ));
2365+ Integer totalHits = searcher .search (new TermQuery (new Term ("value" , lastFieldValue )), new TotalHitCountCollectorManager ());
2366+ assertThat (totalHits , equalTo (1 ));
23642367 }
23652368 }
23662369 }
@@ -2376,9 +2379,8 @@ public void testVersioningPromotedReplica() throws IOException {
23762379 final int opsOnPrimary = assertOpsOnPrimary (primaryOps , finalReplicaVersion , deletedOnReplica , replicaEngine );
23772380 final long currentSeqNo = getSequenceID (replicaEngine , new Engine .Get (false , false , Term .toString (lastReplicaOp .uid ()))).v1 ();
23782381 try (Engine .Searcher searcher = engine .acquireSearcher ("test" , Engine .SearcherScope .INTERNAL )) {
2379- final TotalHitCountCollector collector = new TotalHitCountCollector ();
2380- searcher .search (new MatchAllDocsQuery (), collector );
2381- if (collector .getTotalHits () > 0 ) {
2382+ Integer totalHits = searcher .search (new MatchAllDocsQuery (), new TotalHitCountCollectorManager ());
2383+ if (totalHits > 0 ) {
23822384 // last op wasn't delete
23832385 assertThat (currentSeqNo , equalTo (finalReplicaSeqNo + opsOnPrimary ));
23842386 }
@@ -2401,9 +2403,8 @@ public void testConcurrentExternalVersioningOnPrimary() throws IOException, Inte
24012403 assertVisibleCount (engine , lastFieldValue == null ? 0 : 1 );
24022404 if (lastFieldValue != null ) {
24032405 try (Engine .Searcher searcher = engine .acquireSearcher ("test" )) {
2404- final TotalHitCountCollector collector = new TotalHitCountCollector ();
2405- searcher .search (new TermQuery (new Term ("value" , lastFieldValue )), collector );
2406- assertThat (collector .getTotalHits (), equalTo (1 ));
2406+ Integer totalHits = searcher .search (new TermQuery (new Term ("value" , lastFieldValue )), new TotalHitCountCollectorManager ());
2407+ assertThat (totalHits , equalTo (1 ));
24072408 }
24082409 }
24092410 }
0 commit comments