From b75efa09b8cd943487d634ada8fa91b8cad4a958 Mon Sep 17 00:00:00 2001 From: Siju Varghese Date: Thu, 9 Jan 2025 09:50:56 -0800 Subject: [PATCH] codestyle fixes --- .../handler/component/ResponseBuilder.java | 4 +-- .../solr/response/SolrQueryResponse.java | 3 +- .../search/EarlyTerminatingCollector.java | 13 +++---- .../solr/search/MultiThreadedSearcher.java | 8 ++--- .../apache/solr/search/SolrIndexSearcher.java | 2 +- .../search/SolrMultiCollectorManager.java | 34 +++++++++---------- .../solr/common/params/CommonParams.java | 7 ++-- 7 files changed, 32 insertions(+), 39 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/handler/component/ResponseBuilder.java b/solr/core/src/java/org/apache/solr/handler/component/ResponseBuilder.java index 20c09eda28b..daf3d92a335 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/ResponseBuilder.java +++ b/solr/core/src/java/org/apache/solr/handler/component/ResponseBuilder.java @@ -463,9 +463,7 @@ public void setResult(QueryResult result) { final Boolean terminatedEarly = result.getTerminatedEarly(); if (terminatedEarly != null) { rsp.getResponseHeader() - .add( - SolrQueryResponse.RESPONSE_HEADER_TERMINATED_EARLY_KEY, - terminatedEarly); + .add(SolrQueryResponse.RESPONSE_HEADER_TERMINATED_EARLY_KEY, terminatedEarly); } if (null != cursorMark) { assert null != result.getNextCursorMark() : "using cursor but no next cursor set"; diff --git a/solr/core/src/java/org/apache/solr/response/SolrQueryResponse.java b/solr/core/src/java/org/apache/solr/response/SolrQueryResponse.java index 288afa42b15..035b6847e1b 100644 --- a/solr/core/src/java/org/apache/solr/response/SolrQueryResponse.java +++ b/solr/core/src/java/org/apache/solr/response/SolrQueryResponse.java @@ -68,8 +68,7 @@ public class SolrQueryResponse { public static final String RESPONSE_HEADER_PARTIAL_RESULTS_DETAILS_KEY = "partialResultsDetails"; public static final String RESPONSE_HEADER_SEGMENT_TERMINATED_EARLY_KEY = "segmentTerminatedEarly"; - public static final String RESPONSE_HEADER_TERMINATED_EARLY_KEY = - "terminatedEarly"; + public static final String RESPONSE_HEADER_TERMINATED_EARLY_KEY = "terminatedEarly"; public static final String RESPONSE_HEADER_KEY = "responseHeader"; private static final String RESPONSE_KEY = "response"; diff --git a/solr/core/src/java/org/apache/solr/search/EarlyTerminatingCollector.java b/solr/core/src/java/org/apache/solr/search/EarlyTerminatingCollector.java index 4c8d38eb47d..7dadb066b25 100644 --- a/solr/core/src/java/org/apache/solr/search/EarlyTerminatingCollector.java +++ b/solr/core/src/java/org/apache/solr/search/EarlyTerminatingCollector.java @@ -18,7 +18,6 @@ import java.io.IOException; import java.util.concurrent.atomic.AtomicInteger; - import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.search.Collector; import org.apache.lucene.search.FilterCollector; @@ -41,7 +40,6 @@ public class EarlyTerminatingCollector extends FilterCollector { private final AtomicInteger pendingDocsToCollect; private boolean terminatedEarly = false; - /** * Wraps a {@link Collector}, throwing {@link EarlyTerminatingCollectorException} once the * specified maximum is reached. @@ -50,14 +48,16 @@ public class EarlyTerminatingCollector extends FilterCollector { * @param maxDocsToCollect - the maximum number of documents to Collect */ public EarlyTerminatingCollector(Collector delegate, int maxDocsToCollect) { - this(delegate,maxDocsToCollect, new AtomicInteger(maxDocsToCollect)); + this(delegate, maxDocsToCollect, new AtomicInteger(maxDocsToCollect)); } - public EarlyTerminatingCollector(Collector delegate, int maxDocsToCollect,AtomicInteger docsToCollect) { + public EarlyTerminatingCollector( + Collector delegate, int maxDocsToCollect, AtomicInteger docsToCollect) { super(delegate); this.maxDocsToCollect = maxDocsToCollect; this.pendingDocsToCollect = docsToCollect; } + @Override public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException { prevReaderCumulativeSize += currentReaderSize; // not current any more @@ -74,12 +74,13 @@ public void collect(int doc) throws IOException { terminatedEarly = pendingDocsToCollect.addAndGet(-1 * chunkSize) < 0; } if (terminatedEarly) { - throw new EarlyTerminatingCollectorException(maxDocsToCollect, - prevReaderCumulativeSize + (doc + 1)); + throw new EarlyTerminatingCollectorException( + maxDocsToCollect, prevReaderCumulativeSize + (doc + 1)); } } }; } + public boolean isTerminatedEarly() { return terminatedEarly; } diff --git a/solr/core/src/java/org/apache/solr/search/MultiThreadedSearcher.java b/solr/core/src/java/org/apache/solr/search/MultiThreadedSearcher.java index 0f43ee1a009..727f1834eb7 100644 --- a/solr/core/src/java/org/apache/solr/search/MultiThreadedSearcher.java +++ b/solr/core/src/java/org/apache/solr/search/MultiThreadedSearcher.java @@ -196,11 +196,11 @@ static class SearchResult { private final Object[] result; final boolean isTerminatedEarly; - public SearchResult(ScoreMode scoreMode, Object[] result) { this(scoreMode, result, false); } - public SearchResult(ScoreMode scoreMode, Object[] result,boolean isTerminatedEarly) { + + public SearchResult(ScoreMode scoreMode, Object[] result, boolean isTerminatedEarly) { this.scoreMode = scoreMode; this.result = result; this.isTerminatedEarly = isTerminatedEarly; @@ -271,7 +271,6 @@ public Object reduce(Collection collectors) throws IOException { next = earlyTerminatingCollector.getDelegate(); } collector = (MaxScoreCollector) next; - } return new MaxScoreResult(maxScore); @@ -341,7 +340,8 @@ public Object reduce(Collection collectors) throws IOException { for (Object o : collectors) { collector = (Collector) o; if (collector instanceof EarlyTerminatingCollector) { - EarlyTerminatingCollector earlyTerminatingCollector = (EarlyTerminatingCollector) collector; + EarlyTerminatingCollector earlyTerminatingCollector = + (EarlyTerminatingCollector) collector; collector = earlyTerminatingCollector.getDelegate(); } if (collector instanceof TopDocsCollector) { 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 efa36483362..15f0ffa3f98 100644 --- a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java +++ b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java @@ -1983,7 +1983,7 @@ public ScoreMode scoreMode() { MultiThreadedSearcher.TopDocsResult topDocsResult = searchResult.getTopDocsResult(); totalHits = topDocsResult.totalHits; topDocs = topDocsResult.topDocs; - if(searchResult.isTerminatedEarly){ + if (searchResult.isTerminatedEarly) { qr.setTerminatedEarly(true); qr.setPartialResults(Boolean.TRUE); } diff --git a/solr/core/src/java/org/apache/solr/search/SolrMultiCollectorManager.java b/solr/core/src/java/org/apache/solr/search/SolrMultiCollectorManager.java index 235a993f6ff..d07c64bc9b4 100644 --- a/solr/core/src/java/org/apache/solr/search/SolrMultiCollectorManager.java +++ b/solr/core/src/java/org/apache/solr/search/SolrMultiCollectorManager.java @@ -21,7 +21,6 @@ import java.util.Collection; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; - import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.search.Collector; import org.apache.lucene.search.CollectorManager; @@ -36,18 +35,18 @@ * MultiCollector} acts for {@link Collector}. */ public class SolrMultiCollectorManager - implements CollectorManager { + implements CollectorManager { private final CollectorManager[] collectorManagers; private AtomicInteger maxHits = null; private int maxDocsToCollect; private final List reducableCollectors = new ArrayList<>(); - @SafeVarargs @SuppressWarnings({"varargs", "unchecked"}) - public SolrMultiCollectorManager(QueryCommand queryCommand, - final CollectorManager... collectorManagers) { + public SolrMultiCollectorManager( + QueryCommand queryCommand, + final CollectorManager... collectorManagers) { if (collectorManagers.length < 1) { throw new IllegalArgumentException("There must be at least one collector"); } @@ -91,13 +90,12 @@ public Object[] reduce(Collection reducableCollectors) throws IOExce } return results; } + public Object[] reduce() throws IOException { return reduce(reducableCollectors); } - /** - * Wraps multiple collectors for processing - */ + /** Wraps multiple collectors for processing */ class Collectors implements Collector { private final Collector[] collectors; @@ -115,7 +113,7 @@ private Collectors() throws IOException { @Override public final LeafCollector getLeafCollector(final LeafReaderContext context) - throws IOException { + throws IOException { return new LeafCollectors(context, scoreMode() == ScoreMode.TOP_SCORES); } @@ -135,7 +133,7 @@ private class LeafCollectors implements LeafCollector { private final boolean skipNonCompetitiveScores; private LeafCollectors(final LeafReaderContext context, boolean skipNonCompetitiveScores) - throws IOException { + throws IOException { this.skipNonCompetitiveScores = skipNonCompetitiveScores; leafCollectors = new LeafCollector[collectors.length]; for (int i = 0; i < collectors.length; i++) { @@ -153,14 +151,14 @@ public final void setScorer(final Scorable scorer) throws IOException { } } else { FilterScorable fScorer = - new FilterScorable(scorer) { - @Override - public void setMinCompetitiveScore(float minScore) throws IOException { - // Ignore calls to setMinCompetitiveScore so that if we wrap two - // collectors and one of them wants to skip low-scoring hits, then - // the other collector still sees all hits. - } - }; + new FilterScorable(scorer) { + @Override + public void setMinCompetitiveScore(float minScore) throws IOException { + // Ignore calls to setMinCompetitiveScore so that if we wrap two + // collectors and one of them wants to skip low-scoring hits, then + // the other collector still sees all hits. + } + }; for (LeafCollector leafCollector : leafCollectors) { if (leafCollector != null) { leafCollector.setScorer(fScorer); diff --git a/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java b/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java index ed4fdc722ec..5160edc8c83 100644 --- a/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java +++ b/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java @@ -183,11 +183,8 @@ public interface CommonParams { */ String MEM_ALLOWED = "memAllowed"; - - /** - * The max hits to be collected per shard - */ - String MAX_HITS_PER_SHARD="maxHitsPerShard"; + /** The max hits to be collected per shard */ + String MAX_HITS_PER_SHARD = "maxHitsPerShard"; /** Is the query cancellable? */ String IS_QUERY_CANCELLABLE = "canCancel";