From 7d3d213c04fd260c41feee310b315404c7fa9689 Mon Sep 17 00:00:00 2001 From: Tommaso Teofili Date: Fri, 22 Jun 2012 08:17:34 +0000 Subject: [PATCH] [LUCENE-4159] - lucene queries review: adding final modifiers, removing trailing semicolons, using for each loops instead of index based iterations git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1352795 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/lucene/queries/BoostingQuery.java | 6 ++-- .../apache/lucene/queries/ChainedFilter.java | 2 +- .../lucene/queries/CustomScoreProvider.java | 12 +++---- .../lucene/queries/CustomScoreQuery.java | 34 +++++++++---------- .../apache/lucene/queries/TermsFilter.java | 3 +- .../lucene/queries/function/BoostedQuery.java | 4 +-- .../queries/function/FunctionQuery.java | 6 ++-- .../queries/function/FunctionValues.java | 2 +- .../lucene/queries/function/ValueSource.java | 4 +-- .../queries/function/ValueSourceScorer.java | 2 +- .../function/valuesource/ByteFieldSource.java | 2 +- .../valuesource/DocFreqValueSource.java | 8 ++--- .../valuesource/DoubleFieldSource.java | 2 +- .../valuesource/FieldCacheSource.java | 6 ++-- .../valuesource/FloatFieldSource.java | 4 +-- .../function/valuesource/IfFunction.java | 6 ++-- .../function/valuesource/IntFieldSource.java | 2 +- .../valuesource/JoinDocFreqValueSource.java | 7 ++-- .../valuesource/LiteralValueSource.java | 3 +- .../function/valuesource/LongFieldSource.java | 2 +- .../function/valuesource/NormValueSource.java | 2 +- .../function/valuesource/OrdFieldSource.java | 4 +-- .../valuesource/QueryValueSource.java | 1 - .../valuesource/ReverseOrdFieldSource.java | 4 +-- .../SumTotalTermFreqValueSource.java | 2 +- .../valuesource/TotalTermFreqValueSource.java | 8 ++--- .../valuesource/VectorValueSource.java | 3 +- .../lucene/queries/mlt/MoreLikeThis.java | 4 +-- .../lucene/queries/mlt/MoreLikeThisQuery.java | 4 +-- 29 files changed, 73 insertions(+), 76 deletions(-) diff --git a/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java index 191b2909fa4..037879ee7ab 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java @@ -38,9 +38,9 @@ import org.apache.lucene.search.*; * and is documented here: http://wiki.apache.org/lucene-java/CommunityContributions */ public class BoostingQuery extends Query { - private float boost; // the amount to boost by - private Query match; // query to match - private Query context; // boost when matches too + private final float boost; // the amount to boost by + private final Query match; // query to match + private final Query context; // boost when matches too public BoostingQuery(Query match, Query context, float boost) { this.match = match; diff --git a/lucene/queries/src/java/org/apache/lucene/queries/ChainedFilter.java b/lucene/queries/src/java/org/apache/lucene/queries/ChainedFilter.java index 0626a80f0bd..6f8c9a807eb 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/ChainedFilter.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/ChainedFilter.java @@ -53,7 +53,7 @@ public class ChainedFilter extends Filter { /** * Logical operation when none is declared. Defaults to OR. */ - public static int DEFAULT = OR; + public static final int DEFAULT = OR; /** * The filter chain diff --git a/lucene/queries/src/java/org/apache/lucene/queries/CustomScoreProvider.java b/lucene/queries/src/java/org/apache/lucene/queries/CustomScoreProvider.java index 45a6888ab2a..862334c14d0 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/CustomScoreProvider.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/CustomScoreProvider.java @@ -78,8 +78,8 @@ public class CustomScoreProvider { return customScore(doc, subQueryScore, 1); } float score = subQueryScore; - for(int i = 0; i < valSrcScores.length; i++) { - score *= valSrcScores[i]; + for (float valSrcScore : valSrcScores) { + score *= valSrcScore; } return score; } @@ -127,13 +127,13 @@ public class CustomScoreProvider { return subQueryExpl; } float valSrcScore = 1; - for (int i = 0; i < valSrcExpls.length; i++) { - valSrcScore *= valSrcExpls[i].getValue(); + for (Explanation valSrcExpl : valSrcExpls) { + valSrcScore *= valSrcExpl.getValue(); } Explanation exp = new Explanation( valSrcScore * subQueryExpl.getValue(), "custom score: product of:"); exp.addDetail(subQueryExpl); - for (int i = 0; i < valSrcExpls.length; i++) { - exp.addDetail(valSrcExpls[i]); + for (Explanation valSrcExpl : valSrcExpls) { + exp.addDetail(valSrcExpl); } return exp; } diff --git a/lucene/queries/src/java/org/apache/lucene/queries/CustomScoreQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/CustomScoreQuery.java index 11d84e973e3..500ca7ac0f8 100755 --- a/lucene/queries/src/java/org/apache/lucene/queries/CustomScoreQuery.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/CustomScoreQuery.java @@ -107,8 +107,8 @@ public class CustomScoreQuery extends Query { @Override public void extractTerms(Set terms) { subQuery.extractTerms(terms); - for(int i = 0; i < scoringQueries.length; i++) { - scoringQueries[i].extractTerms(terms); + for (Query scoringQuery : scoringQueries) { + scoringQuery.extractTerms(terms); } } @@ -129,8 +129,8 @@ public class CustomScoreQuery extends Query { public String toString(String field) { StringBuilder sb = new StringBuilder(name()).append("("); sb.append(subQuery.toString(field)); - for(int i = 0; i < scoringQueries.length; i++) { - sb.append(", ").append(scoringQueries[i].toString(field)); + for (Query scoringQuery : scoringQueries) { + sb.append(", ").append(scoringQuery.toString(field)); } sb.append(")"); sb.append(strict?" STRICT" : ""); @@ -199,11 +199,11 @@ public class CustomScoreQuery extends Query { @Override public float getValueForNormalization() throws IOException { float sum = subQueryWeight.getValueForNormalization(); - for(int i = 0; i < valSrcWeights.length; i++) { + for (Weight valSrcWeight : valSrcWeights) { if (qStrict) { - valSrcWeights[i].getValueForNormalization(); // do not include ValueSource part in the query normalization + valSrcWeight.getValueForNormalization(); // do not include ValueSource part in the query normalization } else { - sum += valSrcWeights[i].getValueForNormalization(); + sum += valSrcWeight.getValueForNormalization(); } } sum *= getBoost() * getBoost(); // boost each sub-weight @@ -215,11 +215,11 @@ public class CustomScoreQuery extends Query { public void normalize(float norm, float topLevelBoost) { topLevelBoost *= getBoost(); // incorporate boost subQueryWeight.normalize(norm, topLevelBoost); - for(int i = 0; i < valSrcWeights.length; i++) { + for (Weight valSrcWeight : valSrcWeights) { if (qStrict) { - valSrcWeights[i].normalize(1, 1); // do not normalize the ValueSource part + valSrcWeight.normalize(1, 1); // do not normalize the ValueSource part } else { - valSrcWeights[i].normalize(norm, topLevelBoost); + valSrcWeight.normalize(norm, topLevelBoost); } } } @@ -283,10 +283,10 @@ public class CustomScoreQuery extends Query { */ private class CustomScorer extends Scorer { private final float qWeight; - private Scorer subQueryScorer; - private Scorer[] valSrcScorers; + private final Scorer subQueryScorer; + private final Scorer[] valSrcScorers; private final CustomScoreProvider provider; - private float vScores[]; // reused in score() to avoid allocating this array for each doc + private final float[] vScores; // reused in score() to avoid allocating this array for each doc // constructor private CustomScorer(CustomScoreProvider provider, CustomWeight w, float qWeight, @@ -303,8 +303,8 @@ public class CustomScoreQuery extends Query { public int nextDoc() throws IOException { int doc = subQueryScorer.nextDoc(); if (doc != NO_MORE_DOCS) { - for (int i = 0; i < valSrcScorers.length; i++) { - valSrcScorers[i].advance(doc); + for (Scorer valSrcScorer : valSrcScorers) { + valSrcScorer.advance(doc); } } return doc; @@ -328,8 +328,8 @@ public class CustomScoreQuery extends Query { public int advance(int target) throws IOException { int doc = subQueryScorer.advance(target); if (doc != NO_MORE_DOCS) { - for (int i = 0; i < valSrcScorers.length; i++) { - valSrcScorers[i].advance(doc); + for (Scorer valSrcScorer : valSrcScorers) { + valSrcScorer.advance(doc); } } return doc; diff --git a/lucene/queries/src/java/org/apache/lucene/queries/TermsFilter.java b/lucene/queries/src/java/org/apache/lucene/queries/TermsFilter.java index ac4d411a00c..a50a91f0782 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/TermsFilter.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/TermsFilter.java @@ -65,7 +65,7 @@ public class TermsFilter extends Filter { BytesRef br = new BytesRef(); String lastField = null; - Terms termsC = null; + Terms termsC; TermsEnum termsEnum = null; DocsEnum docs = null; for (Term term : terms) { @@ -80,6 +80,7 @@ public class TermsFilter extends Filter { if (terms != null) { // TODO this check doesn't make sense, decide which variable its supposed to be for br.copyBytes(term.bytes()); + assert termsEnum != null; if (termsEnum.seekCeil(br) == TermsEnum.SeekStatus.FOUND) { docs = termsEnum.docs(acceptDocs, docs, false); while (docs.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) { diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/BoostedQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/function/BoostedQuery.java index 91d98321d3e..f2b22caeaa1 100755 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/BoostedQuery.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/BoostedQuery.java @@ -35,7 +35,7 @@ import java.util.Map; // something has to give public class BoostedQuery extends Query { private Query q; - private ValueSource boostVal; // optional, can be null + private final ValueSource boostVal; // optional, can be null public BoostedQuery(Query subQuery, ValueSource boostVal) { this.q = subQuery; @@ -65,7 +65,7 @@ public class BoostedQuery extends Query { } private class BoostedWeight extends Weight { - IndexSearcher searcher; + final IndexSearcher searcher; Weight qWeight; Map fcontext; diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java index a6211de90e4..bba3219dc25 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java @@ -38,7 +38,7 @@ import java.util.Map; * */ public class FunctionQuery extends Query { - ValueSource func; + final ValueSource func; /** * @param func defines the function to be used for scoring @@ -61,10 +61,10 @@ public class FunctionQuery extends Query { public void extractTerms(Set terms) {} protected class FunctionWeight extends Weight { - protected IndexSearcher searcher; + protected final IndexSearcher searcher; protected float queryNorm; protected float queryWeight; - protected Map context; + protected final Map context; public FunctionWeight(IndexSearcher searcher) throws IOException { this.searcher = searcher; diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionValues.java b/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionValues.java index d0866d54252..c1890f42d56 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionValues.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionValues.java @@ -61,7 +61,7 @@ public abstract class FunctionValues { } target.copyChars(s); return true; - }; + } /** Native Java Object representation of the value */ public Object objectVal(int doc) { diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/ValueSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/ValueSource.java index e4894ee33bf..91c94cf4f9c 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/ValueSource.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/ValueSource.java @@ -131,7 +131,7 @@ public abstract class ValueSource { private final double[] values; private FunctionValues docVals; private double bottom; - private Map fcontext; + private final Map fcontext; ValueSourceComparator(Map fcontext, int numHits) { this.fcontext = fcontext; @@ -187,7 +187,7 @@ public abstract class ValueSource { @Override public int compareDocToValue(int doc, Double valueObj) { - final double value = valueObj.doubleValue(); + final double value = valueObj; final double docValue = docVals.doubleVal(doc); if (docValue < value) { return -1; diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/ValueSourceScorer.java b/lucene/queries/src/java/org/apache/lucene/queries/function/ValueSourceScorer.java index 975bd4b63c1..0401a950c79 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/ValueSourceScorer.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/ValueSourceScorer.java @@ -25,7 +25,7 @@ import org.apache.lucene.util.Bits; import java.io.IOException; public class ValueSourceScorer extends Scorer { - protected IndexReader reader; + protected final IndexReader reader; private int doc = -1; protected final int maxDoc; protected final FunctionValues values; diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ByteFieldSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ByteFieldSource.java index 59195d0df71..c11ee78f3e6 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ByteFieldSource.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ByteFieldSource.java @@ -33,7 +33,7 @@ import org.apache.lucene.search.FieldCache; public class ByteFieldSource extends FieldCacheSource { - private FieldCache.ByteParser parser; + private final FieldCache.ByteParser parser; public ByteFieldSource(String field) { this(field, null); diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DocFreqValueSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DocFreqValueSource.java index 1c70ce2b4c7..3b42539f382 100755 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DocFreqValueSource.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DocFreqValueSource.java @@ -124,10 +124,10 @@ class ConstDoubleDocValues extends DoubleDocValues { * @lucene.internal */ public class DocFreqValueSource extends ValueSource { - protected String field; - protected String indexedField; - protected String val; - protected BytesRef indexedBytes; + protected final String field; + protected final String indexedField; + protected final String val; + protected final BytesRef indexedBytes; public DocFreqValueSource(String field, String val, String indexedField, BytesRef indexedBytes) { this.field = field; diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DoubleFieldSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DoubleFieldSource.java index fc6e27d594d..97f2414ee0c 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DoubleFieldSource.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DoubleFieldSource.java @@ -40,7 +40,7 @@ import org.apache.lucene.util.mutable.MutableValueDouble; public class DoubleFieldSource extends FieldCacheSource { - protected FieldCache.DoubleParser parser; + protected final FieldCache.DoubleParser parser; public DoubleFieldSource(String field) { this(field, null); diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/FieldCacheSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/FieldCacheSource.java index 292d438b7ad..ebdb72c7e86 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/FieldCacheSource.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/FieldCacheSource.java @@ -27,8 +27,8 @@ import org.apache.lucene.search.FieldCache; * */ public abstract class FieldCacheSource extends ValueSource { - protected String field; - protected FieldCache cache = FieldCache.DEFAULT; + protected final String field; + protected final FieldCache cache = FieldCache.DEFAULT; public FieldCacheSource(String field) { this.field=field; @@ -58,6 +58,6 @@ public abstract class FieldCacheSource extends ValueSource { @Override public int hashCode() { return cache.hashCode() + field.hashCode(); - }; + } } diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/FloatFieldSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/FloatFieldSource.java index c9e44019fb8..4486bd09250 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/FloatFieldSource.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/FloatFieldSource.java @@ -38,7 +38,7 @@ import org.apache.lucene.util.mutable.MutableValueFloat; public class FloatFieldSource extends FieldCacheSource { - protected FieldCache.FloatParser parser; + protected final FieldCache.FloatParser parser; public FloatFieldSource(String field) { this(field, null); @@ -108,5 +108,5 @@ public class FloatFieldSource extends FieldCacheSource { int h = parser==null ? Float.class.hashCode() : parser.getClass().hashCode(); h += super.hashCode(); return h; - }; + } } diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/IfFunction.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/IfFunction.java index faa08f8c584..ff693b5c9ab 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/IfFunction.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/IfFunction.java @@ -31,9 +31,9 @@ import java.util.Map; public class IfFunction extends BoolFunction { - private ValueSource ifSource; - private ValueSource trueSource; - private ValueSource falseSource; + private final ValueSource ifSource; + private final ValueSource trueSource; + private final ValueSource falseSource; public IfFunction(ValueSource ifSource, ValueSource trueSource, ValueSource falseSource) { diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/IntFieldSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/IntFieldSource.java index fbdbf7c87be..8efe2de953d 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/IntFieldSource.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/IntFieldSource.java @@ -172,5 +172,5 @@ public class IntFieldSource extends FieldCacheSource { int h = parser==null ? Integer.class.hashCode() : parser.getClass().hashCode(); h += super.hashCode(); return h; - }; + } } diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/JoinDocFreqValueSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/JoinDocFreqValueSource.java index 490f1421fce..d1fe9390a12 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/JoinDocFreqValueSource.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/JoinDocFreqValueSource.java @@ -57,16 +57,15 @@ public class JoinDocFreqValueSource extends FieldCacheSource { final IndexReader top = ReaderUtil.getTopLevelContext(readerContext).reader(); return new IntDocValues(this) { - BytesRef ref = new BytesRef(); + final BytesRef ref = new BytesRef(); @Override public int intVal(int doc) { try { terms.getTerm(doc, ref); - int v = top.docFreq( qfield, ref ); //System.out.println( NAME+"["+field+"="+ref.utf8ToString()+"=("+qfield+":"+v+")]" ); - return v; + return top.docFreq( qfield, ref ); } catch (IOException e) { throw new RuntimeException("caught exception in function "+description()+" : doc="+doc, e); @@ -86,5 +85,5 @@ public class JoinDocFreqValueSource extends FieldCacheSource { @Override public int hashCode() { return qfield.hashCode() + super.hashCode(); - }; + } } diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/LiteralValueSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/LiteralValueSource.java index c8cde6d33b6..1762a80abc2 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/LiteralValueSource.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/LiteralValueSource.java @@ -78,9 +78,8 @@ public class LiteralValueSource extends ValueSource { LiteralValueSource that = (LiteralValueSource) o; - if (!string.equals(that.string)) return false; + return string.equals(that.string); - return true; } public static final int hash = LiteralValueSource.class.hashCode(); diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/LongFieldSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/LongFieldSource.java index 7b90603d123..58a1d68aa56 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/LongFieldSource.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/LongFieldSource.java @@ -40,7 +40,7 @@ import org.apache.lucene.util.mutable.MutableValueLong; public class LongFieldSource extends FieldCacheSource { - protected FieldCache.LongParser parser; + protected final FieldCache.LongParser parser; public LongFieldSource(String field) { this(field, null); diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/NormValueSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/NormValueSource.java index 7295dce5fa4..88b357c5b4d 100755 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/NormValueSource.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/NormValueSource.java @@ -29,7 +29,7 @@ import java.io.IOException; import java.util.Map; public class NormValueSource extends ValueSource { - protected String field; + protected final String field; public NormValueSource(String field) { this.field = field; } diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/OrdFieldSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/OrdFieldSource.java index 8a95d8f8da7..2f46eeb663b 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/OrdFieldSource.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/OrdFieldSource.java @@ -52,7 +52,7 @@ import java.util.Map; */ public class OrdFieldSource extends ValueSource { - protected String field; + protected final String field; public OrdFieldSource(String field) { this.field = field; @@ -124,6 +124,6 @@ public class OrdFieldSource extends ValueSource { @Override public int hashCode() { return hcode + field.hashCode(); - }; + } } diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/QueryValueSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/QueryValueSource.java index 5cd2a035730..df470560bdc 100755 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/QueryValueSource.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/QueryValueSource.java @@ -237,7 +237,6 @@ class QueryDocValues extends FloatDocValues { // a match! mval.value = scorer.score(); mval.exists = true; - return; } catch (IOException e) { throw new RuntimeException("caught exception in QueryDocVals("+q+") doc="+doc, e); } diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ReverseOrdFieldSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ReverseOrdFieldSource.java index a36ee02f3a0..5accef9061a 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ReverseOrdFieldSource.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ReverseOrdFieldSource.java @@ -53,7 +53,7 @@ import java.util.Map; */ public class ReverseOrdFieldSource extends ValueSource { - public String field; + public final String field; public ReverseOrdFieldSource(String field) { this.field = field; @@ -95,6 +95,6 @@ public class ReverseOrdFieldSource extends ValueSource { @Override public int hashCode() { return hcode + field.hashCode(); - }; + } } diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/SumTotalTermFreqValueSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/SumTotalTermFreqValueSource.java index 1e833fa3cff..54e9dac08fb 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/SumTotalTermFreqValueSource.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/SumTotalTermFreqValueSource.java @@ -34,7 +34,7 @@ import java.util.Map; * @lucene.internal */ public class SumTotalTermFreqValueSource extends ValueSource { - protected String indexedField; + protected final String indexedField; public SumTotalTermFreqValueSource(String indexedField) { this.indexedField = indexedField; diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/TotalTermFreqValueSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/TotalTermFreqValueSource.java index 42c8648004a..52cede17cc0 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/TotalTermFreqValueSource.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/TotalTermFreqValueSource.java @@ -32,10 +32,10 @@ import java.util.Map; * @lucene.internal */ public class TotalTermFreqValueSource extends ValueSource { - protected String field; - protected String indexedField; - protected String val; - protected BytesRef indexedBytes; + protected final String field; + protected final String indexedField; + protected final String val; + protected final BytesRef indexedBytes; public TotalTermFreqValueSource(String field, String val, String indexedField, BytesRef indexedBytes) { this.field = field; diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/VectorValueSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/VectorValueSource.java index f0107dfcba8..8d443b420a2 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/VectorValueSource.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/VectorValueSource.java @@ -210,9 +210,8 @@ public class VectorValueSource extends MultiValueSource { VectorValueSource that = (VectorValueSource) o; - if (!sources.equals(that.sources)) return false; + return sources.equals(that.sources); - return true; } @Override diff --git a/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThis.java b/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThis.java index 6229a0c8500..d8b97762782 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThis.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThis.java @@ -717,8 +717,8 @@ public final class MoreLikeThis { if (vector == null) { Document d = ir.document(docNum); IndexableField fields[] = d.getFields(fieldName); - for (int j = 0; j < fields.length; j++) { - final String stringValue = fields[j].stringValue(); + for (IndexableField field : fields) { + final String stringValue = field.stringValue(); if (stringValue != null) { addTermFrequencies(new StringReader(stringValue), termFreqMap, fieldName); } diff --git a/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThisQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThisQuery.java index 74e0dfa0662..1931e721eea 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThisQuery.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThisQuery.java @@ -41,7 +41,7 @@ public class MoreLikeThisQuery extends Query { private String likeText; private String[] moreLikeFields; private Analyzer analyzer; - private String fieldName; + private final String fieldName; private float percentTermsToMatch = 0.3f; private int minTermFrequency = 1; private int maxQueryTerms = 5; @@ -49,7 +49,7 @@ public class MoreLikeThisQuery extends Query { private int minDocFreq = -1; /** - * @param moreLikeFields + * @param moreLikeFields fields used for similarity measure */ public MoreLikeThisQuery(String likeText, String[] moreLikeFields, Analyzer analyzer, String fieldName) { this.likeText = likeText;