You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2011/07/09 23:05:14 UTC
svn commit: r1144744 [1/2] - in
/lucene/dev/trunk/lucene/contrib/queryparser/src:
java/org/apache/lucene/queryParser/core/messages/
java/org/apache/lucene/queryParser/core/nodes/
java/org/apache/lucene/queryParser/standard/ java/org/apache/lucene/query...
Author: uschindler
Date: Sat Jul 9 21:05:13 2011
New Revision: 1144744
URL: http://svn.apache.org/viewvc?rev=1144744&view=rev
Log:
Committing new NumericRangeQuery support by Vinicius Barros to flexible StandardQueryParser. This first commit supports all functionality, but still needs some improvements, that will be part of 2nd half of GSoC.
Added:
lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/FieldValuePairQueryNode.java (with props)
lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/NumberQueryNode.java (with props)
lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/ValueQueryNode.java (with props)
lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/builders/DummyQueryNodeBuilder.java (with props)
lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/builders/NumericRangeQueryNodeBuilder.java (with props)
lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/builders/TermRangeQueryNodeBuilder.java (with props)
lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/NumberDateFormat.java (with props)
lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/NumericConfig.java (with props)
lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/NumericFieldConfigListener.java (with props)
lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/nodes/AbstractRangeQueryNode.java (with props)
lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/nodes/NumericQueryNode.java (with props)
lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/nodes/NumericRangeQueryNode.java (with props)
lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/nodes/TermRangeQueryNode.java (with props)
lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/NumericQueryNodeProcessor.java (with props)
lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/NumericRangeQueryNodeProcessor.java (with props)
lucene/dev/trunk/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestNumericQueryParser.java (with props)
Modified:
lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/messages/QueryParserMessages.java
lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/FieldQueryNode.java
lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/StandardQueryParser.java
lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/builders/StandardQueryTreeBuilder.java
lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/StandardQueryConfigHandler.java
lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/AnalyzerQueryNodeProcessor.java
lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/DefaultPhraseSlopQueryNodeProcessor.java
lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/FuzzyQueryNodeProcessor.java
lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/LowercaseExpandedTermsQueryNodeProcessor.java
lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/MultiFieldQueryNodeProcessor.java
lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/MultiTermRewriteMethodProcessor.java
lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/ParametricRangeQueryNodeProcessor.java
lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/StandardQueryNodeProcessorPipeline.java
lucene/dev/trunk/lucene/contrib/queryparser/src/resources/org/apache/lucene/queryParser/core/messages/QueryParserMessages.properties
Modified: lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/messages/QueryParserMessages.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/messages/QueryParserMessages.java?rev=1144744&r1=1144743&r2=1144744&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/messages/QueryParserMessages.java (original)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/messages/QueryParserMessages.java Sat Jul 9 21:05:13 2011
@@ -51,5 +51,8 @@ public class QueryParserMessages extends
public static String WILDCARD_NOT_SUPPORTED;
public static String TOO_MANY_BOOLEAN_CLAUSES;
public static String LEADING_WILDCARD_NOT_ALLOWED;
+ public static String COULD_NOT_PARSE_NUMBER;
+ public static String NUMBER_CLASS_NOT_SUPPORTED_BY_NUMERIC_RANGE_QUERY;
+ public static String UNSUPPORTED_NUMERIC_DATA_TYPE;
}
Modified: lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/FieldQueryNode.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/FieldQueryNode.java?rev=1144744&r1=1144743&r2=1144744&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/FieldQueryNode.java (original)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/FieldQueryNode.java Sat Jul 9 21:05:13 2011
@@ -25,8 +25,7 @@ import org.apache.lucene.queryParser.cor
/**
* A {@link FieldQueryNode} represents a element that contains field/text tuple
*/
-public class FieldQueryNode extends QueryNodeImpl implements TextableQueryNode,
- FieldableNode {
+public class FieldQueryNode extends QueryNodeImpl implements FieldValuePairQueryNode<CharSequence>, TextableQueryNode {
/**
* The term's field
@@ -180,4 +179,12 @@ public class FieldQueryNode extends Quer
}
+ public CharSequence getValue() {
+ return getText();
+ }
+
+ public void setValue(CharSequence value) {
+ setText(value);
+ }
+
}
Added: lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/FieldValuePairQueryNode.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/FieldValuePairQueryNode.java?rev=1144744&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/FieldValuePairQueryNode.java (added)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/FieldValuePairQueryNode.java Sat Jul 9 21:05:13 2011
@@ -0,0 +1,22 @@
+package org.apache.lucene.queryParser.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.
+ */
+
+public interface FieldValuePairQueryNode<T extends Object> extends FieldableNode, ValueQueryNode<T> {
+
+}
Added: lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/NumberQueryNode.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/NumberQueryNode.java?rev=1144744&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/NumberQueryNode.java (added)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/NumberQueryNode.java Sat Jul 9 21:05:13 2011
@@ -0,0 +1,26 @@
+package org.apache.lucene.queryParser.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.
+ */
+
+public interface NumberQueryNode {
+
+ void setNumber(Number number);
+
+ Number getNumber();
+
+}
Added: lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/ValueQueryNode.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/ValueQueryNode.java?rev=1144744&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/ValueQueryNode.java (added)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/ValueQueryNode.java Sat Jul 9 21:05:13 2011
@@ -0,0 +1,26 @@
+package org.apache.lucene.queryParser.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.
+ */
+
+public interface ValueQueryNode<T extends Object> extends QueryNode {
+
+ public void setValue(T value);
+
+ public T getValue();
+
+}
Modified: lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/StandardQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/StandardQueryParser.java?rev=1144744&r1=1144743&r2=1144744&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/StandardQueryParser.java (original)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/StandardQueryParser.java Sat Jul 9 21:05:13 2011
@@ -29,6 +29,7 @@ import org.apache.lucene.queryParser.cor
import org.apache.lucene.queryParser.core.config.QueryConfigHandler;
import org.apache.lucene.queryParser.standard.builders.StandardQueryTreeBuilder;
import org.apache.lucene.queryParser.standard.config.FuzzyConfig;
+import org.apache.lucene.queryParser.standard.config.NumericConfig;
import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler;
import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys;
import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.Operator;
@@ -109,7 +110,7 @@ import org.apache.lucene.search.Query;
* @see StandardQueryTreeBuilder
*/
public class StandardQueryParser extends QueryParserHelper {
-
+
/**
* Constructs a {@link StandardQueryParser} object.
*/
@@ -118,7 +119,7 @@ public class StandardQueryParser extends
new StandardQueryNodeProcessorPipeline(null),
new StandardQueryTreeBuilder());
}
-
+
/**
* Constructs a {@link StandardQueryParser} object and sets an
* {@link Analyzer} to it. The same as:
@@ -133,15 +134,16 @@ public class StandardQueryParser extends
*/
public StandardQueryParser(Analyzer analyzer) {
this();
-
+
this.setAnalyzer(analyzer);
}
@Override
- public String toString(){
- return "<StandardQueryParser config=\"" + this.getQueryConfigHandler() + "\"/>";
+ public String toString() {
+ return "<StandardQueryParser config=\"" + this.getQueryConfigHandler()
+ + "\"/>";
}
-
+
/**
* Overrides {@link QueryParserHelper#parse(String, String)} so it casts the
* return object to {@link Query}. For more reference about this method, check
@@ -160,11 +162,11 @@ public class StandardQueryParser extends
@Override
public Query parse(String query, String defaultField)
throws QueryNodeException {
-
+
return (Query) super.parse(query, defaultField);
-
+
}
-
+
/**
* Gets implicit operator setting, which will be either {@link Operator#AND}
* or {@link Operator#OR}.
@@ -172,7 +174,7 @@ public class StandardQueryParser extends
public StandardQueryConfigHandler.Operator getDefaultOperator() {
return getQueryConfigHandler().get(ConfigurationKeys.DEFAULT_OPERATOR);
}
-
+
/**
* Sets the boolean operator of the QueryParser. In default mode (
* {@link Operator#OR}) terms without any modifiers are considered optional:
@@ -184,7 +186,7 @@ public class StandardQueryParser extends
public void setDefaultOperator(StandardQueryConfigHandler.Operator operator) {
getQueryConfigHandler().set(ConfigurationKeys.DEFAULT_OPERATOR, operator);
}
-
+
/**
* Set to <code>true</code> to allow leading wildcard characters.
* <p>
@@ -197,7 +199,7 @@ public class StandardQueryParser extends
public void setLowercaseExpandedTerms(boolean lowercaseExpandedTerms) {
getQueryConfigHandler().set(ConfigurationKeys.LOWERCASE_EXPANDED_TERMS, lowercaseExpandedTerms);
}
-
+
/**
* @see #setLowercaseExpandedTerms(boolean)
*/
@@ -212,7 +214,7 @@ public class StandardQueryParser extends
}
}
-
+
/**
* Set to <code>true</code> to allow leading wildcard characters.
* <p>
@@ -225,7 +227,7 @@ public class StandardQueryParser extends
public void setAllowLeadingWildcard(boolean allowLeadingWildcard) {
getQueryConfigHandler().set(ConfigurationKeys.ALLOW_LEADING_WILDCARD, allowLeadingWildcard);
}
-
+
/**
* Set to <code>true</code> to enable position increments in result query.
* <p>
@@ -238,7 +240,7 @@ public class StandardQueryParser extends
public void setEnablePositionIncrements(boolean enabled) {
getQueryConfigHandler().set(ConfigurationKeys.ENABLE_POSITION_INCREMENTS, enabled);
}
-
+
/**
* @see #setEnablePositionIncrements(boolean)
*/
@@ -253,7 +255,7 @@ public class StandardQueryParser extends
}
}
-
+
/**
* By default, it uses
* {@link MultiTermQuery#CONSTANT_SCORE_AUTO_REWRITE_DEFAULT} when creating a
@@ -267,14 +269,14 @@ public class StandardQueryParser extends
public void setMultiTermRewriteMethod(MultiTermQuery.RewriteMethod method) {
getQueryConfigHandler().set(ConfigurationKeys.MULTI_TERM_REWRITE_METHOD, method);
}
-
+
/**
* @see #setMultiTermRewriteMethod(org.apache.lucene.search.MultiTermQuery.RewriteMethod)
*/
public MultiTermQuery.RewriteMethod getMultiTermRewriteMethod() {
return getQueryConfigHandler().get(ConfigurationKeys.MULTI_TERM_REWRITE_METHOD);
}
-
+
/**
* Set the fields a query should be expanded to when the field is
* <code>null</code>
@@ -282,15 +284,15 @@ public class StandardQueryParser extends
* @param fields the fields used to expand the query
*/
public void setMultiFields(CharSequence[] fields) {
-
+
if (fields == null) {
fields = new CharSequence[0];
}
getQueryConfigHandler().set(ConfigurationKeys.MULTI_FIELDS, fields);
-
+
}
-
+
/**
* Returns the fields used to expand the query when the field for a
* certain query is <code>null</code>
@@ -319,21 +321,29 @@ public class StandardQueryParser extends
fuzzyConfig.setPrefixLength(fuzzyPrefixLength);
}
-
+
+ public void setNumericConfigMap(Map<String,NumericConfig> numericConfigMap) {
+ getQueryConfigHandler().set(ConfigurationKeys.NUMERIC_CONFIG_MAP, numericConfigMap);
+ }
+
+ public Map<String,NumericConfig> getNumericConfigMap() {
+ return getQueryConfigHandler().get(ConfigurationKeys.NUMERIC_CONFIG_MAP);
+ }
+
/**
* Set locale used by date range parsing.
*/
public void setLocale(Locale locale) {
getQueryConfigHandler().set(ConfigurationKeys.LOCALE, locale);
}
-
+
/**
* Returns current locale, allowing access by subclasses.
*/
public Locale getLocale() {
return getQueryConfigHandler().get(ConfigurationKeys.LOCALE);
}
-
+
/**
* Sets the default slop for phrases. If zero, then exact phrase matches are
* required. Default value is zero.
@@ -357,10 +367,10 @@ public class StandardQueryParser extends
getQueryConfigHandler().set(ConfigurationKeys.ANALYZER, analyzer);
}
- public Analyzer getAnalyzer() {
+ public Analyzer getAnalyzer() {
return getQueryConfigHandler().get(ConfigurationKeys.ANALYZER);
}
-
+
/**
* @see #setAllowLeadingWildcard(boolean)
*/
@@ -374,7 +384,7 @@ public class StandardQueryParser extends
return allowLeadingWildcard;
}
}
-
+
/**
* Get the minimal similarity for fuzzy queries.
*/
@@ -387,7 +397,7 @@ public class StandardQueryParser extends
return fuzzyConfig.getMinSimilarity();
}
}
-
+
/**
* Get the prefix length for fuzzy queries.
*
@@ -402,7 +412,7 @@ public class StandardQueryParser extends
return fuzzyConfig.getPrefixLength();
}
}
-
+
/**
* Gets the default slop for phrases.
*/
@@ -416,7 +426,7 @@ public class StandardQueryParser extends
return phraseSlop;
}
}
-
+
/**
* Set the minimum similarity for fuzzy queries. Default is defined on
* {@link FuzzyQuery#defaultMinSimilarity}.
Added: lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/builders/DummyQueryNodeBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/builders/DummyQueryNodeBuilder.java?rev=1144744&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/builders/DummyQueryNodeBuilder.java (added)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/builders/DummyQueryNodeBuilder.java Sat Jul 9 21:05:13 2011
@@ -0,0 +1,38 @@
+package org.apache.lucene.queryParser.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.core.QueryNodeException;
+import org.apache.lucene.queryParser.core.nodes.FieldQueryNode;
+import org.apache.lucene.queryParser.core.nodes.QueryNode;
+import org.apache.lucene.search.TermQuery;
+
+/**
+ * Builds a {@link TermQuery} object from a {@link FieldQueryNode} object.
+ */
+public class DummyQueryNodeBuilder implements StandardQueryBuilder {
+
+ public DummyQueryNodeBuilder() {
+ // empty constructor
+ }
+
+ public TermQuery build(QueryNode queryNode) throws QueryNodeException {
+ return null;
+ }
+
+}
Added: lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/builders/NumericRangeQueryNodeBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/builders/NumericRangeQueryNodeBuilder.java?rev=1144744&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/builders/NumericRangeQueryNodeBuilder.java (added)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/builders/NumericRangeQueryNodeBuilder.java Sat Jul 9 21:05:13 2011
@@ -0,0 +1,93 @@
+package org.apache.lucene.queryParser.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.document.NumericField;
+import org.apache.lucene.messages.MessageImpl;
+import org.apache.lucene.queryParser.core.QueryNodeException;
+import org.apache.lucene.queryParser.core.messages.QueryParserMessages;
+import org.apache.lucene.queryParser.core.nodes.QueryNode;
+import org.apache.lucene.queryParser.core.util.StringUtils;
+import org.apache.lucene.queryParser.standard.config.NumericConfig;
+import org.apache.lucene.queryParser.standard.nodes.NumericQueryNode;
+import org.apache.lucene.queryParser.standard.nodes.NumericRangeQueryNode;
+import org.apache.lucene.search.NumericRangeQuery;
+
+public class NumericRangeQueryNodeBuilder implements StandardQueryBuilder {
+
+ public NumericRangeQueryNodeBuilder() {
+ // empty constructor
+ }
+
+ public NumericRangeQuery<? extends Number> build(QueryNode queryNode)
+ throws QueryNodeException {
+ NumericRangeQueryNode numericRangeNode = (NumericRangeQueryNode) queryNode;
+
+ NumericQueryNode lowerNumericNode = numericRangeNode.getLowerBound();
+ NumericQueryNode upperNumericNode = numericRangeNode.getUpperBound();
+
+ Number lowerNumber, upperNumber;
+
+ if (lowerNumericNode != null) {
+ lowerNumber = lowerNumericNode.getValue();
+ } else {
+ lowerNumber = null;
+ }
+
+ if (upperNumericNode != null) {
+ upperNumber = upperNumericNode.getValue();
+ } else {
+ upperNumber = null;
+ }
+
+ NumericConfig numericConfig = numericRangeNode.getNumericConfig();
+ NumericField.DataType numberType = numericConfig.getType();
+ String field = StringUtils.toString(numericRangeNode.getField());
+ boolean minInclusive = numericRangeNode.isLowerInclusive();
+ boolean maxInclusive = numericRangeNode.isUpperInclusive();
+ int precisionStep = numericConfig.getPrecisionStep();
+
+ switch (numberType) {
+
+ case LONG:
+ return NumericRangeQuery.newLongRange(field, precisionStep,
+ (Long) lowerNumber, (Long) upperNumber, minInclusive, maxInclusive);
+
+ case INT:
+ return NumericRangeQuery.newIntRange(field, precisionStep,
+ (Integer) lowerNumber, (Integer) upperNumber, minInclusive,
+ maxInclusive);
+
+ case FLOAT:
+ return NumericRangeQuery.newFloatRange(field, precisionStep,
+ (Float) lowerNumber, (Float) upperNumber, minInclusive,
+ maxInclusive);
+
+ case DOUBLE:
+ return NumericRangeQuery.newDoubleRange(field, precisionStep,
+ (Double) lowerNumber, (Double) upperNumber, minInclusive,
+ maxInclusive);
+
+ default :
+ throw new QueryNodeException(new MessageImpl(
+ QueryParserMessages.UNSUPPORTED_NUMERIC_DATA_TYPE, numberType));
+
+ }
+ }
+
+}
Modified: lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/builders/StandardQueryTreeBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/builders/StandardQueryTreeBuilder.java?rev=1144744&r1=1144743&r2=1144744&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/builders/StandardQueryTreeBuilder.java (original)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/builders/StandardQueryTreeBuilder.java Sat Jul 9 21:05:13 2011
@@ -31,8 +31,10 @@ import org.apache.lucene.queryParser.cor
import org.apache.lucene.queryParser.core.nodes.SlopQueryNode;
import org.apache.lucene.queryParser.core.nodes.TokenizedPhraseQueryNode;
import org.apache.lucene.queryParser.standard.nodes.MultiPhraseQueryNode;
+import org.apache.lucene.queryParser.standard.nodes.NumericQueryNode;
+import org.apache.lucene.queryParser.standard.nodes.NumericRangeQueryNode;
import org.apache.lucene.queryParser.standard.nodes.PrefixWildcardQueryNode;
-import org.apache.lucene.queryParser.standard.nodes.RangeQueryNode;
+import org.apache.lucene.queryParser.standard.nodes.TermRangeQueryNode;
import org.apache.lucene.queryParser.standard.nodes.RegexpQueryNode;
import org.apache.lucene.queryParser.standard.nodes.StandardBooleanQueryNode;
import org.apache.lucene.queryParser.standard.nodes.WildcardQueryNode;
@@ -50,12 +52,14 @@ import org.apache.lucene.search.Query;
*/
public class StandardQueryTreeBuilder extends QueryTreeBuilder implements
StandardQueryBuilder {
-
+
public StandardQueryTreeBuilder() {
setBuilder(GroupQueryNode.class, new GroupQueryNodeBuilder());
setBuilder(FieldQueryNode.class, new FieldQueryNodeBuilder());
setBuilder(BooleanQueryNode.class, new BooleanQueryNodeBuilder());
setBuilder(FuzzyQueryNode.class, new FuzzyQueryNodeBuilder());
+ setBuilder(NumericQueryNode.class, new DummyQueryNodeBuilder());
+ setBuilder(NumericRangeQueryNode.class, new NumericRangeQueryNodeBuilder());
setBuilder(BoostQueryNode.class, new BoostQueryNodeBuilder());
setBuilder(ModifierQueryNode.class, new ModifierQueryNodeBuilder());
setBuilder(WildcardQueryNode.class, new WildcardQueryNodeBuilder());
@@ -63,19 +67,19 @@ public class StandardQueryTreeBuilder ex
setBuilder(MatchNoDocsQueryNode.class, new MatchNoDocsQueryNodeBuilder());
setBuilder(PrefixWildcardQueryNode.class,
new PrefixWildcardQueryNodeBuilder());
- setBuilder(RangeQueryNode.class, new RangeQueryNodeBuilder());
+ setBuilder(TermRangeQueryNode.class, new TermRangeQueryNodeBuilder());
setBuilder(RegexpQueryNode.class, new RegexpQueryNodeBuilder());
setBuilder(SlopQueryNode.class, new SlopQueryNodeBuilder());
setBuilder(StandardBooleanQueryNode.class,
new StandardBooleanQueryNodeBuilder());
setBuilder(MultiPhraseQueryNode.class, new MultiPhraseQueryNodeBuilder());
setBuilder(MatchAllDocsQueryNode.class, new MatchAllDocsQueryNodeBuilder());
-
+
}
-
+
@Override
public Query build(QueryNode queryNode) throws QueryNodeException {
return (Query) super.build(queryNode);
}
-
+
}
Added: lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/builders/TermRangeQueryNodeBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/builders/TermRangeQueryNodeBuilder.java?rev=1144744&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/builders/TermRangeQueryNodeBuilder.java (added)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/builders/TermRangeQueryNodeBuilder.java Sat Jul 9 21:05:13 2011
@@ -0,0 +1,60 @@
+package org.apache.lucene.queryParser.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.core.QueryNodeException;
+import org.apache.lucene.queryParser.core.nodes.FieldQueryNode;
+import org.apache.lucene.queryParser.core.nodes.QueryNode;
+import org.apache.lucene.queryParser.core.util.StringUtils;
+import org.apache.lucene.queryParser.standard.nodes.TermRangeQueryNode;
+import org.apache.lucene.queryParser.standard.processors.MultiTermRewriteMethodProcessor;
+import org.apache.lucene.search.MultiTermQuery;
+import org.apache.lucene.search.TermRangeQuery;
+
+/**
+ * Builds a {@link TermRangeQuery} object from a {@link TermRangeQueryNode}
+ * object.
+ */
+public class TermRangeQueryNodeBuilder implements StandardQueryBuilder {
+
+ public TermRangeQueryNodeBuilder() {
+ // empty constructor
+ }
+
+ public TermRangeQuery build(QueryNode queryNode) throws QueryNodeException {
+ TermRangeQueryNode rangeNode = (TermRangeQueryNode) queryNode;
+ FieldQueryNode upper = rangeNode.getUpperBound();
+ FieldQueryNode lower = rangeNode.getLowerBound();
+
+ String field = StringUtils.toString(rangeNode.getField());
+
+ TermRangeQuery rangeQuery = TermRangeQuery.newStringRange(field, lower
+ .getTextAsString(), upper.getTextAsString(), rangeNode
+ .isLowerInclusive(), rangeNode.isUpperInclusive());
+
+ MultiTermQuery.RewriteMethod method = (MultiTermQuery.RewriteMethod) queryNode
+ .getTag(MultiTermRewriteMethodProcessor.TAG_ID);
+ if (method != null) {
+ rangeQuery.setRewriteMethod(method);
+ }
+
+ return rangeQuery;
+
+ }
+
+}
Added: lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/NumberDateFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/NumberDateFormat.java?rev=1144744&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/NumberDateFormat.java (added)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/NumberDateFormat.java Sat Jul 9 21:05:13 2011
@@ -0,0 +1,59 @@
+package org.apache.lucene.queryParser.standard.config;
+
+/**
+ * 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 java.text.DateFormat;
+import java.text.FieldPosition;
+import java.text.NumberFormat;
+import java.text.ParsePosition;
+import java.util.Date;
+
+public class NumberDateFormat extends NumberFormat {
+
+ private static final long serialVersionUID = 964823936071308283L;
+
+ final private DateFormat dateFormat;
+
+ public NumberDateFormat(DateFormat dateFormat) {
+ this.dateFormat = dateFormat;
+ }
+
+ @Override
+ public StringBuffer format(double number, StringBuffer toAppendTo,
+ FieldPosition pos) {
+ return dateFormat.format(new Date((long) number), toAppendTo, pos);
+ }
+
+ @Override
+ public StringBuffer format(long number, StringBuffer toAppendTo,
+ FieldPosition pos) {
+ return dateFormat.format(new Date(number), toAppendTo, pos);
+ }
+
+ @Override
+ public Number parse(String source, ParsePosition parsePosition) {
+ return dateFormat.parse(source, parsePosition).getTime();
+ }
+
+ @Override
+ public StringBuffer format(Object number, StringBuffer toAppendTo,
+ FieldPosition pos) {
+ return dateFormat.format(number, toAppendTo, pos);
+ }
+
+}
Added: lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/NumericConfig.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/NumericConfig.java?rev=1144744&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/NumericConfig.java (added)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/NumericConfig.java Sat Jul 9 21:05:13 2011
@@ -0,0 +1,94 @@
+package org.apache.lucene.queryParser.standard.config;
+
+/**
+ * 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 java.text.NumberFormat;
+
+import org.apache.lucene.document.NumericField;
+
+public class NumericConfig {
+
+ private int precisionStep;
+
+ private NumberFormat format;
+
+ private NumericField.DataType type;
+
+ public NumericConfig(int precisionStep, NumberFormat format, NumericField.DataType type) {
+ setPrecisionStep(precisionStep);
+ setNumberFormat(format);
+ setType(type);
+
+ }
+
+ public int getPrecisionStep() {
+ return precisionStep;
+ }
+
+ public void setPrecisionStep(int precisionStep) {
+ this.precisionStep = precisionStep;
+ }
+
+ public NumberFormat getNumberFormat() {
+ return format;
+ }
+
+ public NumericField.DataType getType() {
+ return type;
+ }
+
+ public void setType(NumericField.DataType type) {
+
+ if (type == null) {
+ throw new IllegalArgumentException("type cannot be null!");
+ }
+
+ this.type = type;
+
+ }
+
+ public void setNumberFormat(NumberFormat format) {
+
+ if (format == null) {
+ throw new IllegalArgumentException("format cannot be null!");
+ }
+
+ this.format = format;
+
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+
+ if (obj == this) return true;
+
+ if (obj instanceof NumericConfig) {
+ NumericConfig other = (NumericConfig) obj;
+
+ if (this.precisionStep == other.precisionStep
+ && this.format == other.format) {
+ return true;
+ }
+
+ }
+
+ return false;
+
+ }
+
+}
Added: lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/NumericFieldConfigListener.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/NumericFieldConfigListener.java?rev=1144744&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/NumericFieldConfigListener.java (added)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/NumericFieldConfigListener.java Sat Jul 9 21:05:13 2011
@@ -0,0 +1,57 @@
+package org.apache.lucene.queryParser.standard.config;
+
+/**
+ * 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 java.util.Map;
+
+import org.apache.lucene.queryParser.core.config.FieldConfig;
+import org.apache.lucene.queryParser.core.config.FieldConfigListener;
+import org.apache.lucene.queryParser.core.config.QueryConfigHandler;
+import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys;
+
+public class NumericFieldConfigListener implements FieldConfigListener {
+
+ final private QueryConfigHandler config;
+
+ public NumericFieldConfigListener(QueryConfigHandler config) {
+
+ if (config == null) {
+ throw new IllegalArgumentException("config cannot be null!");
+ }
+
+ this.config = config;
+
+ }
+
+ public void buildFieldConfig(FieldConfig fieldConfig) {
+ Map<String,NumericConfig> numericConfigMap = config
+ .get(ConfigurationKeys.NUMERIC_CONFIG_MAP);
+
+ if (numericConfigMap != null) {
+ NumericConfig numericConfig = numericConfigMap
+ .get(fieldConfig.getField());
+
+ if (numericConfig != null) {
+ fieldConfig.set(ConfigurationKeys.NUMERIC_CONFIG, numericConfig);
+ }
+
+ }
+
+ }
+
+}
Modified: lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/StandardQueryConfigHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/StandardQueryConfigHandler.java?rev=1144744&r1=1144743&r2=1144744&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/StandardQueryConfigHandler.java (original)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/StandardQueryConfigHandler.java Sat Jul 9 21:05:13 2011
@@ -161,6 +161,22 @@ public class StandardQueryConfigHandler
*/
final public static ConfigurationKey<Float> BOOST = ConfigurationKey.newInstance();
+ /**
+ * Key used to set a field to its {@link NumericConfig}.
+ *
+ * @see StandardQueryParser#setNumericConfigMap(Map)
+ * @see StandardQueryParser#getNumericConfigMap()
+ */
+ final public static ConfigurationKey<NumericConfig> NUMERIC_CONFIG = ConfigurationKey.newInstance();
+
+ /**
+ * Key used to set the {@link NumericConfig} in {@link FieldConfig} for numeric fields.
+ *
+ * @see StandardQueryParser#setNumericConfigMap(Map)
+ * @see StandardQueryParser#getNumericConfigMap()
+ */
+ final public static ConfigurationKey<Map<String,NumericConfig>> NUMERIC_CONFIG_MAP = ConfigurationKey.newInstance();
+
}
public static enum Operator {
@@ -171,6 +187,7 @@ public class StandardQueryConfigHandler
// Add listener that will build the FieldConfig.
addFieldConfigListener(new FieldBoostMapFCListener(this));
addFieldConfigListener(new FieldDateResolutionFCListener(this));
+ addFieldConfigListener(new NumericFieldConfigListener(this));
// Default Values
set(ConfigurationKeys.ALLOW_LEADING_WILDCARD, false); // default in 2.9
Added: lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/nodes/AbstractRangeQueryNode.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/nodes/AbstractRangeQueryNode.java?rev=1144744&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/nodes/AbstractRangeQueryNode.java (added)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/nodes/AbstractRangeQueryNode.java Sat Jul 9 21:05:13 2011
@@ -0,0 +1,153 @@
+package org.apache.lucene.queryParser.standard.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 java.util.ArrayList;
+
+import org.apache.lucene.queryParser.core.nodes.FieldValuePairQueryNode;
+import org.apache.lucene.queryParser.core.nodes.FieldableNode;
+import org.apache.lucene.queryParser.core.nodes.QueryNode;
+import org.apache.lucene.queryParser.core.nodes.QueryNodeImpl;
+import org.apache.lucene.queryParser.core.parser.EscapeQuerySyntax;
+import org.apache.lucene.queryParser.core.util.StringUtils;
+
+public abstract class AbstractRangeQueryNode<T extends FieldValuePairQueryNode<?>>
+ extends QueryNodeImpl implements FieldableNode {
+
+ private boolean lowerInclusive, upperInclusive;
+
+ protected AbstractRangeQueryNode() {
+ setLeaf(false);
+ allocate();
+ }
+
+ public CharSequence getField() {
+ CharSequence field = null;
+ T lower = getLowerBound();
+ T upper = getUpperBound();
+
+ if (lower != null) {
+ field = lower.getField();
+
+ } else if (upper != null) {
+ field = upper.getField();
+ }
+
+ return field;
+
+ }
+
+ public void setField(CharSequence fieldName) {
+ T lower = getLowerBound();
+ T upper = getUpperBound();
+
+ if (lower != null) {
+ lower.setField(fieldName);
+ }
+
+ if (upper != null) {
+ upper.setField(fieldName);
+ }
+
+ }
+
+ @SuppressWarnings("unchecked")
+ public T getLowerBound() {
+ return (T) getChildren().get(0);
+ }
+
+ @SuppressWarnings("unchecked")
+ public T getUpperBound() {
+ return (T) getChildren().get(1);
+ }
+
+ public boolean isLowerInclusive() {
+ return lowerInclusive;
+ }
+
+ public boolean isUpperInclusive() {
+ return upperInclusive;
+ }
+
+ public void setBounds(T lower, T upper, boolean lowerInclusive,
+ boolean upperInclusive) {
+
+ if (lower != null && upper != null) {
+ String lowerField = StringUtils.toString(lower.getField());
+ String upperField = StringUtils.toString(upper.getField());
+
+ if ((upperField == null && lowerField == null)
+ || (upperField != null && !upperField.equals(lowerField))) {
+ throw new IllegalArgumentException(
+ "lower and upper bounds should have the same field name!");
+ }
+
+ this.lowerInclusive = lowerInclusive;
+ this.upperInclusive = upperInclusive;
+
+ ArrayList<QueryNode> children = new ArrayList<QueryNode>(2);
+ children.add(lower);
+ children.add(upper);
+
+ set(children);
+
+ }
+
+ }
+
+ public CharSequence toQueryString(EscapeQuerySyntax escapeSyntaxParser) {
+ StringBuilder sb = new StringBuilder();
+
+ T lower = getLowerBound();
+ T upper = getUpperBound();
+
+ if (lowerInclusive) {
+ sb.append('[');
+
+ } else {
+ sb.append('{');
+ }
+
+ if (lower != null) {
+ sb.append(lower.toQueryString(escapeSyntaxParser));
+
+ } else {
+ sb.append("...");
+ }
+
+ sb.append(' ');
+
+ if (upper != null) {
+ sb.append(upper.toQueryString(escapeSyntaxParser));
+
+ } else {
+ sb.append("...");
+ }
+
+ if (upperInclusive) {
+ sb.append(']');
+
+ } else {
+ sb.append('}');
+ }
+
+ return sb.toString();
+
+ }
+
+}
Added: lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/nodes/NumericQueryNode.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/nodes/NumericQueryNode.java?rev=1144744&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/nodes/NumericQueryNode.java (added)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/nodes/NumericQueryNode.java Sat Jul 9 21:05:13 2011
@@ -0,0 +1,91 @@
+package org.apache.lucene.queryParser.standard.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 java.text.NumberFormat;
+import java.util.Locale;
+
+import org.apache.lucene.queryParser.core.nodes.FieldValuePairQueryNode;
+import org.apache.lucene.queryParser.core.nodes.QueryNodeImpl;
+import org.apache.lucene.queryParser.core.parser.EscapeQuerySyntax;
+import org.apache.lucene.queryParser.core.parser.EscapeQuerySyntax.Type;
+
+public class NumericQueryNode extends QueryNodeImpl implements
+ FieldValuePairQueryNode<Number> {
+
+ private NumberFormat numberFormat;
+
+ private CharSequence field;
+
+ private Number value;
+
+ public NumericQueryNode(CharSequence field, Number value,
+ NumberFormat numberFormat) {
+
+ super();
+
+ setNumberFormat(numberFormat);
+ setField(field);
+ setValue(value);
+
+ }
+
+ public CharSequence getField() {
+ return this.field;
+ }
+
+ public void setField(CharSequence fieldName) {
+ this.field = fieldName;
+ }
+
+ protected CharSequence getTermEscaped(EscapeQuerySyntax escaper) {
+ return escaper.escape(NumberFormat.getNumberInstance().format(this.value),
+ Locale.ENGLISH, Type.NORMAL);
+ }
+
+ public CharSequence toQueryString(EscapeQuerySyntax escapeSyntaxParser) {
+ if (isDefaultField(this.field)) {
+ return getTermEscaped(escapeSyntaxParser);
+ } else {
+ return this.field + ":" + getTermEscaped(escapeSyntaxParser);
+ }
+ }
+
+ public void setNumberFormat(NumberFormat format) {
+ this.numberFormat = format;
+ }
+
+ public NumberFormat getNumberFormat() {
+ return this.numberFormat;
+ }
+
+ public Number getValue() {
+ return value;
+ }
+
+ public void setValue(Number value) {
+ this.value = value;
+ }
+
+ @Override
+ public String toString() {
+ return "<numeric field='" + this.field + "' number='"
+ + numberFormat.format(value) + "'/>";
+ }
+
+}
Added: lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/nodes/NumericRangeQueryNode.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/nodes/NumericRangeQueryNode.java?rev=1144744&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/nodes/NumericRangeQueryNode.java (added)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/nodes/NumericRangeQueryNode.java Sat Jul 9 21:05:13 2011
@@ -0,0 +1,116 @@
+package org.apache.lucene.queryParser.standard.nodes;
+
+import org.apache.lucene.document.NumericField;
+import org.apache.lucene.messages.MessageImpl;
+import org.apache.lucene.queryParser.core.QueryNodeException;
+import org.apache.lucene.queryParser.core.messages.QueryParserMessages;
+import org.apache.lucene.queryParser.standard.config.NumericConfig;
+
+/**
+ * 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.
+ */
+
+public class NumericRangeQueryNode extends
+ AbstractRangeQueryNode<NumericQueryNode> {
+
+ public NumericConfig numericConfig;
+
+ public NumericRangeQueryNode(NumericQueryNode lower, NumericQueryNode upper,
+ boolean lowerInclusive, boolean upperInclusive, NumericConfig numericConfig) throws QueryNodeException {
+ setBounds(lower, upper, lowerInclusive, upperInclusive, numericConfig);
+ }
+
+ private static NumericField.DataType getNumericDataType(Number number) throws QueryNodeException {
+
+ if (number instanceof Long) {
+ return NumericField.DataType.LONG;
+ } else if (number instanceof Integer) {
+ return NumericField.DataType.INT;
+ } else if (number instanceof Double) {
+ return NumericField.DataType.DOUBLE;
+ } else if (number instanceof Float) {
+ return NumericField.DataType.FLOAT;
+ } else {
+ throw new QueryNodeException(
+ new MessageImpl(
+ QueryParserMessages.NUMBER_CLASS_NOT_SUPPORTED_BY_NUMERIC_RANGE_QUERY,
+ number.getClass()));
+ }
+
+ }
+
+ public void setBounds(NumericQueryNode lower, NumericQueryNode upper,
+ boolean lowerInclusive, boolean upperInclusive, NumericConfig numericConfig) throws QueryNodeException {
+
+ if (numericConfig == null) {
+ throw new IllegalArgumentException("numericConfig cannot be null!");
+ }
+
+ NumericField.DataType lowerNumberType, upperNumberType;
+
+ if (lower != null && lower.getValue() != null) {
+ lowerNumberType = getNumericDataType(lower.getValue());
+ } else {
+ lowerNumberType = null;
+ }
+
+ if (upper != null && upper.getValue() != null) {
+ upperNumberType = getNumericDataType(upper.getValue());
+ } else {
+ upperNumberType = null;
+ }
+
+ if (lowerNumberType != null
+ && !lowerNumberType.equals(numericConfig.getType())) {
+ throw new IllegalArgumentException(
+ "lower value's type should be the same as numericConfig type: "
+ + lowerNumberType + " != " + numericConfig.getType());
+ }
+
+ if (upperNumberType != null
+ && !upperNumberType.equals(numericConfig.getType())) {
+ throw new IllegalArgumentException(
+ "upper value's type should be the same as numericConfig type: "
+ + upperNumberType + " != " + numericConfig.getType());
+ }
+
+ super.setBounds(lower, upper, lowerInclusive, upperInclusive);
+ this.numericConfig = numericConfig;
+
+ }
+
+ public NumericConfig getNumericConfig() {
+ return this.numericConfig;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder("<numericRange lowerInclusive='");
+
+ sb.append(isLowerInclusive()).append("' upperInclusive='").append(
+ isUpperInclusive()).append(
+ "' precisionStep='" + numericConfig.getPrecisionStep()).append(
+ "' type='" + numericConfig.getType()).append("'>\n");
+
+ sb.append(getLowerBound()).append('\n');
+ sb.append(getUpperBound()).append('\n');
+ sb.append("</numericRange>");
+
+ return sb.toString();
+
+ }
+
+}
Added: lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/nodes/TermRangeQueryNode.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/nodes/TermRangeQueryNode.java?rev=1144744&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/nodes/TermRangeQueryNode.java (added)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/nodes/TermRangeQueryNode.java Sat Jul 9 21:05:13 2011
@@ -0,0 +1,35 @@
+package org.apache.lucene.queryParser.standard.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.core.nodes.FieldQueryNode;
+
+/**
+ * This query node represents a range query.
+ *
+ * @see ParametricRangeQueryNodeProcessor
+ * @see org.apache.lucene.search.TermRangeQuery
+ */
+public class TermRangeQueryNode extends AbstractRangeQueryNode<FieldQueryNode> {
+
+ public TermRangeQueryNode(FieldQueryNode lower, FieldQueryNode upper,
+ boolean lowerInclusive, boolean upperInclusive) {
+ setBounds(lower, upper, lowerInclusive, upperInclusive);
+ }
+
+}
Modified: lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/AnalyzerQueryNodeProcessor.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/AnalyzerQueryNodeProcessor.java?rev=1144744&r1=1144743&r2=1144744&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/AnalyzerQueryNodeProcessor.java (original)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/AnalyzerQueryNodeProcessor.java Sat Jul 9 21:05:13 2011
@@ -40,7 +40,6 @@ import org.apache.lucene.queryParser.cor
import org.apache.lucene.queryParser.core.nodes.TextableQueryNode;
import org.apache.lucene.queryParser.core.nodes.TokenizedPhraseQueryNode;
import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorImpl;
-import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler;
import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys;
import org.apache.lucene.queryParser.standard.nodes.MultiPhraseQueryNode;
import org.apache.lucene.queryParser.standard.nodes.StandardBooleanQueryNode;
Modified: lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/DefaultPhraseSlopQueryNodeProcessor.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/DefaultPhraseSlopQueryNodeProcessor.java?rev=1144744&r1=1144743&r2=1144744&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/DefaultPhraseSlopQueryNodeProcessor.java (original)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/DefaultPhraseSlopQueryNodeProcessor.java Sat Jul 9 21:05:13 2011
@@ -25,7 +25,6 @@ import org.apache.lucene.queryParser.cor
import org.apache.lucene.queryParser.core.nodes.SlopQueryNode;
import org.apache.lucene.queryParser.core.nodes.TokenizedPhraseQueryNode;
import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorImpl;
-import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler;
import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys;
import org.apache.lucene.queryParser.standard.nodes.MultiPhraseQueryNode;
Modified: lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/FuzzyQueryNodeProcessor.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/FuzzyQueryNodeProcessor.java?rev=1144744&r1=1144743&r2=1144744&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/FuzzyQueryNodeProcessor.java (original)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/FuzzyQueryNodeProcessor.java Sat Jul 9 21:05:13 2011
@@ -25,7 +25,6 @@ import org.apache.lucene.queryParser.cor
import org.apache.lucene.queryParser.core.nodes.QueryNode;
import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorImpl;
import org.apache.lucene.queryParser.standard.config.FuzzyConfig;
-import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler;
import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys;
import org.apache.lucene.search.FuzzyQuery;
Modified: lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/LowercaseExpandedTermsQueryNodeProcessor.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/LowercaseExpandedTermsQueryNodeProcessor.java?rev=1144744&r1=1144743&r2=1144744&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/LowercaseExpandedTermsQueryNodeProcessor.java (original)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/LowercaseExpandedTermsQueryNodeProcessor.java Sat Jul 9 21:05:13 2011
@@ -27,7 +27,6 @@ import org.apache.lucene.queryParser.cor
import org.apache.lucene.queryParser.core.nodes.TextableQueryNode;
import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorImpl;
import org.apache.lucene.queryParser.core.util.UnescapedCharSequence;
-import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler;
import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys;
import org.apache.lucene.queryParser.standard.nodes.RegexpQueryNode;
import org.apache.lucene.queryParser.standard.nodes.WildcardQueryNode;
Modified: lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/MultiFieldQueryNodeProcessor.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/MultiFieldQueryNodeProcessor.java?rev=1144744&r1=1144743&r2=1144744&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/MultiFieldQueryNodeProcessor.java (original)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/MultiFieldQueryNodeProcessor.java Sat Jul 9 21:05:13 2011
@@ -27,7 +27,6 @@ import org.apache.lucene.queryParser.cor
import org.apache.lucene.queryParser.core.nodes.GroupQueryNode;
import org.apache.lucene.queryParser.core.nodes.QueryNode;
import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorImpl;
-import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler;
import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys;
/**
Modified: lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/MultiTermRewriteMethodProcessor.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/MultiTermRewriteMethodProcessor.java?rev=1144744&r1=1144743&r2=1144744&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/MultiTermRewriteMethodProcessor.java (original)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/MultiTermRewriteMethodProcessor.java Sat Jul 9 21:05:13 2011
@@ -19,10 +19,10 @@ package org.apache.lucene.queryParser.st
import java.util.List;
-import org.apache.lucene.queryParser.core.nodes.ParametricRangeQueryNode;
import org.apache.lucene.queryParser.core.nodes.QueryNode;
import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorImpl;
import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys;
+import org.apache.lucene.queryParser.standard.nodes.AbstractRangeQueryNode;
import org.apache.lucene.queryParser.standard.nodes.RegexpQueryNode;
import org.apache.lucene.queryParser.standard.nodes.WildcardQueryNode;
import org.apache.lucene.search.MultiTermQuery;
@@ -43,7 +43,7 @@ public class MultiTermRewriteMethodProce
// set setMultiTermRewriteMethod for WildcardQueryNode and
// PrefixWildcardQueryNode
if (node instanceof WildcardQueryNode
- || node instanceof ParametricRangeQueryNode || node instanceof RegexpQueryNode) {
+ || node instanceof AbstractRangeQueryNode || node instanceof RegexpQueryNode) {
MultiTermQuery.RewriteMethod rewriteMethod = getQueryConfigHandler().get(ConfigurationKeys.MULTI_TERM_REWRITE_METHOD);
Added: lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/NumericQueryNodeProcessor.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/NumericQueryNodeProcessor.java?rev=1144744&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/NumericQueryNodeProcessor.java (added)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/NumericQueryNodeProcessor.java Sat Jul 9 21:05:13 2011
@@ -0,0 +1,122 @@
+package org.apache.lucene.queryParser.standard.processors;
+
+/**
+ * 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 java.text.NumberFormat;
+import java.text.ParseException;
+import java.util.List;
+
+import org.apache.lucene.messages.MessageImpl;
+import org.apache.lucene.queryParser.core.QueryNodeException;
+import org.apache.lucene.queryParser.core.QueryNodeParseException;
+import org.apache.lucene.queryParser.core.config.FieldConfig;
+import org.apache.lucene.queryParser.core.config.QueryConfigHandler;
+import org.apache.lucene.queryParser.core.messages.QueryParserMessages;
+import org.apache.lucene.queryParser.core.nodes.FieldQueryNode;
+import org.apache.lucene.queryParser.core.nodes.ParametricQueryNode;
+import org.apache.lucene.queryParser.core.nodes.QueryNode;
+import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorImpl;
+import org.apache.lucene.queryParser.standard.config.NumericConfig;
+import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys;
+import org.apache.lucene.queryParser.standard.nodes.NumericQueryNode;
+import org.apache.lucene.queryParser.standard.nodes.NumericRangeQueryNode;
+
+public class NumericQueryNodeProcessor extends QueryNodeProcessorImpl {
+
+ public NumericQueryNodeProcessor() {
+ // empty constructor
+ }
+
+ @Override
+ protected QueryNode postProcessNode(QueryNode node) throws QueryNodeException {
+
+ if (node instanceof FieldQueryNode
+ && !(node instanceof ParametricQueryNode)) {
+
+ QueryConfigHandler config = getQueryConfigHandler();
+
+ if (config != null) {
+ FieldQueryNode fieldNode = (FieldQueryNode) node;
+ FieldConfig fieldConfig = config.getFieldConfig(fieldNode
+ .getFieldAsString());
+
+ if (fieldConfig != null) {
+ NumericConfig numericConfig = fieldConfig
+ .get(ConfigurationKeys.NUMERIC_CONFIG);
+
+ if (numericConfig != null) {
+
+ NumberFormat numberFormat = numericConfig.getNumberFormat();
+ Number number;
+
+ try {
+ number = numberFormat.parse(fieldNode.getTextAsString());
+
+ } catch (ParseException e) {
+ throw new QueryNodeParseException(new MessageImpl(
+ QueryParserMessages.COULD_NOT_PARSE_NUMBER, fieldNode
+ .getTextAsString(), numberFormat.getClass()
+ .getCanonicalName()), e);
+ }
+
+ switch (numericConfig.getType()) {
+ case LONG:
+ number = number.longValue();
+ break;
+ case INT:
+ number = number.intValue();
+ break;
+ case DOUBLE:
+ number = number.doubleValue();
+ break;
+ case FLOAT:
+ number = number.floatValue();
+ }
+
+ NumericQueryNode lowerNode = new NumericQueryNode(fieldNode
+ .getField(), number, numberFormat);
+ NumericQueryNode upperNode = new NumericQueryNode(fieldNode
+ .getField(), number, numberFormat);
+
+ return new NumericRangeQueryNode(lowerNode, upperNode, true, true,
+ numericConfig);
+
+ }
+
+ }
+
+ }
+
+ }
+
+ return node;
+
+ }
+
+ @Override
+ protected QueryNode preProcessNode(QueryNode node) throws QueryNodeException {
+ return node;
+ }
+
+ @Override
+ protected List<QueryNode> setChildrenOrder(List<QueryNode> children)
+ throws QueryNodeException {
+ return children;
+ }
+
+}
Added: lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/NumericRangeQueryNodeProcessor.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/NumericRangeQueryNodeProcessor.java?rev=1144744&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/NumericRangeQueryNodeProcessor.java (added)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/NumericRangeQueryNodeProcessor.java Sat Jul 9 21:05:13 2011
@@ -0,0 +1,143 @@
+package org.apache.lucene.queryParser.standard.processors;
+
+/**
+ * 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 java.text.NumberFormat;
+import java.text.ParseException;
+import java.util.List;
+
+import org.apache.lucene.messages.MessageImpl;
+import org.apache.lucene.queryParser.core.QueryNodeException;
+import org.apache.lucene.queryParser.core.QueryNodeParseException;
+import org.apache.lucene.queryParser.core.config.FieldConfig;
+import org.apache.lucene.queryParser.core.config.QueryConfigHandler;
+import org.apache.lucene.queryParser.core.messages.QueryParserMessages;
+import org.apache.lucene.queryParser.core.nodes.ParametricQueryNode;
+import org.apache.lucene.queryParser.core.nodes.ParametricRangeQueryNode;
+import org.apache.lucene.queryParser.core.nodes.QueryNode;
+import org.apache.lucene.queryParser.core.nodes.ParametricQueryNode.CompareOperator;
+import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorImpl;
+import org.apache.lucene.queryParser.core.util.StringUtils;
+import org.apache.lucene.queryParser.standard.config.NumericConfig;
+import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys;
+import org.apache.lucene.queryParser.standard.nodes.NumericQueryNode;
+import org.apache.lucene.queryParser.standard.nodes.NumericRangeQueryNode;
+
+public class NumericRangeQueryNodeProcessor extends QueryNodeProcessorImpl {
+
+ public NumericRangeQueryNodeProcessor() {
+ // empty constructor
+ }
+
+ @Override
+ protected QueryNode postProcessNode(QueryNode node) throws QueryNodeException {
+
+ if (node instanceof ParametricRangeQueryNode) {
+ QueryConfigHandler config = getQueryConfigHandler();
+
+ if (config != null) {
+ ParametricRangeQueryNode parametricRangeNode = (ParametricRangeQueryNode) node;
+ FieldConfig fieldConfig = config.getFieldConfig(StringUtils
+ .toString(parametricRangeNode.getField()));
+
+ if (fieldConfig != null) {
+
+ NumericConfig numericConfig = fieldConfig
+ .get(ConfigurationKeys.NUMERIC_CONFIG);
+
+ if (numericConfig != null) {
+
+ ParametricQueryNode lower = parametricRangeNode.getLowerBound();
+ ParametricQueryNode upper = parametricRangeNode.getUpperBound();
+
+ NumberFormat numberFormat = numericConfig.getNumberFormat();
+ Number lowerNumber, upperNumber;
+
+ try {
+ lowerNumber = numberFormat.parse(lower.getTextAsString());
+
+ } catch (ParseException e) {
+ throw new QueryNodeParseException(new MessageImpl(
+ QueryParserMessages.COULD_NOT_PARSE_NUMBER, lower
+ .getTextAsString(), numberFormat.getClass()
+ .getCanonicalName()), e);
+ }
+
+ try {
+ upperNumber = numberFormat.parse(upper.getTextAsString());
+
+ } catch (ParseException e) {
+ throw new QueryNodeParseException(new MessageImpl(
+ QueryParserMessages.COULD_NOT_PARSE_NUMBER, upper
+ .getTextAsString(), numberFormat.getClass()
+ .getCanonicalName()), e);
+ }
+
+ switch (numericConfig.getType()) {
+ case LONG:
+ upperNumber = upperNumber.longValue();
+ lowerNumber = lowerNumber.longValue();
+ break;
+ case INT:
+ upperNumber = upperNumber.intValue();
+ lowerNumber = lowerNumber.intValue();
+ break;
+ case DOUBLE:
+ upperNumber = upperNumber.doubleValue();
+ lowerNumber = lowerNumber.doubleValue();
+ break;
+ case FLOAT:
+ upperNumber = upperNumber.floatValue();
+ lowerNumber = lowerNumber.floatValue();
+ }
+
+ NumericQueryNode lowerNode = new NumericQueryNode(
+ parametricRangeNode.getField(), lowerNumber, numberFormat);
+ NumericQueryNode upperNode = new NumericQueryNode(
+ parametricRangeNode.getField(), upperNumber, numberFormat);
+
+ boolean upperInclusive = upper.getOperator() == CompareOperator.LE;
+ boolean lowerInclusive = lower.getOperator() == CompareOperator.GE;
+
+ return new NumericRangeQueryNode(lowerNode, upperNode,
+ lowerInclusive, upperInclusive, numericConfig);
+
+ }
+
+ }
+
+ }
+
+ }
+
+ return node;
+
+ }
+
+ @Override
+ protected QueryNode preProcessNode(QueryNode node) throws QueryNodeException {
+ return node;
+ }
+
+ @Override
+ protected List<QueryNode> setChildrenOrder(List<QueryNode> children)
+ throws QueryNodeException {
+ return children;
+ }
+
+}
Modified: lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/ParametricRangeQueryNodeProcessor.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/ParametricRangeQueryNodeProcessor.java?rev=1144744&r1=1144743&r2=1144744&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/ParametricRangeQueryNodeProcessor.java (original)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/ParametricRangeQueryNodeProcessor.java Sat Jul 9 21:05:13 2011
@@ -33,17 +33,16 @@ import org.apache.lucene.queryParser.cor
import org.apache.lucene.queryParser.core.nodes.QueryNode;
import org.apache.lucene.queryParser.core.nodes.ParametricQueryNode.CompareOperator;
import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorImpl;
-import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler;
import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys;
-import org.apache.lucene.queryParser.standard.nodes.RangeQueryNode;
+import org.apache.lucene.queryParser.standard.nodes.TermRangeQueryNode;
/**
* This processor converts {@link ParametricRangeQueryNode} objects to
- * {@link RangeQueryNode} objects. It reads the lower and upper bounds value
+ * {@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 RangeQueryNode} using the non-parsed
- * values. <br/>
+ * value, it will only create the {@link TermRangeQueryNode} using the
+ * non-parsed values. <br/>
* <br/>
* If a {@link ConfigurationKeys#LOCALE} is defined in the {@link QueryConfigHandler} it
* will be used to parse the date, otherwise {@link Locale#getDefault()} will be
@@ -55,18 +54,18 @@ import org.apache.lucene.queryParser.sta
*
* @see ConfigurationKeys#DATE_RESOLUTION
* @see ConfigurationKeys#LOCALE
- * @see RangeQueryNode
+ * @see TermRangeQueryNode
* @see ParametricRangeQueryNode
*/
public class ParametricRangeQueryNodeProcessor extends QueryNodeProcessorImpl {
-
+
public ParametricRangeQueryNodeProcessor() {
- // empty constructor
+ // empty constructor
}
-
+
@Override
protected QueryNode postProcessNode(QueryNode node) throws QueryNodeException {
-
+
if (node instanceof ParametricRangeQueryNode) {
ParametricRangeQueryNode parametricRangeNode = (ParametricRangeQueryNode) node;
ParametricQueryNode upper = parametricRangeNode.getUpperBound();
@@ -79,31 +78,31 @@ public class ParametricRangeQueryNodePro
if (locale == null) {
locale = Locale.getDefault();
}
-
+
CharSequence field = parametricRangeNode.getField();
String fieldStr = null;
-
+
if (field != null) {
fieldStr = field.toString();
}
-
+
FieldConfig fieldConfig = getQueryConfigHandler()
.getFieldConfig(fieldStr);
-
+
if (fieldConfig != null) {
dateRes = fieldConfig.get(ConfigurationKeys.DATE_RESOLUTION);
}
-
+
if (upper.getOperator() == CompareOperator.LE) {
inclusive = true;
-
+
} else if (lower.getOperator() == CompareOperator.GE) {
inclusive = true;
}
-
+
String part1 = lower.getTextAsString();
String part2 = upper.getTextAsString();
-
+
try {
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
df.setLenient(true);
@@ -121,37 +120,39 @@ public class ParametricRangeQueryNodePro
cal.set(Calendar.MILLISECOND, 999);
d2 = cal.getTime();
}
-
+
part1 = DateTools.dateToString(d1, dateRes);
part2 = DateTools.dateToString(d2, dateRes);
} catch (Exception e) {
// do nothing
}
-
+
lower.setText(part1);
upper.setText(part2);
-
- return new RangeQueryNode(lower, upper);
-
+
+ return new TermRangeQueryNode(lower, upper,
+ lower.getOperator() == CompareOperator.GE,
+ upper.getOperator() == CompareOperator.LE);
+
}
-
+
return node;
-
+
}
-
+
@Override
protected QueryNode preProcessNode(QueryNode node) throws QueryNodeException {
-
+
return node;
-
+
}
-
+
@Override
protected List<QueryNode> setChildrenOrder(List<QueryNode> children)
throws QueryNodeException {
-
+
return children;
-
+
}
-
+
}
Modified: lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/StandardQueryNodeProcessorPipeline.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/StandardQueryNodeProcessorPipeline.java?rev=1144744&r1=1144743&r2=1144744&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/StandardQueryNodeProcessorPipeline.java (original)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/StandardQueryNodeProcessorPipeline.java Sat Jul 9 21:05:13 2011
@@ -53,6 +53,8 @@ public class StandardQueryNodeProcessorP
add(new FuzzyQueryNodeProcessor());
add(new MatchAllDocsQueryNodeProcessor());
add(new LowercaseExpandedTermsQueryNodeProcessor());
+ add(new NumericQueryNodeProcessor());
+ add(new NumericRangeQueryNodeProcessor());
add(new ParametricRangeQueryNodeProcessor());
add(new AllowLeadingWildcardProcessor());
add(new AnalyzerQueryNodeProcessor());
Modified: lucene/dev/trunk/lucene/contrib/queryparser/src/resources/org/apache/lucene/queryParser/core/messages/QueryParserMessages.properties
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queryparser/src/resources/org/apache/lucene/queryParser/core/messages/QueryParserMessages.properties?rev=1144744&r1=1144743&r2=1144744&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queryparser/src/resources/org/apache/lucene/queryParser/core/messages/QueryParserMessages.properties (original)
+++ lucene/dev/trunk/lucene/contrib/queryparser/src/resources/org/apache/lucene/queryParser/core/messages/QueryParserMessages.properties Sat Jul 9 21:05:13 2011
@@ -46,3 +46,12 @@ TOO_MANY_BOOLEAN_CLAUSES = Too many bool
#<CREATEDBY>Apache Lucene Community</CREATEDBY>
LEADING_WILDCARD_NOT_ALLOWED = Leading wildcard is not allowed: {0}
+
+#<CREATEDBY>Apache Lucene Community</CREATEDBY>
+COULD_NOT_PARSE_NUMBER = Could not parse text "{0}" using {1}
+
+#<CREATEDBY>Apache Lucene Community</CREATEDBY>
+NUMBER_CLASS_NOT_SUPPORTED_BY_NUMERIC_RANGE_QUERY = Number class not supported by NumericRangeQueryNode: {0}
+
+#<CREATEDBY>Apache Lucene Community</CREATEDBY>
+UNSUPPORTED_NUMERIC_DATA_TYPE = Unsupported NumericField.DataType: {0}