jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/381879 )
Change subject: cleanup checkstyle warnings on ...-lucene module ...................................................................... cleanup checkstyle warnings on ...-lucene module Javadoc warnings are left. Discussion is open on wheather we should fix them. Change-Id: I8e0a266f2625f812ca2335716c0e5cb52a86944c --- M experimental-highlighter-lucene/src/main/java/org/wikimedia/highlighter/experimental/lucene/QueryFlattener.java M experimental-highlighter-lucene/src/main/java/org/wikimedia/highlighter/experimental/lucene/hit/AutomatonHitEnum.java M experimental-highlighter-lucene/src/main/java/org/wikimedia/highlighter/experimental/lucene/hit/PostingsHitEnum.java M experimental-highlighter-lucene/src/main/java/org/wikimedia/highlighter/experimental/lucene/hit/weight/BasicQueryWeigher.java M experimental-highlighter-lucene/src/main/java/org/wikimedia/highlighter/experimental/lucene/hit/weight/DefaultSimilarityTermWeigher.java M experimental-highlighter-lucene/src/test/java/org/wikimedia/highlighter/experimental/Matchers.java M experimental-highlighter-lucene/src/test/java/org/wikimedia/highlighter/experimental/lucene/LuceneMatchers.java M experimental-highlighter-lucene/src/test/java/org/wikimedia/highlighter/experimental/lucene/QueryFlattenerTest.java M experimental-highlighter-lucene/src/test/java/org/wikimedia/highlighter/experimental/lucene/hit/AbstractHitEnumTestBase.java M experimental-highlighter-lucene/src/test/java/org/wikimedia/highlighter/experimental/lucene/hit/AbstractLuceneHitEnumTestBase.java M experimental-highlighter-lucene/src/test/java/org/wikimedia/highlighter/experimental/lucene/hit/AutomatonHitEnumTest.java 11 files changed, 87 insertions(+), 77 deletions(-) Approvals: jenkins-bot: Verified DCausse: Looks good to me, approved diff --git a/experimental-highlighter-lucene/src/main/java/org/wikimedia/highlighter/experimental/lucene/QueryFlattener.java b/experimental-highlighter-lucene/src/main/java/org/wikimedia/highlighter/experimental/lucene/QueryFlattener.java index 834f56e..1875167 100644 --- a/experimental-highlighter-lucene/src/main/java/org/wikimedia/highlighter/experimental/lucene/QueryFlattener.java +++ b/experimental-highlighter-lucene/src/main/java/org/wikimedia/highlighter/experimental/lucene/QueryFlattener.java @@ -1,5 +1,11 @@ package org.wikimedia.highlighter.experimental.lucene; +import java.io.IOException; +import java.util.HashSet; +import java.util.List; +import java.util.Objects; +import java.util.Set; + import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.Term; import org.apache.lucene.queries.CommonTermsQuery; @@ -32,14 +38,10 @@ import org.apache.lucene.util.automaton.LevenshteinAutomata; import org.apache.lucene.util.automaton.Operations; -import java.io.IOException; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - /** * Flattens {@link Query}s similarly to Lucene's FieldQuery. */ +@SuppressWarnings("checkstyle:classfanoutcomplexity") // should be fixed at some point public class QueryFlattener { /** * Some queries are inefficient to rebuild multiple times so we store some @@ -115,6 +117,7 @@ return phraseAsTerms; } + @SuppressWarnings("checkstyle:CyclomaticComplexity") // cyclomatic complexity is high, but the code is simple to read protected void flatten(Query query, float pathBoost, Object sourceOverride, IndexReader reader, Callback callback) { if (query instanceof TermQuery) { @@ -387,6 +390,7 @@ callback.flattened(automaton, boost, source.hashCode()); } + @SuppressWarnings({"checkstyle:CyclomaticComplexity", "checkstyle:NPathComplexity"}) protected void flattenQuery(CommonTermsQuery query, float pathBoost, Object sourceOverride, IndexReader reader, Callback callback) { Query rewritten = rewriteQuery(query, pathBoost, sourceOverride, reader); @@ -481,7 +485,7 @@ private final boolean transpositions; private final int prefixLength; - public FuzzyQueryInfo(String term, FuzzyQuery query) { + FuzzyQueryInfo(String term, FuzzyQuery query) { this.term = term; this.maxEdits = query.getMaxEdits(); this.transpositions = query.getTranspositions(); @@ -509,18 +513,10 @@ if (getClass() != obj.getClass()) return false; FuzzyQueryInfo other = (FuzzyQueryInfo) obj; - if (maxEdits != other.maxEdits) - return false; - if (prefixLength != other.prefixLength) - return false; - if (term == null) { - if (other.term != null) - return false; - } else if (!term.equals(other.term)) - return false; - if (transpositions != other.transpositions) - return false; - return true; + return Objects.equals(maxEdits, other.maxEdits) + && Objects.equals(prefixLength, other.prefixLength) + && Objects.equals(term, other.term) + && Objects.equals(transpositions, other.transpositions); } } } diff --git a/experimental-highlighter-lucene/src/main/java/org/wikimedia/highlighter/experimental/lucene/hit/AutomatonHitEnum.java b/experimental-highlighter-lucene/src/main/java/org/wikimedia/highlighter/experimental/lucene/hit/AutomatonHitEnum.java index 62a151d..0ac0ca2 100644 --- a/experimental-highlighter-lucene/src/main/java/org/wikimedia/highlighter/experimental/lucene/hit/AutomatonHitEnum.java +++ b/experimental-highlighter-lucene/src/main/java/org/wikimedia/highlighter/experimental/lucene/hit/AutomatonHitEnum.java @@ -15,7 +15,7 @@ return new Factory(automaton); } - public static class Factory { + public static final class Factory { private final OffsetReturningRunAutomaton run; private Factory(Automaton automaton) { diff --git a/experimental-highlighter-lucene/src/main/java/org/wikimedia/highlighter/experimental/lucene/hit/PostingsHitEnum.java b/experimental-highlighter-lucene/src/main/java/org/wikimedia/highlighter/experimental/lucene/hit/PostingsHitEnum.java index 94ce8a3..7746dc7 100644 --- a/experimental-highlighter-lucene/src/main/java/org/wikimedia/highlighter/experimental/lucene/hit/PostingsHitEnum.java +++ b/experimental-highlighter-lucene/src/main/java/org/wikimedia/highlighter/experimental/lucene/hit/PostingsHitEnum.java @@ -92,6 +92,8 @@ return EmptyHitEnum.INSTANCE; case 1: return enums.get(0); + default: + // do nothing, we only handle the simple cases here. } return new MergingHitEnum(enums, HitEnum.LessThans.POSITION); } diff --git a/experimental-highlighter-lucene/src/main/java/org/wikimedia/highlighter/experimental/lucene/hit/weight/BasicQueryWeigher.java b/experimental-highlighter-lucene/src/main/java/org/wikimedia/highlighter/experimental/lucene/hit/weight/BasicQueryWeigher.java index b5f6476..52d528d 100644 --- a/experimental-highlighter-lucene/src/main/java/org/wikimedia/highlighter/experimental/lucene/hit/weight/BasicQueryWeigher.java +++ b/experimental-highlighter-lucene/src/main/java/org/wikimedia/highlighter/experimental/lucene/hit/weight/BasicQueryWeigher.java @@ -154,7 +154,7 @@ public final Automaton automaton; public ByteRunAutomaton compiled; - public AutomatonSourceInfo(Automaton automaton) { + AutomatonSourceInfo(Automaton automaton) { this.automaton = automaton; } @@ -190,7 +190,7 @@ private final int slop; private float weight; - public PhraseInfo(int[][] phrase, int slop, float weight) { + PhraseInfo(int[][] phrase, int slop, float weight) { this.phrase = phrase; this.slop = slop; this.weight = weight; @@ -214,7 +214,7 @@ } private class FlattenerCallback implements QueryFlattener.Callback { - private float maxTermWeight = 0; + private float maxTermWeight; private int[][] phrase; private int phrasePosition; private int phraseTerm; @@ -332,7 +332,7 @@ private static class PhraseKey { private final int[][] phrase; - public PhraseKey(int[][] phrase) { + PhraseKey(int[][] phrase) { this.phrase = phrase; } diff --git a/experimental-highlighter-lucene/src/main/java/org/wikimedia/highlighter/experimental/lucene/hit/weight/DefaultSimilarityTermWeigher.java b/experimental-highlighter-lucene/src/main/java/org/wikimedia/highlighter/experimental/lucene/hit/weight/DefaultSimilarityTermWeigher.java index 18ff893..4849730 100644 --- a/experimental-highlighter-lucene/src/main/java/org/wikimedia/highlighter/experimental/lucene/hit/weight/DefaultSimilarityTermWeigher.java +++ b/experimental-highlighter-lucene/src/main/java/org/wikimedia/highlighter/experimental/lucene/hit/weight/DefaultSimilarityTermWeigher.java @@ -7,7 +7,6 @@ import org.apache.lucene.search.similarities.ClassicSimilarity; import org.apache.lucene.util.BytesRef; import org.wikimedia.highlighter.experimental.lucene.WrappedExceptionFromLucene; - import org.wikimedia.search.highlighter.experimental.hit.TermWeigher; /** diff --git a/experimental-highlighter-lucene/src/test/java/org/wikimedia/highlighter/experimental/Matchers.java b/experimental-highlighter-lucene/src/test/java/org/wikimedia/highlighter/experimental/Matchers.java index 96695ff..aaff8b9 100644 --- a/experimental-highlighter-lucene/src/test/java/org/wikimedia/highlighter/experimental/Matchers.java +++ b/experimental-highlighter-lucene/src/test/java/org/wikimedia/highlighter/experimental/Matchers.java @@ -1,5 +1,9 @@ package org.wikimedia.highlighter.experimental; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.closeTo; +import static org.hamcrest.Matchers.equalTo; + import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; @@ -7,11 +11,14 @@ import org.wikimedia.search.highlighter.experimental.Segment; import org.wikimedia.search.highlighter.experimental.SourceExtracter; -import static org.hamcrest.Matchers.*; - // Copied from core submodule, relying on test dependencies -// causes -public class Matchers { +// causes issues +public final class Matchers { + + private Matchers() { + // utility class + } + public static <T> Matcher<Segment> extracted(SourceExtracter<T> extracter, T t) { return extracted(extracter, equalTo(t)); } @@ -22,7 +29,7 @@ } public static <T> Matcher<HitEnum> hit(int position, SourceExtracter<T> extracter, - Matcher<T> extractedMatcher) { + Matcher<T> extractedMatcher) { return allOf(extracted(extracter, extractedMatcher), atPosition(position)); } @@ -62,10 +69,10 @@ return new SourceMatcher(source); } - private static class AdvancesMatcher extends TypeSafeMatcher<HitEnum> { + private static final class AdvancesMatcher extends TypeSafeMatcher<HitEnum> { private final boolean advances; - public AdvancesMatcher(boolean advances) { + private AdvancesMatcher(boolean advances) { this.advances = advances; } @@ -94,10 +101,10 @@ } } - private static class PositionMatcher extends TypeSafeMatcher<HitEnum> { + private static final class PositionMatcher extends TypeSafeMatcher<HitEnum> { private final int position; - public PositionMatcher(int position) { + private PositionMatcher(int position) { this.position = position; } @@ -117,10 +124,10 @@ } } - private static class StartOffsetMatcher extends TypeSafeMatcher<HitEnum> { + private static final class StartOffsetMatcher extends TypeSafeMatcher<HitEnum> { private final int startOffset; - public StartOffsetMatcher(int startOffset) { + private StartOffsetMatcher(int startOffset) { this.startOffset = startOffset; } @@ -140,10 +147,10 @@ } } - private static class EndOffsetMatcher extends TypeSafeMatcher<HitEnum> { + private static final class EndOffsetMatcher extends TypeSafeMatcher<HitEnum> { private final int endOffset; - public EndOffsetMatcher(int endOffset) { + private EndOffsetMatcher(int endOffset) { this.endOffset = endOffset; } @@ -163,10 +170,10 @@ } } - private static class SourceMatcher extends TypeSafeMatcher<HitEnum> { + private static final class SourceMatcher extends TypeSafeMatcher<HitEnum> { private final int source; - public SourceMatcher(int source) { + private SourceMatcher(int source) { this.source = source; } @@ -186,11 +193,11 @@ } } - private static class ExtractedMatcher<T> extends TypeSafeMatcher<Segment> { + private static final class ExtractedMatcher<T> extends TypeSafeMatcher<Segment> { private final SourceExtracter<T> extracter; private final Matcher<T> extractedMatcher; - public ExtractedMatcher(SourceExtracter<T> extracter, Matcher<T> extractedMatcher) { + private ExtractedMatcher(SourceExtracter<T> extracter, Matcher<T> extractedMatcher) { this.extracter = extracter; this.extractedMatcher = extractedMatcher; } @@ -215,10 +222,10 @@ } } - private static class WeightMatcher extends TypeSafeMatcher<HitEnum> { + private static final class WeightMatcher extends TypeSafeMatcher<HitEnum> { private final Matcher<Double> weightMatcher; - public WeightMatcher(Matcher<Double> weightMatcher) { + private WeightMatcher(Matcher<Double> weightMatcher) { this.weightMatcher = weightMatcher; } @@ -241,10 +248,10 @@ } } - private static class QueryWeightMatcher extends TypeSafeMatcher<HitEnum> { + private static final class QueryWeightMatcher extends TypeSafeMatcher<HitEnum> { private final Matcher<Double> weightMatcher; - public QueryWeightMatcher(Matcher<Double> weightMatcher) { + private QueryWeightMatcher(Matcher<Double> weightMatcher) { this.weightMatcher = weightMatcher; } @@ -267,10 +274,10 @@ } } - private static class CorpusWeightMatcher extends TypeSafeMatcher<HitEnum> { + private static final class CorpusWeightMatcher extends TypeSafeMatcher<HitEnum> { private final Matcher<Double> weightMatcher; - public CorpusWeightMatcher(Matcher<Double> weightMatcher) { + private CorpusWeightMatcher(Matcher<Double> weightMatcher) { this.weightMatcher = weightMatcher; } diff --git a/experimental-highlighter-lucene/src/test/java/org/wikimedia/highlighter/experimental/lucene/LuceneMatchers.java b/experimental-highlighter-lucene/src/test/java/org/wikimedia/highlighter/experimental/lucene/LuceneMatchers.java index 3744d32..6895db1 100644 --- a/experimental-highlighter-lucene/src/test/java/org/wikimedia/highlighter/experimental/lucene/LuceneMatchers.java +++ b/experimental-highlighter-lucene/src/test/java/org/wikimedia/highlighter/experimental/lucene/LuceneMatchers.java @@ -8,7 +8,7 @@ import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; -public class LuceneMatchers { +public final class LuceneMatchers { public static Matcher<Automaton> recognises(Term t) { return new AutomatonMatchesBytesMatcher(t.bytes()); } @@ -21,10 +21,14 @@ return new AutomatonMatchesBytesMatcher(new BytesRef(s)); } + private LuceneMatchers() { + // utility class + } + private static class AutomatonMatchesBytesMatcher extends TypeSafeMatcher<Automaton> { private final BytesRef term; - public AutomatonMatchesBytesMatcher(BytesRef term) { + AutomatonMatchesBytesMatcher(BytesRef term) { this.term = term; } diff --git a/experimental-highlighter-lucene/src/test/java/org/wikimedia/highlighter/experimental/lucene/QueryFlattenerTest.java b/experimental-highlighter-lucene/src/test/java/org/wikimedia/highlighter/experimental/lucene/QueryFlattenerTest.java index d0a8f9a..8dd0911 100644 --- a/experimental-highlighter-lucene/src/test/java/org/wikimedia/highlighter/experimental/lucene/QueryFlattenerTest.java +++ b/experimental-highlighter-lucene/src/test/java/org/wikimedia/highlighter/experimental/lucene/QueryFlattenerTest.java @@ -1,6 +1,25 @@ package org.wikimedia.highlighter.experimental.lucene; -import com.google.common.collect.Lists; +import static org.hamcrest.Matchers.not; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyFloat; +import static org.mockito.Matchers.anyInt; +import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.eq; +import static org.mockito.Matchers.isNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.wikimedia.highlighter.experimental.lucene.LuceneMatchers.recognises; + +import java.io.Closeable; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + import org.apache.lucene.analysis.core.KeywordAnalyzer; import org.apache.lucene.document.Field; import org.apache.lucene.document.TextField; @@ -30,25 +49,7 @@ import org.mockito.ArgumentCaptor; import org.wikimedia.highlighter.experimental.lucene.QueryFlattener.Callback; -import java.io.Closeable; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import static org.hamcrest.Matchers.not; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyFloat; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.isNull; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static org.wikimedia.highlighter.experimental.lucene.LuceneMatchers.recognises; +import com.google.common.collect.Lists; public class QueryFlattenerTest extends LuceneTestCase { private final List<Closeable> toClose = new ArrayList<>(); diff --git a/experimental-highlighter-lucene/src/test/java/org/wikimedia/highlighter/experimental/lucene/hit/AbstractHitEnumTestBase.java b/experimental-highlighter-lucene/src/test/java/org/wikimedia/highlighter/experimental/lucene/hit/AbstractHitEnumTestBase.java index d8b742e..6f788fc 100644 --- a/experimental-highlighter-lucene/src/test/java/org/wikimedia/highlighter/experimental/lucene/hit/AbstractHitEnumTestBase.java +++ b/experimental-highlighter-lucene/src/test/java/org/wikimedia/highlighter/experimental/lucene/hit/AbstractHitEnumTestBase.java @@ -1,15 +1,18 @@ package org.wikimedia.highlighter.experimental.lucene.hit; -import com.carrotsearch.randomizedtesting.RandomizedRunner; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.wikimedia.highlighter.experimental.Matchers.advances; +import static org.wikimedia.highlighter.experimental.Matchers.hit; +import static org.wikimedia.highlighter.experimental.Matchers.isEmpty; + import org.junit.Test; import org.junit.runner.RunWith; import org.wikimedia.search.highlighter.experimental.HitEnum; import org.wikimedia.search.highlighter.experimental.SourceExtracter; import org.wikimedia.search.highlighter.experimental.source.StringSourceExtracter; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.wikimedia.highlighter.experimental.Matchers.*; +import com.carrotsearch.randomizedtesting.RandomizedRunner; /** * XXX: copied from core (tests dependencies are troublesome) diff --git a/experimental-highlighter-lucene/src/test/java/org/wikimedia/highlighter/experimental/lucene/hit/AbstractLuceneHitEnumTestBase.java b/experimental-highlighter-lucene/src/test/java/org/wikimedia/highlighter/experimental/lucene/hit/AbstractLuceneHitEnumTestBase.java index 0e76aa9..fe7962e 100644 --- a/experimental-highlighter-lucene/src/test/java/org/wikimedia/highlighter/experimental/lucene/hit/AbstractLuceneHitEnumTestBase.java +++ b/experimental-highlighter-lucene/src/test/java/org/wikimedia/highlighter/experimental/lucene/hit/AbstractLuceneHitEnumTestBase.java @@ -11,7 +11,6 @@ import org.apache.lucene.util.automaton.CharacterRunAutomaton; import org.apache.lucene.util.automaton.RegExp; import org.junit.After; -import org.wikimedia.highlighter.experimental.lucene.hit.AbstractHitEnumTestBase; /** * Base class for tests for Lucene based HitEnums. @@ -19,14 +18,14 @@ public abstract class AbstractLuceneHitEnumTestBase extends AbstractHitEnumTestBase { private final List<TokenStream> builtStreams = new ArrayList<TokenStream>(); private final List<Analyzer> builtAnalyzers = new ArrayList<Analyzer>(); - + protected Analyzer mockAnalyzer() { // Pretty much MockTokenizer.WHITESPACE with a "." added in to make sentences a bit more sane. CharacterRunAutomaton tokenizer = new CharacterRunAutomaton( new RegExp("[^ \t\r\n\\.]+").toAutomaton()); return trackAnalyzer(new MockAnalyzer(new Random(), tokenizer, true)); } - + protected Analyzer trackAnalyzer(Analyzer analyzer) { builtAnalyzers.add(analyzer); return analyzer; diff --git a/experimental-highlighter-lucene/src/test/java/org/wikimedia/highlighter/experimental/lucene/hit/AutomatonHitEnumTest.java b/experimental-highlighter-lucene/src/test/java/org/wikimedia/highlighter/experimental/lucene/hit/AutomatonHitEnumTest.java index 69f40af..f62a836 100644 --- a/experimental-highlighter-lucene/src/test/java/org/wikimedia/highlighter/experimental/lucene/hit/AutomatonHitEnumTest.java +++ b/experimental-highlighter-lucene/src/test/java/org/wikimedia/highlighter/experimental/lucene/hit/AutomatonHitEnumTest.java @@ -10,7 +10,6 @@ import org.junit.Test; import org.wikimedia.search.highlighter.experimental.HitEnum; import org.wikimedia.search.highlighter.experimental.SourceExtracter; -import org.wikimedia.highlighter.experimental.lucene.hit.AbstractHitEnumTestBase; import org.wikimedia.search.highlighter.experimental.source.StringSourceExtracter; public class AutomatonHitEnumTest extends AbstractHitEnumTestBase { -- To view, visit https://gerrit.wikimedia.org/r/381879 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I8e0a266f2625f812ca2335716c0e5cb52a86944c Gerrit-PatchSet: 2 Gerrit-Project: search/highlighter Gerrit-Branch: master Gerrit-Owner: Gehel <guillaume.leder...@wikimedia.org> Gerrit-Reviewer: DCausse <dcau...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits