mirror of https://github.com/apache/lucene.git
[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
This commit is contained in:
parent
991bbd7b57
commit
7d3d213c04
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -107,8 +107,8 @@ public class CustomScoreQuery extends Query {
|
|||
@Override
|
||||
public void extractTerms(Set<Term> 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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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<Term> 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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -172,5 +172,5 @@ public class IntFieldSource extends FieldCacheSource {
|
|||
int h = parser==null ? Integer.class.hashCode() : parser.getClass().hashCode();
|
||||
h += super.hashCode();
|
||||
return h;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue