Index: modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/FieldValuePairQueryNode.java
===================================================================
--- modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/FieldValuePairQueryNode.java (revision 1147687)
+++ modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/FieldValuePairQueryNode.java (working copy)
@@ -17,6 +17,14 @@
* limitations under the License.
*/
-public interface FieldValuePairQueryNode
null.
+ *
+ * return null
+ */
public TermQuery build(QueryNode queryNode) throws QueryNodeException {
return null;
}
Index: modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/NumericRangeQueryNodeBuilder.java
===================================================================
--- modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/NumericRangeQueryNodeBuilder.java (revision 1147687)
+++ modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/NumericRangeQueryNodeBuilder.java (working copy)
@@ -28,8 +28,17 @@
import org.apache.lucene.queryparser.flexible.standard.nodes.NumericRangeQueryNode;
import org.apache.lucene.search.NumericRangeQuery;
+/**
+ * Builds {@link NumericRangeQuery}s out of {@link NumericRangeQueryNode}s.
+ *
+ * @see NumericRangeQuery
+ * @see NumericRangeQueryNode
+ */
public class NumericRangeQueryNodeBuilder implements StandardQueryBuilder {
+ /**
+ * Constructs a {@link NumericRangeQueryNodeBuilder} object.
+ */
public NumericRangeQueryNodeBuilder() {
// empty constructor
}
Index: modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/config/NumberDateFormat.java
===================================================================
--- modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/config/NumberDateFormat.java (revision 1147687)
+++ modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/config/NumberDateFormat.java (working copy)
@@ -19,16 +19,27 @@
import java.text.DateFormat;
import java.text.FieldPosition;
+import java.text.Format;
import java.text.NumberFormat;
import java.text.ParsePosition;
import java.util.Date;
+/**
+ * This {@link Format} parses {@link Long} into date strings and vice-versa. It
+ * uses the given {@link DateFormat} to parse and format dates, but before, it
+ * converts {@link Long} to {@link Date} objects or vice-versa.
+ */
public class NumberDateFormat extends NumberFormat {
private static final long serialVersionUID = 964823936071308283L;
final private DateFormat dateFormat;
+ /**
+ * Constructs a {@link NumberDateFormat} object using the given {@link DateFormat}.
+ *
+ * @param dateFormat {@link DateFormat} used to parse and format dates
+ */
public NumberDateFormat(DateFormat dateFormat) {
this.dateFormat = dateFormat;
}
Index: modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/config/NumericConfig.java
===================================================================
--- modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/config/NumericConfig.java (revision 1147687)
+++ modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/config/NumericConfig.java (working copy)
@@ -20,7 +20,15 @@
import java.text.NumberFormat;
import org.apache.lucene.document.NumericField;
+import org.apache.lucene.search.NumericRangeQuery;
+/**
+ * This class holds the configuration used to parse numeric queries and create
+ * {@link NumericRangeQuery}s.
+ *
+ * @see NumericRangeQuery
+ * @see NumberFormat
+ */
public class NumericConfig {
private int precisionStep;
@@ -28,30 +36,78 @@
private NumberFormat format;
private NumericField.DataType type;
-
- public NumericConfig(int precisionStep, NumberFormat format, NumericField.DataType type) {
+
+ /**
+ * Constructs a {@link NumericConfig} object.
+ *
+ * @param precisionStep
+ * the precision used to index the numeric values
+ * @param format
+ * the {@link NumberFormat} used to parse a {@link String} to
+ * {@link Number}
+ * @param type
+ * the numeric type used to index the numeric values
+ *
+ * @see NumericConfig#setPrecisionStep(int)
+ * @see NumericConfig#setNumberFormat(NumberFormat)
+ * @see #setType(org.apache.lucene.document.NumericField.DataType)
+ */
+ public NumericConfig(int precisionStep, NumberFormat format,
+ NumericField.DataType type) {
setPrecisionStep(precisionStep);
setNumberFormat(format);
setType(type);
}
+ /**
+ * Returns the precision used to index the numeric values
+ *
+ * @return the precision used to index the numeric values
+ *
+ * @see NumericRangeQuery#getPrecisionStep()
+ */
public int getPrecisionStep() {
return precisionStep;
}
+ /**
+ * Sets the precision used to index the numeric values
+ *
+ * @param precisionStep
+ * the precision used to index the numeric values
+ *
+ * @see NumericRangeQuery#getPrecisionStep()
+ */
public void setPrecisionStep(int precisionStep) {
this.precisionStep = precisionStep;
}
+ /**
+ * Returns the {@link NumberFormat} used to parse a {@link String} to
+ * {@link Number}
+ *
+ * @return the {@link NumberFormat} used to parse a {@link String} to
+ * {@link Number}
+ */
public NumberFormat getNumberFormat() {
return format;
}
+ /**
+ * Returns the numeric type used to index the numeric values
+ *
+ * @return the numeric type used to index the numeric values
+ */
public NumericField.DataType getType() {
return type;
}
-
+
+ /**
+ * Sets the numeric type used to index the numeric values
+ *
+ * @param type the numeric type used to index the numeric values
+ */
public void setType(NumericField.DataType type) {
if (type == null) {
@@ -61,7 +117,15 @@
this.type = type;
}
-
+
+ /**
+ * Sets the {@link NumberFormat} used to parse a {@link String} to
+ * {@link Number}
+ *
+ * @param format
+ * the {@link NumberFormat} used to parse a {@link String} to
+ * {@link Number}, cannot be null
+ */
public void setNumberFormat(NumberFormat format) {
if (format == null) {
@@ -81,7 +145,8 @@
NumericConfig other = (NumericConfig) obj;
if (this.precisionStep == other.precisionStep
- && this.format == other.format) {
+ && this.type == other.type
+ && (this.format == other.format || (this.format.equals(other.format)))) {
return true;
}
Index: modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/config/NumericFieldConfigListener.java
===================================================================
--- modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/config/NumericFieldConfigListener.java (revision 1147687)
+++ modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/config/NumericFieldConfigListener.java (working copy)
@@ -24,10 +24,26 @@
import org.apache.lucene.queryparser.flexible.core.config.QueryConfigHandler;
import org.apache.lucene.queryparser.flexible.standard.config.StandardQueryConfigHandler.ConfigurationKeys;
+/**
+ * This listener is used to listen to {@link FieldConfig} requests in
+ * {@link QueryConfigHandler} and add {@link ConfigurationKeys#NUMERIC_CONFIG}
+ * based on the {@link ConfigurationKeys#NUMERIC_CONFIG_MAP} set in the
+ * {@link QueryConfigHandler}.
+ *
+ * @see NumericConfig
+ * @see QueryConfigHandler
+ * @see ConfigurationKeys#NUMERIC_CONFIG
+ * @see ConfigurationKeys#NUMERIC_CONFIG_MAP
+ */
public class NumericFieldConfigListener implements FieldConfigListener {
final private QueryConfigHandler config;
+ /**
+ * Construcs a {@link NumericFieldConfigListener} object using the given {@link QueryConfigHandler}.
+ *
+ * @param config the {@link QueryConfigHandler} it will listen too
+ */
public NumericFieldConfigListener(QueryConfigHandler config) {
if (config == null) {
Index: modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/nodes/AbstractRangeQueryNode.java
===================================================================
--- modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/nodes/AbstractRangeQueryNode.java (revision 1147687)
+++ modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/nodes/AbstractRangeQueryNode.java (working copy)
@@ -26,16 +26,32 @@
import org.apache.lucene.queryparser.flexible.core.parser.EscapeQuerySyntax;
import org.apache.lucene.queryparser.flexible.core.util.StringUtils;
+/**
+ * This class should be extended by nodes intending to represent range queries.
+ *
+ * @param true if the lower bound is inclusive, otherwise, false
+ */
public boolean isLowerInclusive() {
return lowerInclusive;
}
+ /**
+ * Returns whether the upper bound is inclusive or exclusive.
+ *
+ * @return true if the upper bound is inclusive, otherwise, false
+ */
public boolean isUpperInclusive() {
return upperInclusive;
}
+ /**
+ * Sets the lower and upper bounds.
+ *
+ * @param lower the lower bound, null if lower bound is open
+ * @param upper the upper bound, null if upper bound is open
+ * @param lowerInclusive true if the lower bound is inclusive, otherwise, false
+ * @param upperInclusive true if the upper bound is inclusive, otherwise, false
+ *
+ * @see #getLowerBound()
+ * @see #getUpperBound()
+ * @see #isLowerInclusive()
+ * @see #isUpperInclusive()
+ */
public void setBounds(T lower, T upper, boolean lowerInclusive,
boolean upperInclusive) {
Index: modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/nodes/NumericQueryNode.java
===================================================================
--- modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/nodes/NumericQueryNode.java (revision 1147687)
+++ modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/nodes/NumericQueryNode.java (working copy)
@@ -20,11 +20,20 @@
import java.text.NumberFormat;
import java.util.Locale;
+import org.apache.lucene.queryparser.flexible.core.nodes.FieldQueryNode;
import org.apache.lucene.queryparser.flexible.core.nodes.FieldValuePairQueryNode;
import org.apache.lucene.queryparser.flexible.core.nodes.QueryNodeImpl;
import org.apache.lucene.queryparser.flexible.core.parser.EscapeQuerySyntax;
import org.apache.lucene.queryparser.flexible.core.parser.EscapeQuerySyntax.Type;
+import org.apache.lucene.queryparser.flexible.standard.config.NumericConfig;
+/**
+ * This query node represents a field query that holds a numeric value. It is
+ * similar to {@link FieldQueryNode}, however the {@link #getValue()} returns a
+ * {@link Number}.
+ *
+ * @see NumericConfig
+ */
public class NumericQueryNode extends QueryNodeImpl implements
FieldValuePairQueryNodetrue if the lower bound is inclusive, otherwise, false
+ * @param upperInclusive true if the upper bound is inclusive, otherwise, false
+ * @param numericConfig the {@link NumericConfig} that represents associated with the upper and lower bounds
+ *
+ * @see #setBounds(NumericQueryNode, NumericQueryNode, boolean, boolean, NumericConfig)
+ */
public NumericRangeQueryNode(NumericQueryNode lower, NumericQueryNode upper,
boolean lowerInclusive, boolean upperInclusive, NumericConfig numericConfig) throws QueryNodeException {
setBounds(lower, upper, lowerInclusive, upperInclusive, numericConfig);
@@ -52,6 +72,17 @@
}
+ /**
+ * Sets the upper and lower bounds of this range query node and the
+ * {@link NumericConfig} associated with these bounds.
+ *
+ * @param lower the lower bound
+ * @param upper the upper bound
+ * @param lowerInclusive true if the lower bound is inclusive, otherwise, false
+ * @param upperInclusive true if the upper bound is inclusive, otherwise, false
+ * @param numericConfig the {@link NumericConfig} that represents associated with the upper and lower bounds
+ *
+ */
public void setBounds(NumericQueryNode lower, NumericQueryNode upper,
boolean lowerInclusive, boolean upperInclusive, NumericConfig numericConfig) throws QueryNodeException {
@@ -92,6 +123,11 @@
}
+ /**
+ * Returns the {@link NumericConfig} associated with the lower and upper bounds.
+ *
+ * @return the {@link NumericConfig} associated with the lower and upper bounds
+ */
public NumericConfig getNumericConfig() {
return this.numericConfig;
}
Index: modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/nodes/TermRangeQueryNode.java
===================================================================
--- modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/nodes/TermRangeQueryNode.java (revision 1147687)
+++ modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/nodes/TermRangeQueryNode.java (working copy)
@@ -20,13 +20,23 @@
import org.apache.lucene.queryparser.flexible.core.nodes.FieldQueryNode;
/**
- * This query node represents a range query.
+ * This query node represents a range query composed by {@link FieldQueryNode}
+ * bounds, which means the bound values are strings.
*
- * @see org.apache.lucene.queryparser.flexible.standard.processors.ParametricRangeQueryNodeProcessor
- * @see org.apache.lucene.search.TermRangeQuery
+ * @see FieldQueryNode
+ * @see AbstractRangeQueryNode
*/
public class TermRangeQueryNode extends AbstractRangeQueryNodetrue if the lower bound is inclusive, otherwise, false
+ * @param upperInclusive true if the upper bound is inclusive, otherwise, false
+ */
public TermRangeQueryNode(FieldQueryNode lower, FieldQueryNode upper,
boolean lowerInclusive, boolean upperInclusive) {
setBounds(lower, upper, lowerInclusive, upperInclusive);
Index: modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/NumericQueryNodeProcessor.java
===================================================================
--- modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/NumericQueryNodeProcessor.java (revision 1147687)
+++ modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/NumericQueryNodeProcessor.java (working copy)
@@ -36,8 +36,31 @@
import org.apache.lucene.queryparser.flexible.standard.nodes.NumericQueryNode;
import org.apache.lucene.queryparser.flexible.standard.nodes.NumericRangeQueryNode;
+/**
+ * This processor is used to convert {@link FieldQueryNode}s to
+ * {@link NumericRangeQueryNode}s. It looks for
+ * {@link ConfigurationKeys#NUMERIC_CONFIG} set in the {@link FieldConfig} of
+ * every {@link FieldQueryNode} found. If
+ * {@link ConfigurationKeys#NUMERIC_CONFIG} is found, it considers that
+ * {@link FieldQueryNode} to be a numeric query and convert it to
+ * {@link NumericRangeQueryNode} with upper and lower inclusive and lower and
+ * upper equals to the value represented by the {@link FieldQueryNode} converted
+ * to {@link Number}. It means that field:1 is converted to field:[1 TO
+ * 1]. -This processors are already assembled correctly in the StandardQueryNodeProcessorPipeline. +These processors are already assembled correctly in the StandardQueryNodeProcessorPipeline.