From 31495a1d2cfece483985c6799dde55fddd12dde2 Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Thu, 8 Sep 2011 16:47:50 +0000 Subject: [PATCH] LUCENE-1768: Cleanup in trunk (removal of deprecated stuff, unused subclasses in between) git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1166789 13f79535-47bb-0310-9956-ffa450edef68 --- modules/queryparser/CHANGES.txt | 16 +-- .../flexible/core/config/package.html | 2 +- .../core/nodes/ParametricQueryNode.java | 106 ---------------- .../core/nodes/ParametricRangeQueryNode.java | 119 ------------------ .../flexible/core/nodes/RangeQueryNode.java | 36 ++++++ .../flexible/core/nodes/package.html | 3 +- .../builders/RangeQueryNodeBuilder.java | 67 ---------- .../nodes/AbstractRangeQueryNode.java | 17 +-- .../standard/nodes/RangeQueryNode.java | 50 -------- .../standard/parser/StandardSyntaxParser.java | 87 +++++++------ .../standard/parser/StandardSyntaxParser.jj | 47 ++++--- .../StandardSyntaxParserTokenManager.java | 3 +- .../AnalyzerQueryNodeProcessor.java | 6 +- ...ercaseExpandedTermsQueryNodeProcessor.java | 11 +- .../processors/NumericQueryNodeProcessor.java | 13 +- .../NumericRangeQueryNodeProcessor.java | 33 +++-- .../OpenRangeQueryNodeProcessor.java | 12 +- .../StandardQueryNodeProcessorPipeline.java | 2 +- ....java => TermRangeQueryNodeProcessor.java} | 36 +++--- .../WildcardQueryNodeProcessor.java | 6 +- 20 files changed, 192 insertions(+), 480 deletions(-) delete mode 100644 modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/ParametricQueryNode.java delete mode 100644 modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/ParametricRangeQueryNode.java create mode 100644 modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/RangeQueryNode.java delete mode 100644 modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/RangeQueryNodeBuilder.java delete mode 100644 modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/nodes/RangeQueryNode.java rename modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/{ParametricRangeQueryNodeProcessor.java => TermRangeQueryNodeProcessor.java} (75%) diff --git a/modules/queryparser/CHANGES.txt b/modules/queryparser/CHANGES.txt index 4ee3b38c328..60dde215858 100644 --- a/modules/queryparser/CHANGES.txt +++ b/modules/queryparser/CHANGES.txt @@ -7,19 +7,19 @@ http://s.apache.org/luceneversions Changes in runtime behavior - * LUCENE-1768: StandardQueryTreeBuilder uses RangeQueryNodeBuilder for - RangeQueryNodes, since theses two classes were removed; - ParametricRangeQueryNodeProcessor now creates TermRangeQueryNode, - instead of RangeQueryNode, from ParametricRangeQueryNode + * LUCENE-1768: StandardQueryTreeBuilder no longer uses RangeQueryNodeBuilder + for RangeQueryNodes, since theses two classes were removed; + TermRangeQueryNodeProcessor now creates TermRangeQueryNode, + instead of RangeQueryNode; the same applies for numeric nodes; (Vinicius Barros via Uwe Schindler) API Changes - * LUCENE-1768: ParametricRangeQueryNode now implements - RangeQueryNode instead of - RangeQueryNode (Vinicius Barros via Uwe Schindler) + * LUCENE-1768: Deprecated Parametric(Range)QueryNode, RangeQueryNode(Builder), + ParametricRangeQueryNodeProcessor were removed. (Vinicius Barros via Uwe Schindler) Bug fixes * LUCENE-2945: Fix hashCode/equals for surround query parser generated queries. - (Paul Elschot, Simon Rosenthal, gsingers via ehatcher) \ No newline at end of file + (Paul Elschot, Simon Rosenthal, gsingers via ehatcher) + diff --git a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/config/package.html b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/config/package.html index 14407656f23..62c7bcfeb10 100644 --- a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/config/package.html +++ b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/config/package.html @@ -35,7 +35,7 @@ implementation.

The {@link org.apache.lucene.queryparser.flexible.core.config.QueryConfigHandler} and {@link org.apache.lucene.queryparser.flexible.core.config.FieldConfig} are used in the processors to access config information in a flexible and independent way. -See {@link org.apache.lucene.queryparser.flexible.standard.processors.ParametricRangeQueryNodeProcessor} for a +See {@link org.apache.lucene.queryparser.flexible.standard.processors.TermRangeQueryNodeProcessor} for a reference implementation.

diff --git a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/ParametricQueryNode.java b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/ParametricQueryNode.java deleted file mode 100644 index 5f02007258d..00000000000 --- a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/ParametricQueryNode.java +++ /dev/null @@ -1,106 +0,0 @@ -package org.apache.lucene.queryparser.flexible.core.nodes; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.lucene.queryparser.flexible.core.parser.EscapeQuerySyntax; - -/** - * A {@link ParametricQueryNode} represents LE, LT, GE, GT, EQ, NE query. - * Example: date >= "2009-10-10" OR price = 200 - */ -public class ParametricQueryNode extends FieldQueryNode { - - private CompareOperator operator; - - public enum CompareOperator { - LE { - @Override - public String toString() { return "<="; } - }, - LT { - @Override - public String toString() { return "<"; } - }, - GE { - @Override - public String toString() { return ">="; } - }, - GT { - @Override - public String toString() { return ">"; } - }, - EQ { - @Override - public String toString() { return "="; } - }, - NE { - @Override - public String toString() { return "!="; } - }; - } - - /** - * @param field - * - field name - * @param comp - * - CompareOperator - * @param value - * - text value - * @param begin - * - position in the query string - * @param end - * - position in the query string - */ - public ParametricQueryNode(CharSequence field, CompareOperator comp, - CharSequence value, int begin, int end) { - super(field, value, begin, end); - this.operator = comp; - setLeaf(true); - } - - public CharSequence getOperand() { - return getText(); - } - - @Override - public CharSequence toQueryString(EscapeQuerySyntax escapeSyntaxParser) { - return this.field + "" + this.operator.toString() + "\"" + this.text + "\""; - } - - @Override - public String toString() { - return ""; - } - - @Override - public ParametricQueryNode cloneTree() throws CloneNotSupportedException { - ParametricQueryNode clone = (ParametricQueryNode) super.cloneTree(); - - clone.operator = this.operator; - - return clone; - } - - /** - * @return the operator - */ - public CompareOperator getOperator() { - return this.operator; - } -} diff --git a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/ParametricRangeQueryNode.java b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/ParametricRangeQueryNode.java deleted file mode 100644 index 24e070aa189..00000000000 --- a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/ParametricRangeQueryNode.java +++ /dev/null @@ -1,119 +0,0 @@ -package org.apache.lucene.queryparser.flexible.core.nodes; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.lucene.queryparser.flexible.core.parser.EscapeQuerySyntax; - -import java.util.List; - - -/** - * A {@link ParametricRangeQueryNode} represents LE, LT, GE, GT, EQ, NE query. - * Example: date >= "2009-10-10" OR price = 200 - */ -public class ParametricRangeQueryNode extends QueryNodeImpl implements - FieldableNode { - - public ParametricRangeQueryNode(ParametricQueryNode lowerBound, - ParametricQueryNode upperBound) { - - if (upperBound.getOperator() != ParametricQueryNode.CompareOperator.LE - && upperBound.getOperator() != ParametricQueryNode.CompareOperator.LT) { - throw new IllegalArgumentException("upper bound should have " - + ParametricQueryNode.CompareOperator.LE + " or " + ParametricQueryNode.CompareOperator.LT); - } - - if (lowerBound.getOperator() != ParametricQueryNode.CompareOperator.GE - && lowerBound.getOperator() != ParametricQueryNode.CompareOperator.GT) { - throw new IllegalArgumentException("lower bound should have " - + ParametricQueryNode.CompareOperator.GE + " or " + ParametricQueryNode.CompareOperator.GT); - } - - if (upperBound.getField() != lowerBound.getField() - || (upperBound.getField() != null && !upperBound.getField().equals( - lowerBound.getField()))) { - - throw new IllegalArgumentException( - "lower and upper bounds should have the same field name!"); - - } - - allocate(); - setLeaf(false); - - add(lowerBound); - add(upperBound); - - } - - public ParametricQueryNode getUpperBound() { - return (ParametricQueryNode) getChildren().get(1); - } - - public ParametricQueryNode getLowerBound() { - return (ParametricQueryNode) getChildren().get(0); - } - - public CharSequence toQueryString(EscapeQuerySyntax escapeSyntaxParser) { - return getLowerBound().toQueryString(escapeSyntaxParser) + " AND " - + getUpperBound().toQueryString(escapeSyntaxParser); - } - - public CharSequence getField() { - return getLowerBound().getField(); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder("\n\t"); - sb.append(getUpperBound()).append("\n\t"); - sb.append(getLowerBound()).append("\n"); - sb.append("\n"); - - return sb.toString(); - - } - - @Override - public ParametricRangeQueryNode cloneTree() throws CloneNotSupportedException { - ParametricRangeQueryNode clone = (ParametricRangeQueryNode) super - .cloneTree(); - - // nothing to do here - - return clone; - } - - public void setField(CharSequence fieldName) { - List children = getChildren(); - - if (children != null) { - - for (QueryNode child : getChildren()) { - - if (child instanceof FieldableNode) { - ((FieldableNode) child).setField(fieldName); - } - - } - - } - - } - -} diff --git a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/RangeQueryNode.java b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/RangeQueryNode.java new file mode 100644 index 00000000000..033f9bd9768 --- /dev/null +++ b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/RangeQueryNode.java @@ -0,0 +1,36 @@ +package org.apache.lucene.queryparser.flexible.core.nodes; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + /** + * This interface should be implemented by a {@link QueryNode} that represents + * some kind of range query. + * + */ +public interface RangeQueryNode> extends + FieldableNode { + + T getLowerBound(); + + T getUpperBound(); + + boolean isLowerInclusive(); + + boolean isUpperInclusive(); + +} diff --git a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/package.html b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/package.html index e781271c0c5..03d3f40e69a 100644 --- a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/package.html +++ b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/package.html @@ -59,7 +59,7 @@ Grouping nodes:
  • BoostQueryNode - used for boost operator
  • SlopQueryNode - phrase slop
  • FuzzyQueryNode - fuzzy node
  • -
  • ParametricRangeQueryNode - used for parametric field:[low_value TO high_value]
  • +
  • TermRangeQueryNode - used for parametric field:[low_value TO high_value]
  • ProximityQueryNode - used for proximity search
  • NumericRangeQueryNode - used for numeric range search
  • TokenizedPhraseQueryNode - used by tokenizers/lemmatizers/analyzers for phrases/autophrases
  • @@ -72,7 +72,6 @@ Leaf Nodes:
  • NumericQueryNode - used for numeric search
  • PathQueryNode - {@link org.apache.lucene.queryparser.flexible.core.nodes.QueryNode} object used with path-like queries
  • OpaqueQueryNode - Used as for part of the query that can be parsed by other parsers. schema/value
  • -
  • ParametricQueryNode - used for parametric field [>=|<=|=|<|>] value
  • PrefixWildcardQueryNode - non-phrase wildcard query
  • QuotedFieldQUeryNode - regular phrase node
  • WildcardQueryNode - non-phrase wildcard query
  • diff --git a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/RangeQueryNodeBuilder.java b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/RangeQueryNodeBuilder.java deleted file mode 100644 index 0cd68f85c9f..00000000000 --- a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/RangeQueryNodeBuilder.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.apache.lucene.queryparser.flexible.standard.builders; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.lucene.queryparser.flexible.core.QueryNodeException; -import org.apache.lucene.queryparser.flexible.core.nodes.ParametricQueryNode; -import org.apache.lucene.queryparser.flexible.core.nodes.QueryNode; -import org.apache.lucene.queryparser.flexible.core.nodes.ParametricQueryNode.CompareOperator; -import org.apache.lucene.queryparser.flexible.standard.nodes.RangeQueryNode; -import org.apache.lucene.queryparser.flexible.standard.processors.MultiTermRewriteMethodProcessor; -import org.apache.lucene.search.MultiTermQuery; -import org.apache.lucene.search.TermRangeQuery; - -/** - * Builds a {@link TermRangeQuery} object from a {@link RangeQueryNode} object. - */ -public class RangeQueryNodeBuilder implements StandardQueryBuilder { - - public RangeQueryNodeBuilder() { - // empty constructor - } - - public TermRangeQuery build(QueryNode queryNode) throws QueryNodeException { - RangeQueryNode rangeNode = (RangeQueryNode) queryNode; - ParametricQueryNode upper = rangeNode.getUpperBound(); - ParametricQueryNode lower = rangeNode.getLowerBound(); - - boolean lowerInclusive = false; - boolean upperInclusive = false; - - if (upper.getOperator() == CompareOperator.LE) { - upperInclusive = true; - } - - if (lower.getOperator() == CompareOperator.GE) { - lowerInclusive = true; - } - - String field = rangeNode.getField().toString(); - - TermRangeQuery rangeQuery = TermRangeQuery.newStringRange(field, lower.getTextAsString(), upper.getTextAsString(), lowerInclusive, upperInclusive); - - MultiTermQuery.RewriteMethod method = (MultiTermQuery.RewriteMethod)queryNode.getTag(MultiTermRewriteMethodProcessor.TAG_ID); - if (method != null) { - rangeQuery.setRewriteMethod(method); - } - - return rangeQuery; - - } - -} diff --git a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/nodes/AbstractRangeQueryNode.java b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/nodes/AbstractRangeQueryNode.java index cce16de59a3..fdc6dd5f0fa 100644 --- a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/nodes/AbstractRangeQueryNode.java +++ b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/nodes/AbstractRangeQueryNode.java @@ -23,16 +23,18 @@ import org.apache.lucene.queryparser.flexible.core.nodes.FieldValuePairQueryNode import org.apache.lucene.queryparser.flexible.core.nodes.FieldableNode; import org.apache.lucene.queryparser.flexible.core.nodes.QueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.QueryNodeImpl; +import org.apache.lucene.queryparser.flexible.core.nodes.RangeQueryNode; 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 the type of the range query bounds (lower and upper) + * This class should be extended by nodes intending to represent range queries. + * + * @param + * the type of the range query bounds (lower and upper) */ -public abstract class AbstractRangeQueryNode> - extends QueryNodeImpl implements FieldableNode { +public class AbstractRangeQueryNode> + extends QueryNodeImpl implements RangeQueryNode> { private boolean lowerInclusive, upperInclusive; @@ -145,8 +147,9 @@ public abstract class AbstractRangeQueryNode\n\t"); - sb.append(this.getUpperBound()).append("\n\t"); - sb.append(this.getLowerBound()).append("\n"); - sb.append("\n"); - - return sb.toString(); - - } -} diff --git a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParser.java b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParser.java index 44a5d2c79d5..c5c5c8af505 100644 --- a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParser.java +++ b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParser.java @@ -33,13 +33,12 @@ import org.apache.lucene.queryparser.flexible.core.nodes.FuzzyQueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.ModifierQueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.GroupQueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.OrQueryNode; -import org.apache.lucene.queryparser.flexible.core.nodes.ParametricQueryNode; -import org.apache.lucene.queryparser.flexible.core.nodes.ParametricRangeQueryNode; import org.apache.lucene.queryparser.flexible.standard.nodes.RegexpQueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.SlopQueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.QueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.QuotedFieldQueryNode; import org.apache.lucene.queryparser.flexible.core.parser.SyntaxParser; +import org.apache.lucene.queryparser.flexible.standard.nodes.TermRangeQueryNode; public class StandardSyntaxParser implements SyntaxParser, StandardSyntaxParserConstants { @@ -309,7 +308,8 @@ public class StandardSyntaxParser implements SyntaxParser, StandardSyntaxParserC final public QueryNode Clause(CharSequence field) throws ParseException { QueryNode q; Token fieldToken=null, boost=null, operator=null, term=null; - ParametricQueryNode qLower, qUpper; + FieldQueryNode qLower, qUpper; + boolean lowerInclusive, upperInclusive; boolean group = false; if (jj_2_2(3)) { @@ -375,33 +375,46 @@ public class StandardSyntaxParser implements SyntaxParser, StandardSyntaxParserC } switch (operator.kind) { case OP_LESSTHAN: - qLower = new ParametricQueryNode(field, ParametricQueryNode.CompareOperator.GE, + lowerInclusive = true; + upperInclusive = false; + + qLower = new FieldQueryNode(field, "*", term.beginColumn, term.endColumn); - qUpper = new ParametricQueryNode(field, ParametricQueryNode.CompareOperator.LT, - EscapeQuerySyntaxImpl.discardEscapeChar(term.image), term.beginColumn, term.endColumn); + qUpper = new FieldQueryNode(field, + EscapeQuerySyntaxImpl.discardEscapeChar(term.image), term.beginColumn, term.endColumn); + break; case OP_LESSTHANEQ: - qLower = new ParametricQueryNode(field, ParametricQueryNode.CompareOperator.GE, + lowerInclusive = true; + upperInclusive = true; + + qLower = new FieldQueryNode(field, "*", term.beginColumn, term.endColumn); - qUpper = new ParametricQueryNode(field, ParametricQueryNode.CompareOperator.LE, + qUpper = new FieldQueryNode(field, EscapeQuerySyntaxImpl.discardEscapeChar(term.image), term.beginColumn, term.endColumn); break; case OP_MORETHAN: - qLower = new ParametricQueryNode(field, ParametricQueryNode.CompareOperator.GT, + lowerInclusive = false; + upperInclusive = true; + + qLower = new FieldQueryNode(field, EscapeQuerySyntaxImpl.discardEscapeChar(term.image), term.beginColumn, term.endColumn); - qUpper = new ParametricQueryNode(field, ParametricQueryNode.CompareOperator.LE, + qUpper = new FieldQueryNode(field, "*", term.beginColumn, term.endColumn); break; case OP_MORETHANEQ: - qLower = new ParametricQueryNode(field, ParametricQueryNode.CompareOperator.GE, + lowerInclusive = true; + upperInclusive = true; + + qLower = new FieldQueryNode(field, EscapeQuerySyntaxImpl.discardEscapeChar(term.image), term.beginColumn, term.endColumn); - qUpper = new ParametricQueryNode(field, ParametricQueryNode.CompareOperator.LE, + qUpper = new FieldQueryNode(field, "*", term.beginColumn, term.endColumn); break; default: {if (true) throw new Error("Unhandled case: operator="+operator.toString());} } - q = new ParametricRangeQueryNode(qLower, qUpper); + q = new TermRangeQueryNode(qLower, qUpper, lowerInclusive, upperInclusive); break; default: jj_la1[10] = jj_gen; @@ -497,7 +510,7 @@ public class StandardSyntaxParser implements SyntaxParser, StandardSyntaxParserC boolean startInc=false; boolean endInc=false; QueryNode q =null; - ParametricQueryNode qLower, qUpper; + FieldQueryNode qLower, qUpper; float defaultMinSimilarity = org.apache.lucene.search.FuzzyQuery.defaultMinSimilarity; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case TERM: @@ -638,11 +651,11 @@ public class StandardSyntaxParser implements SyntaxParser, StandardSyntaxParserC goop2.image = goop2.image.substring(1, goop2.image.length()-1); } - qLower = new ParametricQueryNode(field, startInc ? ParametricQueryNode.CompareOperator.GE : ParametricQueryNode.CompareOperator.GT, + qLower = new FieldQueryNode(field, EscapeQuerySyntaxImpl.discardEscapeChar(goop1.image), goop1.beginColumn, goop1.endColumn); - qUpper = new ParametricQueryNode(field, endInc ? ParametricQueryNode.CompareOperator.LE : ParametricQueryNode.CompareOperator.LT, + qUpper = new FieldQueryNode(field, EscapeQuerySyntaxImpl.discardEscapeChar(goop2.image), goop2.beginColumn, goop2.endColumn); - q = new ParametricRangeQueryNode(qLower, qUpper); + q = new TermRangeQueryNode(qLower, qUpper, startInc ? true : false, endInc ? true : false); break; case QUOTED: term = jj_consume_token(QUOTED); @@ -726,8 +739,16 @@ public class StandardSyntaxParser implements SyntaxParser, StandardSyntaxParserC return false; } - private boolean jj_3R_10() { - if (jj_scan_token(TERM)) return true; + private boolean jj_3R_6() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_7()) { + jj_scanpos = xsp; + if (jj_3R_8()) { + jj_scanpos = xsp; + if (jj_3R_9()) return true; + } + } return false; } @@ -742,6 +763,11 @@ public class StandardSyntaxParser implements SyntaxParser, StandardSyntaxParserC return false; } + private boolean jj_3R_10() { + if (jj_scan_token(TERM)) return true; + return false; + } + private boolean jj_3R_12() { if (jj_scan_token(RANGEIN_START)) return true; return false; @@ -786,24 +812,6 @@ public class StandardSyntaxParser implements SyntaxParser, StandardSyntaxParserC return false; } - private boolean jj_3R_9() { - if (jj_scan_token(QUOTED)) return true; - return false; - } - - private boolean jj_3R_6() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_7()) { - jj_scanpos = xsp; - if (jj_3R_8()) { - jj_scanpos = xsp; - if (jj_3R_9()) return true; - } - } - return false; - } - private boolean jj_3R_5() { Token xsp; xsp = jj_scanpos; @@ -828,6 +836,11 @@ public class StandardSyntaxParser implements SyntaxParser, StandardSyntaxParserC return false; } + private boolean jj_3R_9() { + if (jj_scan_token(QUOTED)) return true; + return false; + } + /** Generated Token Manager. */ public StandardSyntaxParserTokenManager token_source; JavaCharStream jj_input_stream; diff --git a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParser.jj b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParser.jj index 45a35a72c7b..c9744a5559b 100644 --- a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParser.jj +++ b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParser.jj @@ -45,13 +45,12 @@ import org.apache.lucene.queryparser.flexible.core.nodes.FuzzyQueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.ModifierQueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.GroupQueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.OrQueryNode; -import org.apache.lucene.queryparser.flexible.core.nodes.ParametricQueryNode; -import org.apache.lucene.queryparser.flexible.core.nodes.ParametricRangeQueryNode; import org.apache.lucene.queryparser.flexible.standard.nodes.RegexpQueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.SlopQueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.QueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.QuotedFieldQueryNode; import org.apache.lucene.queryparser.flexible.core.parser.SyntaxParser; +import org.apache.lucene.queryparser.flexible.standard.nodes.TermRangeQueryNode; public class StandardSyntaxParser implements SyntaxParser { @@ -328,7 +327,8 @@ QueryNode ModClause(CharSequence field) : { QueryNode Clause(CharSequence field) : { QueryNode q; Token fieldToken=null, boost=null, operator=null, term=null; - ParametricQueryNode qLower, qUpper; + FieldQueryNode qLower, qUpper; + boolean lowerInclusive, upperInclusive; boolean group = false; } @@ -344,33 +344,46 @@ QueryNode Clause(CharSequence field) : { } switch (operator.kind) { case OP_LESSTHAN: - qLower = new ParametricQueryNode(field, ParametricQueryNode.CompareOperator.GE, + lowerInclusive = true; + upperInclusive = false; + + qLower = new FieldQueryNode(field, "*", term.beginColumn, term.endColumn); - qUpper = new ParametricQueryNode(field, ParametricQueryNode.CompareOperator.LT, - EscapeQuerySyntaxImpl.discardEscapeChar(term.image), term.beginColumn, term.endColumn); + qUpper = new FieldQueryNode(field, + EscapeQuerySyntaxImpl.discardEscapeChar(term.image), term.beginColumn, term.endColumn); + break; case OP_LESSTHANEQ: - qLower = new ParametricQueryNode(field, ParametricQueryNode.CompareOperator.GE, + lowerInclusive = true; + upperInclusive = true; + + qLower = new FieldQueryNode(field, "*", term.beginColumn, term.endColumn); - qUpper = new ParametricQueryNode(field, ParametricQueryNode.CompareOperator.LE, + qUpper = new FieldQueryNode(field, EscapeQuerySyntaxImpl.discardEscapeChar(term.image), term.beginColumn, term.endColumn); break; case OP_MORETHAN: - qLower = new ParametricQueryNode(field, ParametricQueryNode.CompareOperator.GT, + lowerInclusive = false; + upperInclusive = true; + + qLower = new FieldQueryNode(field, EscapeQuerySyntaxImpl.discardEscapeChar(term.image), term.beginColumn, term.endColumn); - qUpper = new ParametricQueryNode(field, ParametricQueryNode.CompareOperator.LE, + qUpper = new FieldQueryNode(field, "*", term.beginColumn, term.endColumn); break; case OP_MORETHANEQ: - qLower = new ParametricQueryNode(field, ParametricQueryNode.CompareOperator.GE, + lowerInclusive = true; + upperInclusive = true; + + qLower = new FieldQueryNode(field, EscapeQuerySyntaxImpl.discardEscapeChar(term.image), term.beginColumn, term.endColumn); - qUpper = new ParametricQueryNode(field, ParametricQueryNode.CompareOperator.LE, + qUpper = new FieldQueryNode(field, "*", term.beginColumn, term.endColumn); break; default: throw new Error("Unhandled case: operator="+operator.toString()); } - q = new ParametricRangeQueryNode(qLower, qUpper); + q = new TermRangeQueryNode(qLower, qUpper, lowerInclusive, upperInclusive); } ) | [ @@ -411,7 +424,7 @@ QueryNode Term(CharSequence field) : { boolean startInc=false; boolean endInc=false; QueryNode q =null; - ParametricQueryNode qLower, qUpper; + FieldQueryNode qLower, qUpper; float defaultMinSimilarity = org.apache.lucene.search.FuzzyQuery.defaultMinSimilarity; } { @@ -453,11 +466,11 @@ QueryNode Term(CharSequence field) : { goop2.image = goop2.image.substring(1, goop2.image.length()-1); } - qLower = new ParametricQueryNode(field, startInc ? ParametricQueryNode.CompareOperator.GE : ParametricQueryNode.CompareOperator.GT, + qLower = new FieldQueryNode(field, EscapeQuerySyntaxImpl.discardEscapeChar(goop1.image), goop1.beginColumn, goop1.endColumn); - qUpper = new ParametricQueryNode(field, endInc ? ParametricQueryNode.CompareOperator.LE : ParametricQueryNode.CompareOperator.LT, + qUpper = new FieldQueryNode(field, EscapeQuerySyntaxImpl.discardEscapeChar(goop2.image), goop2.beginColumn, goop2.endColumn); - q = new ParametricRangeQueryNode(qLower, qUpper); + q = new TermRangeQueryNode(qLower, qUpper, startInc ? true : false, endInc ? true : false); } | term= {q = new QuotedFieldQueryNode(field, EscapeQuerySyntaxImpl.discardEscapeChar(term.image.substring(1, term.image.length()-1)), term.beginColumn + 1, term.endColumn - 1);} [ fuzzySlop= ] diff --git a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParserTokenManager.java b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParserTokenManager.java index f2abc43c16a..1fa8ee5ac2a 100644 --- a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParserTokenManager.java +++ b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParserTokenManager.java @@ -31,13 +31,12 @@ import org.apache.lucene.queryparser.flexible.core.nodes.FuzzyQueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.ModifierQueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.GroupQueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.OrQueryNode; -import org.apache.lucene.queryparser.flexible.core.nodes.ParametricQueryNode; -import org.apache.lucene.queryparser.flexible.core.nodes.ParametricRangeQueryNode; import org.apache.lucene.queryparser.flexible.standard.nodes.RegexpQueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.SlopQueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.QueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.QuotedFieldQueryNode; import org.apache.lucene.queryparser.flexible.core.parser.SyntaxParser; +import org.apache.lucene.queryparser.flexible.standard.nodes.TermRangeQueryNode; /** Token Manager. */ public class StandardSyntaxParserTokenManager implements StandardSyntaxParserConstants diff --git a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/AnalyzerQueryNodeProcessor.java b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/AnalyzerQueryNodeProcessor.java index b13220253f2..2ef8808a193 100644 --- a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/AnalyzerQueryNodeProcessor.java +++ b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/AnalyzerQueryNodeProcessor.java @@ -34,9 +34,9 @@ import org.apache.lucene.queryparser.flexible.core.nodes.FieldQueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.FuzzyQueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.GroupQueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.NoTokenFoundQueryNode; -import org.apache.lucene.queryparser.flexible.core.nodes.ParametricQueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.QueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.QuotedFieldQueryNode; +import org.apache.lucene.queryparser.flexible.core.nodes.RangeQueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.TextableQueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.TokenizedPhraseQueryNode; import org.apache.lucene.queryparser.flexible.core.processors.QueryNodeProcessorImpl; @@ -50,7 +50,7 @@ import org.apache.lucene.queryparser.flexible.standard.nodes.WildcardQueryNode; * is defined in the {@link QueryConfigHandler}. If it is and the analyzer is * not null, it looks for every {@link FieldQueryNode} that is not * {@link WildcardQueryNode}, {@link FuzzyQueryNode} or - * {@link ParametricQueryNode} contained in the query node tree, then it applies + * {@link RangeQueryNode} contained in the query node tree, then it applies * the analyzer to that {@link FieldQueryNode} object.
    *
    * If the analyzer return only one term, the returned term is set to the @@ -106,7 +106,7 @@ public class AnalyzerQueryNodeProcessor extends QueryNodeProcessorImpl { if (node instanceof TextableQueryNode && !(node instanceof WildcardQueryNode) && !(node instanceof FuzzyQueryNode) - && !(node instanceof ParametricQueryNode)) { + && !(node.getParent() instanceof RangeQueryNode)) { FieldQueryNode fieldNode = ((FieldQueryNode) node); String text = fieldNode.getTextAsString(); diff --git a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/LowercaseExpandedTermsQueryNodeProcessor.java b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/LowercaseExpandedTermsQueryNodeProcessor.java index 814f561db9b..8ee9936e898 100644 --- a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/LowercaseExpandedTermsQueryNodeProcessor.java +++ b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/LowercaseExpandedTermsQueryNodeProcessor.java @@ -21,9 +21,10 @@ import java.util.List; import org.apache.lucene.queryparser.flexible.core.QueryNodeException; import org.apache.lucene.queryparser.flexible.core.config.QueryConfigHandler; +import org.apache.lucene.queryparser.flexible.core.nodes.FieldQueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.FuzzyQueryNode; -import org.apache.lucene.queryparser.flexible.core.nodes.ParametricQueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.QueryNode; +import org.apache.lucene.queryparser.flexible.core.nodes.RangeQueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.TextableQueryNode; import org.apache.lucene.queryparser.flexible.core.processors.QueryNodeProcessorImpl; import org.apache.lucene.queryparser.flexible.core.util.UnescapedCharSequence; @@ -36,7 +37,7 @@ import org.apache.lucene.queryparser.flexible.standard.nodes.WildcardQueryNode; * {@link ConfigurationKeys#LOWERCASE_EXPANDED_TERMS} is defined in the * {@link QueryConfigHandler}. If it is and the expanded terms should be * lower-cased, it looks for every {@link WildcardQueryNode}, - * {@link FuzzyQueryNode} and {@link ParametricQueryNode} and lower-case its + * {@link FuzzyQueryNode} and children of a {@link RangeQueryNode} and lower-case its * term.
    * * @see ConfigurationKeys#LOWERCASE_EXPANDED_TERMS @@ -63,8 +64,10 @@ public class LowercaseExpandedTermsQueryNodeProcessor extends @Override protected QueryNode postProcessNode(QueryNode node) throws QueryNodeException { - if (node instanceof WildcardQueryNode || node instanceof FuzzyQueryNode - || node instanceof ParametricQueryNode || node instanceof RegexpQueryNode) { + if (node instanceof WildcardQueryNode + || node instanceof FuzzyQueryNode + || (node instanceof FieldQueryNode && node.getParent() instanceof RangeQueryNode) + || node instanceof RegexpQueryNode) { TextableQueryNode txtNode = (TextableQueryNode) node; CharSequence text = txtNode.getText(); diff --git a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/NumericQueryNodeProcessor.java b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/NumericQueryNodeProcessor.java index 066038b701c..d1114c6fcd8 100644 --- a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/NumericQueryNodeProcessor.java +++ b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/NumericQueryNodeProcessor.java @@ -28,9 +28,8 @@ import org.apache.lucene.queryparser.flexible.core.config.FieldConfig; import org.apache.lucene.queryparser.flexible.core.config.QueryConfigHandler; import org.apache.lucene.queryparser.flexible.core.messages.QueryParserMessages; import org.apache.lucene.queryparser.flexible.core.nodes.FieldQueryNode; -import org.apache.lucene.queryparser.flexible.core.nodes.ParametricQueryNode; -import org.apache.lucene.queryparser.flexible.core.nodes.ParametricRangeQueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.QueryNode; +import org.apache.lucene.queryparser.flexible.core.nodes.RangeQueryNode; import org.apache.lucene.queryparser.flexible.core.processors.QueryNodeProcessorImpl; import org.apache.lucene.queryparser.flexible.standard.config.NumericConfig; import org.apache.lucene.queryparser.flexible.standard.config.StandardQueryConfigHandler.ConfigurationKeys; @@ -46,11 +45,11 @@ import org.apache.lucene.queryparser.flexible.standard.nodes.NumericRangeQueryNo * {@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].
    + * to {@link Number}. It means that field:1 is converted to field:[1 + * TO 1].
    *
    - * Note that {@link ParametricQueryNode}s are ignored, even being a - * {@link FieldQueryNode}. + * Note that {@link FieldQueryNode}s children of a + * {@link RangeQueryNode} are ignored. * * @see ConfigurationKeys#NUMERIC_CONFIG * @see FieldQueryNode @@ -70,7 +69,7 @@ public class NumericQueryNodeProcessor extends QueryNodeProcessorImpl { protected QueryNode postProcessNode(QueryNode node) throws QueryNodeException { if (node instanceof FieldQueryNode - && !(node.getParent() instanceof ParametricRangeQueryNode)) { + && !(node.getParent() instanceof RangeQueryNode)) { QueryConfigHandler config = getQueryConfigHandler(); diff --git a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/NumericRangeQueryNodeProcessor.java b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/NumericRangeQueryNodeProcessor.java index 015f98ed181..fde94494d7a 100644 --- a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/NumericRangeQueryNodeProcessor.java +++ b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/NumericRangeQueryNodeProcessor.java @@ -27,28 +27,27 @@ import org.apache.lucene.queryparser.flexible.core.QueryNodeParseException; import org.apache.lucene.queryparser.flexible.core.config.FieldConfig; import org.apache.lucene.queryparser.flexible.core.config.QueryConfigHandler; import org.apache.lucene.queryparser.flexible.core.messages.QueryParserMessages; -import org.apache.lucene.queryparser.flexible.core.nodes.ParametricQueryNode; -import org.apache.lucene.queryparser.flexible.core.nodes.ParametricRangeQueryNode; +import org.apache.lucene.queryparser.flexible.core.nodes.FieldQueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.QueryNode; -import org.apache.lucene.queryparser.flexible.core.nodes.ParametricQueryNode.CompareOperator; import org.apache.lucene.queryparser.flexible.core.processors.QueryNodeProcessorImpl; import org.apache.lucene.queryparser.flexible.core.util.StringUtils; import org.apache.lucene.queryparser.flexible.standard.config.NumericConfig; import org.apache.lucene.queryparser.flexible.standard.config.StandardQueryConfigHandler.ConfigurationKeys; import org.apache.lucene.queryparser.flexible.standard.nodes.NumericQueryNode; import org.apache.lucene.queryparser.flexible.standard.nodes.NumericRangeQueryNode; +import org.apache.lucene.queryparser.flexible.standard.nodes.TermRangeQueryNode; /** - * This processor is used to convert {@link ParametricRangeQueryNode}s to + * This processor is used to convert {@link TermRangeQueryNode}s to * {@link NumericRangeQueryNode}s. It looks for * {@link ConfigurationKeys#NUMERIC_CONFIG} set in the {@link FieldConfig} of - * every {@link ParametricRangeQueryNode} found. If + * every {@link TermRangeQueryNode} found. If * {@link ConfigurationKeys#NUMERIC_CONFIG} is found, it considers that - * {@link ParametricRangeQueryNode} to be a numeric range query and convert it to + * {@link TermRangeQueryNode} to be a numeric range query and convert it to * {@link NumericRangeQueryNode}. * * @see ConfigurationKeys#NUMERIC_CONFIG - * @see ParametricRangeQueryNode + * @see TermRangeQueryNode * @see NumericConfig * @see NumericRangeQueryNode */ @@ -64,13 +63,13 @@ public class NumericRangeQueryNodeProcessor extends QueryNodeProcessorImpl { @Override protected QueryNode postProcessNode(QueryNode node) throws QueryNodeException { - if (node instanceof ParametricRangeQueryNode) { + if (node instanceof TermRangeQueryNode) { QueryConfigHandler config = getQueryConfigHandler(); if (config != null) { - ParametricRangeQueryNode parametricRangeNode = (ParametricRangeQueryNode) node; + TermRangeQueryNode termRangeNode = (TermRangeQueryNode) node; FieldConfig fieldConfig = config.getFieldConfig(StringUtils - .toString(parametricRangeNode.getField())); + .toString(termRangeNode.getField())); if (fieldConfig != null) { @@ -79,8 +78,8 @@ public class NumericRangeQueryNodeProcessor extends QueryNodeProcessorImpl { if (numericConfig != null) { - ParametricQueryNode lower = parametricRangeNode.getLowerBound(); - ParametricQueryNode upper = parametricRangeNode.getUpperBound(); + FieldQueryNode lower = termRangeNode.getLowerBound(); + FieldQueryNode upper = termRangeNode.getUpperBound(); String lowerText = lower.getTextAsString(); String upperText = upper.getTextAsString(); @@ -134,14 +133,12 @@ public class NumericRangeQueryNodeProcessor extends QueryNodeProcessorImpl { } NumericQueryNode lowerNode = new NumericQueryNode( - parametricRangeNode.getField(), lowerNumber, numberFormat); + termRangeNode.getField(), lowerNumber, numberFormat); NumericQueryNode upperNode = new NumericQueryNode( - parametricRangeNode.getField(), upperNumber, numberFormat); + termRangeNode.getField(), upperNumber, numberFormat); - boolean upperInclusive = upper == null - | upper.getOperator() == CompareOperator.LE; - boolean lowerInclusive = lower == null - | lower.getOperator() == CompareOperator.GE; + boolean lowerInclusive = termRangeNode.isLowerInclusive(); + boolean upperInclusive = termRangeNode.isUpperInclusive(); return new NumericRangeQueryNode(lowerNode, upperNode, lowerInclusive, upperInclusive, numericConfig); diff --git a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/OpenRangeQueryNodeProcessor.java b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/OpenRangeQueryNodeProcessor.java index 2551a7009f9..050b599f168 100644 --- a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/OpenRangeQueryNodeProcessor.java +++ b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/OpenRangeQueryNodeProcessor.java @@ -3,11 +3,11 @@ package org.apache.lucene.queryparser.flexible.standard.processors; import java.util.List; import org.apache.lucene.queryparser.flexible.core.QueryNodeException; -import org.apache.lucene.queryparser.flexible.core.nodes.ParametricQueryNode; -import org.apache.lucene.queryparser.flexible.core.nodes.ParametricRangeQueryNode; +import org.apache.lucene.queryparser.flexible.core.nodes.FieldQueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.QueryNode; import org.apache.lucene.queryparser.flexible.core.processors.QueryNodeProcessorImpl; import org.apache.lucene.queryparser.flexible.core.util.UnescapedCharSequence; +import org.apache.lucene.queryparser.flexible.standard.nodes.TermRangeQueryNode; public class OpenRangeQueryNodeProcessor extends QueryNodeProcessorImpl { @@ -18,10 +18,10 @@ public class OpenRangeQueryNodeProcessor extends QueryNodeProcessorImpl { @Override protected QueryNode postProcessNode(QueryNode node) throws QueryNodeException { - if (node instanceof ParametricRangeQueryNode) { - ParametricRangeQueryNode rangeNode = (ParametricRangeQueryNode) node; - ParametricQueryNode lowerNode = (ParametricQueryNode) rangeNode.getLowerBound(); - ParametricQueryNode upperNode = (ParametricQueryNode) rangeNode.getUpperBound(); + if (node instanceof TermRangeQueryNode) { + TermRangeQueryNode rangeNode = (TermRangeQueryNode) node; + FieldQueryNode lowerNode = (FieldQueryNode) rangeNode.getLowerBound(); + FieldQueryNode upperNode = (FieldQueryNode) rangeNode.getUpperBound(); CharSequence lowerText = lowerNode.getText(); CharSequence upperText = upperNode.getText(); diff --git a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/StandardQueryNodeProcessorPipeline.java b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/StandardQueryNodeProcessorPipeline.java index ee11f85f5b7..bd8a29cb820 100644 --- a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/StandardQueryNodeProcessorPipeline.java +++ b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/StandardQueryNodeProcessorPipeline.java @@ -56,7 +56,7 @@ public class StandardQueryNodeProcessorPipeline extends add(new NumericQueryNodeProcessor()); add(new NumericRangeQueryNodeProcessor()); add(new LowercaseExpandedTermsQueryNodeProcessor()); - add(new ParametricRangeQueryNodeProcessor()); + add(new TermRangeQueryNodeProcessor()); add(new AllowLeadingWildcardProcessor()); add(new AnalyzerQueryNodeProcessor()); add(new PhraseSlopQueryNodeProcessor()); diff --git a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/ParametricRangeQueryNodeProcessor.java b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/TermRangeQueryNodeProcessor.java similarity index 75% rename from modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/ParametricRangeQueryNodeProcessor.java rename to modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/TermRangeQueryNodeProcessor.java index 6662e691070..7220b1fa454 100644 --- a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/ParametricRangeQueryNodeProcessor.java +++ b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/TermRangeQueryNodeProcessor.java @@ -28,21 +28,18 @@ import org.apache.lucene.document.DateTools.Resolution; import org.apache.lucene.queryparser.flexible.core.QueryNodeException; import org.apache.lucene.queryparser.flexible.core.config.FieldConfig; import org.apache.lucene.queryparser.flexible.core.config.QueryConfigHandler; -import org.apache.lucene.queryparser.flexible.core.nodes.ParametricQueryNode; -import org.apache.lucene.queryparser.flexible.core.nodes.ParametricRangeQueryNode; +import org.apache.lucene.queryparser.flexible.core.nodes.FieldQueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.QueryNode; -import org.apache.lucene.queryparser.flexible.core.nodes.ParametricQueryNode.CompareOperator; import org.apache.lucene.queryparser.flexible.core.processors.QueryNodeProcessorImpl; import org.apache.lucene.queryparser.flexible.standard.config.StandardQueryConfigHandler.ConfigurationKeys; import org.apache.lucene.queryparser.flexible.standard.nodes.TermRangeQueryNode; /** - * This processor converts {@link ParametricRangeQueryNode} objects to - * {@link TermRangeQueryNode} objects. It reads the lower and upper bounds value - * from the {@link ParametricRangeQueryNode} object and try to parse their - * values using a {@link DateFormat}. If the values cannot be parsed to a date - * value, it will only create the {@link TermRangeQueryNode} using the - * non-parsed values.
    + * This processors process {@link TermRangeQueryNode}s. It reads the lower and + * upper bounds value from the {@link TermRangeQueryNode} object and try + * to parse their values using a {@link DateFormat}. If the values cannot be + * parsed to a date value, it will only create the {@link TermRangeQueryNode} + * using the non-parsed values.
    *
    * If a {@link ConfigurationKeys#LOCALE} is defined in the * {@link QueryConfigHandler} it will be used to parse the date, otherwise @@ -56,21 +53,20 @@ import org.apache.lucene.queryparser.flexible.standard.nodes.TermRangeQueryNode; * @see ConfigurationKeys#DATE_RESOLUTION * @see ConfigurationKeys#LOCALE * @see TermRangeQueryNode - * @see ParametricRangeQueryNode */ -public class ParametricRangeQueryNodeProcessor extends QueryNodeProcessorImpl { +public class TermRangeQueryNodeProcessor extends QueryNodeProcessorImpl { - public ParametricRangeQueryNodeProcessor() { + public TermRangeQueryNodeProcessor() { // empty constructor } @Override protected QueryNode postProcessNode(QueryNode node) throws QueryNodeException { - if (node instanceof ParametricRangeQueryNode) { - ParametricRangeQueryNode parametricRangeNode = (ParametricRangeQueryNode) node; - ParametricQueryNode upper = parametricRangeNode.getUpperBound(); - ParametricQueryNode lower = parametricRangeNode.getLowerBound(); + if (node instanceof TermRangeQueryNode) { + TermRangeQueryNode termRangeNode = (TermRangeQueryNode) node; + FieldQueryNode upper = termRangeNode.getUpperBound(); + FieldQueryNode lower = termRangeNode.getLowerBound(); DateTools.Resolution dateRes = null; boolean inclusive = false; @@ -80,7 +76,7 @@ public class ParametricRangeQueryNodeProcessor extends QueryNodeProcessorImpl { locale = Locale.getDefault(); } - CharSequence field = parametricRangeNode.getField(); + CharSequence field = termRangeNode.getField(); String fieldStr = null; if (field != null) { @@ -94,7 +90,7 @@ public class ParametricRangeQueryNodeProcessor extends QueryNodeProcessorImpl { dateRes = fieldConfig.get(ConfigurationKeys.DATE_RESOLUTION); } - if (upper.getOperator() == CompareOperator.LE) { + if (termRangeNode.isUpperInclusive()) { inclusive = true; } @@ -136,10 +132,6 @@ public class ParametricRangeQueryNodeProcessor extends QueryNodeProcessorImpl { // do nothing } - return new TermRangeQueryNode(lower, upper, part1.length() == 0 - | lower.getOperator() == CompareOperator.GE, part2.length() == 0 - | upper.getOperator() == CompareOperator.LE); - } return node; diff --git a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/WildcardQueryNodeProcessor.java b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/WildcardQueryNodeProcessor.java index 331f8fd6e1f..e572fb99a36 100644 --- a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/WildcardQueryNodeProcessor.java +++ b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/WildcardQueryNodeProcessor.java @@ -22,12 +22,12 @@ import java.util.List; import org.apache.lucene.queryparser.flexible.core.QueryNodeException; import org.apache.lucene.queryparser.flexible.core.nodes.FieldQueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.FuzzyQueryNode; -import org.apache.lucene.queryparser.flexible.core.nodes.ParametricQueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.QueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.QuotedFieldQueryNode; import org.apache.lucene.queryparser.flexible.core.processors.QueryNodeProcessorImpl; import org.apache.lucene.queryparser.flexible.core.util.UnescapedCharSequence; import org.apache.lucene.queryparser.flexible.standard.nodes.PrefixWildcardQueryNode; +import org.apache.lucene.queryparser.flexible.standard.nodes.TermRangeQueryNode; import org.apache.lucene.queryparser.flexible.standard.nodes.WildcardQueryNode; import org.apache.lucene.queryparser.flexible.standard.parser.StandardSyntaxParser; import org.apache.lucene.search.PrefixQuery; @@ -57,9 +57,9 @@ public class WildcardQueryNodeProcessor extends QueryNodeProcessorImpl { FieldQueryNode fqn = (FieldQueryNode) node; CharSequence text = fqn.getText(); - // do not process wildcards for ParametricQueryNode and + // do not process wildcards for TermRangeQueryNode children and // QuotedFieldQueryNode to reproduce the old parser behavior - if (fqn instanceof ParametricQueryNode + if (fqn.getParent() instanceof TermRangeQueryNode || fqn instanceof QuotedFieldQueryNode || text.length() <= 0){ // Ignore empty terms