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 ;
@@ -640,9 +640,8 @@ public void testTranslogMultipleOperationsSameDocument() throws IOException {
640640 recoverFromTranslog (recoveringEngine , translogHandler , Long .MAX_VALUE );
641641 recoveringEngine .refresh ("test" );
642642 try (Engine .Searcher searcher = recoveringEngine .acquireSearcher ("test" )) {
643- final TotalHitCountCollector collector = new TotalHitCountCollector ();
644- searcher .search (new MatchAllDocsQuery (), collector );
645- assertThat (collector .getTotalHits (), equalTo (operations .get (operations .size () - 1 ) instanceof Engine .Delete ? 0 : 1 ));
643+ Integer totalHits = searcher .search (new MatchAllDocsQuery (), new TotalHitCountCollectorManager ());
644+ assertThat (totalHits , equalTo (operations .get (operations .size () - 1 ) instanceof Engine .Delete ? 0 : 1 ));
646645 }
647646 }
648647 }
@@ -2009,16 +2008,20 @@ public void testConcurrentOutOfOrderDocsOnReplica() throws IOException, Interrup
20092008
20102009 if (lastFieldValueDoc1 != null ) {
20112010 try (Engine .Searcher searcher = engine .acquireSearcher ("test" )) {
2012- final TotalHitCountCollector collector = new TotalHitCountCollector ();
2013- searcher .search (new TermQuery (new Term ("value" , lastFieldValueDoc1 )), collector );
2014- assertThat (collector .getTotalHits (), equalTo (1 ));
2011+ Integer totalHits = searcher .search (
2012+ new TermQuery (new Term ("value" , lastFieldValueDoc1 )),
2013+ new TotalHitCountCollectorManager ()
2014+ );
2015+ assertThat (totalHits , equalTo (1 ));
20152016 }
20162017 }
20172018 if (lastFieldValueDoc2 != null ) {
20182019 try (Engine .Searcher searcher = engine .acquireSearcher ("test" )) {
2019- final TotalHitCountCollector collector = new TotalHitCountCollector ();
2020- searcher .search (new TermQuery (new Term ("value" , lastFieldValueDoc2 )), collector );
2021- assertThat (collector .getTotalHits (), equalTo (1 ));
2020+ Integer totalHits = searcher .search (
2021+ new TermQuery (new Term ("value" , lastFieldValueDoc2 )),
2022+ new TotalHitCountCollectorManager ()
2023+ );
2024+ assertThat (totalHits , equalTo (1 ));
20222025 }
20232026 }
20242027
@@ -2244,9 +2247,11 @@ private int assertOpsOnPrimary(List<Engine.Operation> ops, long currentOpVersion
22442247 // first op and it failed.
22452248 if (docDeleted == false && lastFieldValue != null ) {
22462249 try (Engine .Searcher searcher = engine .acquireSearcher ("test" )) {
2247- final TotalHitCountCollector collector = new TotalHitCountCollector ();
2248- searcher .search (new TermQuery (new Term ("value" , lastFieldValue )), collector );
2249- assertThat (collector .getTotalHits (), equalTo (1 ));
2250+ Integer totalHits = searcher .search (
2251+ new TermQuery (new Term ("value" , lastFieldValue )),
2252+ new TotalHitCountCollectorManager ()
2253+ );
2254+ assertThat (totalHits , equalTo (1 ));
22502255 }
22512256 }
22522257 }
@@ -2270,9 +2275,8 @@ private int assertOpsOnPrimary(List<Engine.Operation> ops, long currentOpVersion
22702275 assertVisibleCount (engine , docDeleted ? 0 : 1 );
22712276 if (docDeleted == false ) {
22722277 try (Engine .Searcher searcher = engine .acquireSearcher ("test" )) {
2273- final TotalHitCountCollector collector = new TotalHitCountCollector ();
2274- searcher .search (new TermQuery (new Term ("value" , lastFieldValue )), collector );
2275- assertThat (collector .getTotalHits (), equalTo (1 ));
2278+ Integer totalHits = searcher .search (new TermQuery (new Term ("value" , lastFieldValue )), new TotalHitCountCollectorManager ());
2279+ assertThat (totalHits , equalTo (1 ));
22762280 }
22772281 }
22782282 return opsPerformed ;
@@ -2357,9 +2361,8 @@ public void testNonInternalVersioningOnPrimary() throws IOException {
23572361 if (docDeleted == false ) {
23582362 logger .info ("searching for [{}]" , lastFieldValue );
23592363 try (Engine .Searcher searcher = engine .acquireSearcher ("test" )) {
2360- final TotalHitCountCollector collector = new TotalHitCountCollector ();
2361- searcher .search (new TermQuery (new Term ("value" , lastFieldValue )), collector );
2362- assertThat (collector .getTotalHits (), equalTo (1 ));
2364+ Integer totalHits = searcher .search (new TermQuery (new Term ("value" , lastFieldValue )), new TotalHitCountCollectorManager ());
2365+ assertThat (totalHits , equalTo (1 ));
23632366 }
23642367 }
23652368 }
@@ -2375,9 +2378,8 @@ public void testVersioningPromotedReplica() throws IOException {
23752378 final int opsOnPrimary = assertOpsOnPrimary (primaryOps , finalReplicaVersion , deletedOnReplica , replicaEngine );
23762379 final long currentSeqNo = getSequenceID (replicaEngine , new Engine .Get (false , false , Term .toString (lastReplicaOp .uid ()))).v1 ();
23772380 try (Engine .Searcher searcher = engine .acquireSearcher ("test" , Engine .SearcherScope .INTERNAL )) {
2378- final TotalHitCountCollector collector = new TotalHitCountCollector ();
2379- searcher .search (new MatchAllDocsQuery (), collector );
2380- if (collector .getTotalHits () > 0 ) {
2381+ Integer totalHits = searcher .search (new MatchAllDocsQuery (), new TotalHitCountCollectorManager ());
2382+ if (totalHits > 0 ) {
23812383 // last op wasn't delete
23822384 assertThat (currentSeqNo , equalTo (finalReplicaSeqNo + opsOnPrimary ));
23832385 }
@@ -2400,9 +2402,8 @@ public void testConcurrentExternalVersioningOnPrimary() throws IOException, Inte
24002402 assertVisibleCount (engine , lastFieldValue == null ? 0 : 1 );
24012403 if (lastFieldValue != null ) {
24022404 try (Engine .Searcher searcher = engine .acquireSearcher ("test" )) {
2403- final TotalHitCountCollector collector = new TotalHitCountCollector ();
2404- searcher .search (new TermQuery (new Term ("value" , lastFieldValue )), collector );
2405- assertThat (collector .getTotalHits (), equalTo (1 ));
2405+ Integer totalHits = searcher .search (new TermQuery (new Term ("value" , lastFieldValue )), new TotalHitCountCollectorManager ());
2406+ assertThat (totalHits , equalTo (1 ));
24062407 }
24072408 }
24082409 }
0 commit comments