diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 144bb2e4c2b..27d9a183bb4 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -116,6 +116,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 diff --git a/lucene/core/src/java/org/apache/lucene/search/FieldValueQuery.java b/lucene/core/src/java/org/apache/lucene/search/FieldValueQuery.java index e73b8971d42..4bc081c460e 100644 --- a/lucene/core/src/java/org/apache/lucene/search/FieldValueQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/FieldValueQuery.java @@ -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) { diff --git a/lucene/core/src/java/org/apache/lucene/search/MultiTermQueryConstantScoreWrapper.java b/lucene/core/src/java/org/apache/lucene/search/MultiTermQueryConstantScoreWrapper.java index 410386b92cf..b7a27dcd781 100644 --- a/lucene/core/src/java/org/apache/lucene/search/MultiTermQueryConstantScoreWrapper.java +++ b/lucene/core/src/java/org/apache/lucene/search/MultiTermQueryConstantScoreWrapper.java @@ -104,6 +104,9 @@ final class MultiTermQueryConstantScoreWrapper 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(); } diff --git a/lucene/core/src/java/org/apache/lucene/search/NGramPhraseQuery.java b/lucene/core/src/java/org/apache/lucene/search/NGramPhraseQuery.java index 1b49e8f0f26..e6f085c326a 100644 --- a/lucene/core/src/java/org/apache/lucene/search/NGramPhraseQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/NGramPhraseQuery.java @@ -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(); diff --git a/lucene/core/src/java/org/apache/lucene/search/RegexpQuery.java b/lucene/core/src/java/org/apache/lucene/search/RegexpQuery.java index 39d56dcee4a..dffde737dd1 100644 --- a/lucene/core/src/java/org/apache/lucene/search/RegexpQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/RegexpQuery.java @@ -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) { diff --git a/lucene/core/src/java/org/apache/lucene/search/SynonymQuery.java b/lucene/core/src/java/org/apache/lucene/search/SynonymQuery.java index 6bca14babf6..4a0ca56b62b 100644 --- a/lucene/core/src/java/org/apache/lucene/search/SynonymQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/SynonymQuery.java @@ -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 getTerms() { + return Collections.unmodifiableList(Arrays.asList(terms)); + } + @Override public String toString(String field) { StringBuilder builder = new StringBuilder("Synonym("); diff --git a/lucene/core/src/java/org/apache/lucene/search/spans/SpanContainQuery.java b/lucene/core/src/java/org/apache/lucene/search/spans/SpanContainQuery.java index 06f9467b11e..551138d32c8 100644 --- a/lucene/core/src/java/org/apache/lucene/search/spans/SpanContainQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/spans/SpanContainQuery.java @@ -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 { 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 022d83894c3..0d4ff2cbf30 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java @@ -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) { diff --git a/lucene/queries/src/java/org/apache/lucene/queries/CommonTermsQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/CommonTermsQuery.java index dd902373b70..c7b7e2f3fdc 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/CommonTermsQuery.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/CommonTermsQuery.java @@ -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 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(); diff --git a/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java index ce99fc8aa1a..4c20571e1ba 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java @@ -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(); diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionRangeQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionRangeQuery.java index 0541d39c9cd..73f0ee7c9a8 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionRangeQuery.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionRangeQuery.java @@ -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 + "):" diff --git a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointDistanceQuery.java b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointDistanceQuery.java index de4805be5c9..7ac21b35c42 100644 --- a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointDistanceQuery.java +++ b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointDistanceQuery.java @@ -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; diff --git a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointInPolygonQuery.java b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointInPolygonQuery.java index d75e615e967..fb9189f2bb6 100644 --- a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointInPolygonQuery.java +++ b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointInPolygonQuery.java @@ -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; diff --git a/lucene/sandbox/src/java/org/apache/lucene/search/DocValuesNumbersQuery.java b/lucene/sandbox/src/java/org/apache/lucene/search/DocValuesNumbersQuery.java index d9ad4bee6a3..a2ebca109fa 100644 --- a/lucene/sandbox/src/java/org/apache/lucene/search/DocValuesNumbersQuery.java +++ b/lucene/sandbox/src/java/org/apache/lucene/search/DocValuesNumbersQuery.java @@ -75,6 +75,14 @@ public class DocValuesNumbersQuery extends Query { return 31 * super.hashCode() + Objects.hash(field, numbers); } + public String getField() { + return field; + } + + public Set getNumbers() { + return numbers; + } + @Override public String toString(String defaultField) { StringBuilder sb = new StringBuilder(); diff --git a/lucene/sandbox/src/java/org/apache/lucene/search/DocValuesRangeQuery.java b/lucene/sandbox/src/java/org/apache/lucene/search/DocValuesRangeQuery.java index 8105968093a..cbdd9ba3377 100644 --- a/lucene/sandbox/src/java/org/apache/lucene/search/DocValuesRangeQuery.java +++ b/lucene/sandbox/src/java/org/apache/lucene/search/DocValuesRangeQuery.java @@ -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(); diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointTermQueryConstantScoreWrapper.java b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointTermQueryConstantScoreWrapper.java index c8d3e553901..6eea8df764e 100644 --- a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointTermQueryConstantScoreWrapper.java +++ b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointTermQueryConstantScoreWrapper.java @@ -54,6 +54,13 @@ final class GeoPointTermQueryConstantScoreWrapper