LUCENE-7058: Add getters for various Query implementations

This commit is contained in:
Alan Woodward 2016-03-03 11:13:29 +00:00
parent 4c4313889f
commit 682b179605
21 changed files with 278 additions and 1 deletions

View File

@ -119,6 +119,9 @@ API Changes
* LUCENE-7060: Update Spatial4j to 0.6. The package com.spatial4j.core
is now org.locationtech.spatial4j. (David Smiley)
* LUCENE-7058: Add getters to various Query implementations (Guillaume Smet via
Alan Woodward)
Optimizations
* LUCENE-6891: Use prefix coding when writing points in

View File

@ -38,6 +38,10 @@ public final class FieldValueQuery extends Query {
this.field = Objects.requireNonNull(field);
}
public String getField() {
return field;
}
@Override
public boolean equals(Object obj) {
if (super.equals(obj) == false) {

View File

@ -104,6 +104,9 @@ final class MultiTermQueryConstantScoreWrapper<Q extends MultiTermQuery> extends
return 31 * super.hashCode() + query.hashCode();
}
/** Returns the encapsulated query */
public Q getQuery() { return query; }
/** Returns the field name for this query */
public final String getField() { return query.getField(); }

View File

@ -94,6 +94,11 @@ public class NGramPhraseQuery extends Query {
return h;
}
/** Return the n in n-gram */
public int getN() {
return n;
}
/** Return the list of terms. */
public Term[] getTerms() {
return phraseQuery.getTerms();

View File

@ -109,7 +109,12 @@ public class RegexpQuery extends AutomatonQuery {
new RegExp(term.text(), flags).toAutomaton(
provider, maxDeterminizedStates), maxDeterminizedStates);
}
/** Returns the regexp of this query wrapped in a Term. */
public Term getRegexp() {
return term;
}
/** Prints a user-readable version of this query. */
@Override
public String toString(String field) {

View File

@ -20,6 +20,7 @@ package org.apache.lucene.search;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Set;
@ -67,6 +68,10 @@ public final class SynonymQuery extends Query {
Arrays.sort(this.terms);
}
public List<Term> getTerms() {
return Collections.unmodifiableList(Arrays.asList(terms));
}
@Override
public String toString(String field) {
StringBuilder builder = new StringBuilder("Synonym(");

View File

@ -47,6 +47,14 @@ abstract class SpanContainQuery extends SpanQuery implements Cloneable {
@Override
public String getField() { return big.getField(); }
public SpanQuery getBig() {
return big;
}
public SpanQuery getLittle() {
return little;
}
public abstract class SpanContainWeight extends SpanWeight {

View File

@ -139,6 +139,18 @@ public class BoostingQuery extends Query {
return 31 * super.hashCode() + Objects.hash(match, context, boost);
}
public Query getMatch() {
return match;
}
public Query getContext() {
return context;
}
public float getBoost() {
return boost;
}
@Override
public boolean equals(Object obj) {
if (super.equals(obj) == false) {

View File

@ -18,6 +18,7 @@ package org.apache.lucene.queries;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.lucene.index.Fields;
@ -338,6 +339,49 @@ public class CommonTermsQuery extends Query {
return highFreqMinNrShouldMatch;
}
/**
* Gets the list of terms.
*/
public List<Term> getTerms() {
return Collections.unmodifiableList(terms);
}
/**
* Gets the maximum threshold of a terms document frequency to be considered a
* low frequency term.
*/
public float getMaxTermFrequency() {
return maxTermFrequency;
}
/**
* Gets the {@link Occur} used for low frequency terms.
*/
public Occur getLowFreqOccur() {
return lowFreqOccur;
}
/**
* Gets the {@link Occur} used for high frequency terms.
*/
public Occur getHighFreqOccur() {
return highFreqOccur;
}
/**
* Gets the boost used for low frequency terms.
*/
public float getLowFreqBoost() {
return lowFreqBoost;
}
/**
* Gets the boost used for high frequency terms.
*/
public float getHighFreqBoost() {
return highFreqBoost;
}
@Override
public String toString(String field) {
StringBuilder buffer = new StringBuilder();

View File

@ -185,6 +185,11 @@ public class TermsQuery extends Query implements Accountable {
return 31 * super.hashCode() + termDataHashCode;
}
/** Returns the terms wrapped in a PrefixCodedTerms. */
public PrefixCodedTerms getTermData() {
return termData;
}
@Override
public String toString(String defaultField) {
StringBuilder builder = new StringBuilder();

View File

@ -67,6 +67,26 @@ public class FunctionRangeQuery extends Query {
this.includeUpper = includeUpper;
}
public ValueSource getValueSource() {
return valueSource;
}
public String getLowerVal() {
return lowerVal;
}
public String getUpperVal() {
return upperVal;
}
public boolean isIncludeLower() {
return includeLower;
}
public boolean isIncludeUpper() {
return includeUpper;
}
@Override
public String toString(String field) {
return "frange(" + valueSource + "):"

View File

@ -147,6 +147,22 @@ final class LatLonPointDistanceQuery extends Query {
};
}
public String getField() {
return field;
}
public double getLatitude() {
return latitude;
}
public double getLongitude() {
return longitude;
}
public double getRadiusMeters() {
return radiusMeters;
}
@Override
public int hashCode() {
final int prime = 31;

View File

@ -177,6 +177,34 @@ final class LatLonPointInPolygonQuery extends Query {
};
}
public String getField() {
return field;
}
public double getMinLat() {
return minLat;
}
public double getMaxLat() {
return maxLat;
}
public double getMinLon() {
return minLon;
}
public double getMaxLon() {
return maxLon;
}
public double[] getPolyLats() {
return polyLats;
}
public double[] getPolyLons() {
return polyLons;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;

View File

@ -75,6 +75,14 @@ public class DocValuesNumbersQuery extends Query {
return 31 * super.hashCode() + Objects.hash(field, numbers);
}
public String getField() {
return field;
}
public Set<Long> getNumbers() {
return numbers;
}
@Override
public String toString(String defaultField) {
StringBuilder sb = new StringBuilder();

View File

@ -96,6 +96,26 @@ public final class DocValuesRangeQuery extends Query {
return 31 * super.hashCode() + Objects.hash(field, lowerVal, upperVal, includeLower, includeUpper);
}
public String getField() {
return field;
}
public Object getLowerVal() {
return lowerVal;
}
public Object getUpperVal() {
return upperVal;
}
public boolean isIncludeLower() {
return includeLower;
}
public boolean isIncludeUpper() {
return includeUpper;
}
@Override
public String toString(String field) {
StringBuilder sb = new StringBuilder();

View File

@ -54,6 +54,13 @@ final class GeoPointTermQueryConstantScoreWrapper <Q extends GeoPointMultiTermQu
this.query = query;
}
/**
* Returns the encapsulated query.
*/
public Q getQuery() {
return query;
}
@Override
public String toString(String field) {
return query.toString();

View File

@ -161,6 +161,18 @@ class PointInGeo3DShapeQuery extends Query {
};
}
public String getField() {
return field;
}
public PlanetModel getPlanetModel() {
return planetModel;
}
public GeoShape getShape() {
return shape;
}
@Override
@SuppressWarnings({"unchecked","rawtypes"})
public boolean equals(Object o) {

View File

@ -196,6 +196,48 @@ public class FuzzyCompletionQuery extends PrefixCompletionQuery {
}
}
/**
* Get the maximum edit distance for fuzzy matches
*/
public int getMaxEdits() {
return maxEdits;
}
/**
* Return whether transpositions count as a single edit
*/
public boolean isTranspositions() {
return transpositions;
}
/**
* Get the length of a prefix where no edits are permitted
*/
public int getNonFuzzyPrefix() {
return nonFuzzyPrefix;
}
/**
* Get the minimum length of a term considered for matching
*/
public int getMinFuzzyLength() {
return minFuzzyLength;
}
/**
* Return true if lengths are measured in unicode code-points rather than bytes
*/
public boolean isUnicodeAware() {
return unicodeAware;
}
/**
* Get the maximum number of determinized states permitted
*/
public int getMaxDeterminizedStates() {
return maxDeterminizedStates;
}
@Override
public String toString(String field) {
StringBuilder buffer = new StringBuilder();

View File

@ -70,4 +70,11 @@ public class PrefixCompletionQuery extends CompletionQuery {
CompletionTokenStream stream = (CompletionTokenStream) analyzer.tokenStream(getField(), getTerm().text());
return new CompletionWeight(this, stream.toAutomaton());
}
/**
* Gets the analyzer used to analyze the prefix.
*/
public Analyzer getAnalyzer() {
return analyzer;
}
}

View File

@ -91,4 +91,19 @@ public class RegexCompletionQuery extends CompletionQuery {
public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
return new CompletionWeight(this, new RegExp(getTerm().text(), flags).toAutomaton(maxDeterminizedStates));
}
/**
* Get the regex flags
*/
public int getFlags() {
return flags;
}
/**
* Get the maximum number of states permitted in the determinized automaton
*/
public int getMaxDeterminizedStates() {
return maxDeterminizedStates;
}
}

View File

@ -62,6 +62,14 @@ public final class AssertingQuery extends Query {
return -in.hashCode();
}
public Random getRandom() {
return random;
}
public Query getIn() {
return in;
}
@Override
public Query rewrite(IndexReader reader) throws IOException {
final Query rewritten = in.rewrite(reader);