lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From busc...@apache.org
Subject svn commit: r805633 [2/2] - in /lucene/java/trunk/contrib: ./ queryparser/src/java/org/apache/lucene/queryParser/core/ queryparser/src/java/org/apache/lucene/queryParser/core/nodes/ queryparser/src/java/org/apache/lucene/queryParser/core/util/ querypar...
Date Wed, 19 Aug 2009 00:09:42 GMT
Modified: lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/AllowLeadingWildcardProcessor.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/AllowLeadingWildcardProcessor.java?rev=805633&r1=805632&r2=805633&view=diff
==============================================================================
--- lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/AllowLeadingWildcardProcessor.java
(original)
+++ lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/AllowLeadingWildcardProcessor.java
Wed Aug 19 00:09:41 2009
@@ -24,9 +24,10 @@
 import org.apache.lucene.queryParser.core.config.QueryConfigHandler;
 import org.apache.lucene.queryParser.core.messages.QueryParserMessages;
 import org.apache.lucene.queryParser.core.nodes.QueryNode;
-import org.apache.lucene.queryParser.core.nodes.WildcardQueryNode;
 import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorImpl;
+import org.apache.lucene.queryParser.core.util.UnescapedCharSequence;
 import org.apache.lucene.queryParser.standard.config.AllowLeadingWildcardAttribute;
+import org.apache.lucene.queryParser.standard.nodes.WildcardQueryNode;
 import org.apache.lucene.queryParser.standard.parser.EscapeQuerySyntaxImpl;
 
 /**
@@ -46,19 +47,16 @@
 
   public QueryNode process(QueryNode queryTree) throws QueryNodeException {
 
-    if (getQueryConfigHandler().hasAttribute(
-        AllowLeadingWildcardAttribute.class)) {
+    if (getQueryConfigHandler().hasAttribute(AllowLeadingWildcardAttribute.class)) {
 
-      if (!((AllowLeadingWildcardAttribute) getQueryConfigHandler()
-          .getAttribute(AllowLeadingWildcardAttribute.class))
-          .isAllowLeadingWildcard()) {
+      AllowLeadingWildcardAttribute alwAttr= (AllowLeadingWildcardAttribute) getQueryConfigHandler().getAttribute(AllowLeadingWildcardAttribute.class);
+      if (!alwAttr.isAllowLeadingWildcard()) {
         return super.process(queryTree);
       }
 
     }
 
     return queryTree;
-
   }
 
   protected QueryNode postProcessNode(QueryNode node) throws QueryNodeException {
@@ -66,14 +64,19 @@
     if (node instanceof WildcardQueryNode) {
       WildcardQueryNode wildcardNode = (WildcardQueryNode) node;
 
-      switch (wildcardNode.getText().charAt(0)) {
-
-      case '*':
-      case '?':
-        throw new QueryNodeException(new MessageImpl(
-            QueryParserMessages.LEADING_WILDCARD_NOT_ALLOWED, node
-                .toQueryString(new EscapeQuerySyntaxImpl())));
-
+      if (wildcardNode.getText().length() > 0) {
+        
+        // Validate if the wildcard was escaped
+        if (UnescapedCharSequence.wasEscaped(wildcardNode.getText(), 0))
+          return node;
+        
+        switch (wildcardNode.getText().charAt(0)) {    
+          case '*':
+          case '?':
+            throw new QueryNodeException(new MessageImpl(
+                QueryParserMessages.LEADING_WILDCARD_NOT_ALLOWED, node
+                    .toQueryString(new EscapeQuerySyntaxImpl())));    
+        }
       }
 
     }

Modified: lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/AnalyzerQueryNodeProcessor.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/AnalyzerQueryNodeProcessor.java?rev=805633&r1=805632&r2=805633&view=diff
==============================================================================
--- lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/AnalyzerQueryNodeProcessor.java
(original)
+++ lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/AnalyzerQueryNodeProcessor.java
Wed Aug 19 00:09:41 2009
@@ -38,12 +38,12 @@
 import org.apache.lucene.queryParser.core.nodes.QueryNode;
 import org.apache.lucene.queryParser.core.nodes.TextableQueryNode;
 import org.apache.lucene.queryParser.core.nodes.TokenizedPhraseQueryNode;
-import org.apache.lucene.queryParser.core.nodes.WildcardQueryNode;
 import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorImpl;
 import org.apache.lucene.queryParser.standard.config.AnalyzerAttribute;
 import org.apache.lucene.queryParser.standard.config.PositionIncrementsAttribute;
-import org.apache.lucene.queryParser.standard.nodes.StandardBooleanQueryNode;
 import org.apache.lucene.queryParser.standard.nodes.MultiPhraseQueryNode;
+import org.apache.lucene.queryParser.standard.nodes.StandardBooleanQueryNode;
+import org.apache.lucene.queryParser.standard.nodes.WildcardQueryNode;
 
 /**
  * This processor verifies if the attribute {@link AnalyzerQueryNodeProcessor}

Modified: lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/LowercaseExpandedTermsQueryNodeProcessor.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/LowercaseExpandedTermsQueryNodeProcessor.java?rev=805633&r1=805632&r2=805633&view=diff
==============================================================================
--- lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/LowercaseExpandedTermsQueryNodeProcessor.java
(original)
+++ lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/LowercaseExpandedTermsQueryNodeProcessor.java
Wed Aug 19 00:09:41 2009
@@ -25,9 +25,10 @@
 import org.apache.lucene.queryParser.core.nodes.FuzzyQueryNode;
 import org.apache.lucene.queryParser.core.nodes.ParametricQueryNode;
 import org.apache.lucene.queryParser.core.nodes.QueryNode;
-import org.apache.lucene.queryParser.core.nodes.WildcardQueryNode;
 import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorImpl;
+import org.apache.lucene.queryParser.core.util.UnescapedCharSequence;
 import org.apache.lucene.queryParser.standard.config.LowercaseExpandedTermsAttribute;
+import org.apache.lucene.queryParser.standard.nodes.WildcardQueryNode;
 
 /**
  * This processor verifies if the attribute
@@ -68,9 +69,8 @@
     if (node instanceof WildcardQueryNode || node instanceof FuzzyQueryNode
         || node instanceof ParametricQueryNode) {
 
-      FieldQueryNode fieldNode = (FieldQueryNode) node;
-      fieldNode.setText(fieldNode.getText().toString().toLowerCase());
-
+      FieldQueryNode fieldNode = (FieldQueryNode) node;      
+      fieldNode.setText(UnescapedCharSequence.toLowerCase(fieldNode.getText()));
     }
 
     return node;

Modified: lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/MatchAllDocsQueryNodeProcessor.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/MatchAllDocsQueryNodeProcessor.java?rev=805633&r1=805632&r2=805633&view=diff
==============================================================================
--- lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/MatchAllDocsQueryNodeProcessor.java
(original)
+++ lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/MatchAllDocsQueryNodeProcessor.java
Wed Aug 19 00:09:41 2009
@@ -20,10 +20,11 @@
 import java.util.List;
 
 import org.apache.lucene.queryParser.core.QueryNodeException;
+import org.apache.lucene.queryParser.core.nodes.FieldQueryNode;
 import org.apache.lucene.queryParser.core.nodes.MatchAllDocsQueryNode;
 import org.apache.lucene.queryParser.core.nodes.QueryNode;
-import org.apache.lucene.queryParser.core.nodes.WildcardQueryNode;
 import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorImpl;
+import org.apache.lucene.queryParser.standard.nodes.WildcardQueryNode;
 import org.apache.lucene.search.MatchAllDocsQuery;
 
 /**
@@ -41,11 +42,11 @@
 
   protected QueryNode postProcessNode(QueryNode node) throws QueryNodeException {
 
-    if (node instanceof WildcardQueryNode) {
-      WildcardQueryNode wildcardNode = (WildcardQueryNode) node;
+    if (node instanceof FieldQueryNode) {
+      FieldQueryNode fqn = (FieldQueryNode) node;
 
-      if (wildcardNode.getField().toString().equals("*")
-          && wildcardNode.getText().toString().equals("*")) {
+      if (fqn.getField().toString().equals("*")
+          && fqn.getText().toString().equals("*")) {
 
         return new MatchAllDocsQueryNode();
 

Modified: lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/MultiTermRewriteDefaultProcessor.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/MultiTermRewriteDefaultProcessor.java?rev=805633&r1=805632&r2=805633&view=diff
==============================================================================
--- lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/MultiTermRewriteDefaultProcessor.java
(original)
+++ lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/MultiTermRewriteDefaultProcessor.java
Wed Aug 19 00:09:41 2009
@@ -1,53 +0,0 @@
-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.util.List;
-
-import org.apache.lucene.queryParser.core.nodes.QueryNode;
-import org.apache.lucene.queryParser.core.nodes.WildcardQueryNode;
-import org.apache.lucene.queryParser.core.nodes.PrefixWildcardQueryNode;
-import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorImpl;
-import org.apache.lucene.search.MultiTermQuery;
-
-/**
- * This processor instates the default {@link
- * MultiTermQuery.RewriteMethod}, {@link
- * MultiTermQuery#CONSTANT_SCORE_AUTO_REWRITE_DEFAULT}, for
- * multi-term query nodes.
- */
-public class MultiTermRewriteDefaultProcessor extends QueryNodeProcessorImpl {
-
-  protected QueryNode postProcessNode(QueryNode node) {
-    if (node instanceof WildcardQueryNode) {
-      ((WildcardQueryNode) node).setMultiTermRewriteMethod(MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT);
-    } else if (node instanceof PrefixWildcardQueryNode) {
-      ((PrefixWildcardQueryNode) node).setMultiTermRewriteMethod(MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT);
-    }
-
-    return node;
-  }
-
-  protected QueryNode preProcessNode(QueryNode node) {
-    return node;
-  }
-
-  protected List<QueryNode> setChildrenOrder(List<QueryNode> children) {
-    return children;
-  }
-}

Added: lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/MultiTermRewriteMethodProcessor.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/MultiTermRewriteMethodProcessor.java?rev=805633&view=auto
==============================================================================
--- lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/MultiTermRewriteMethodProcessor.java
(added)
+++ lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/MultiTermRewriteMethodProcessor.java
Wed Aug 19 00:09:41 2009
@@ -0,0 +1,66 @@
+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.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.MultiTermRewriteMethodAttribute;
+import org.apache.lucene.queryParser.standard.nodes.WildcardQueryNode;
+import org.apache.lucene.search.MultiTermQuery;
+
+/**
+ * This processor instates the default {@link
+ * MultiTermQuery.RewriteMethod}, {@link
+ * MultiTermQuery#CONSTANT_SCORE_AUTO_REWRITE_DEFAULT}, for
+ * multi-term query nodes.
+ */
+public class MultiTermRewriteMethodProcessor extends QueryNodeProcessorImpl {  
+
+  protected QueryNode postProcessNode(QueryNode node) {
+    
+    // set setMultiTermRewriteMethod for WildcardQueryNode and PrefixWildcardQueryNode
+    if (node instanceof WildcardQueryNode || node instanceof  ParametricRangeQueryNode
+        || node instanceof ParametricRangeQueryNode) {
+      
+      if (!getQueryConfigHandler().hasAttribute(MultiTermRewriteMethodAttribute.class)) {
+        // This should not happen, this attribute is created in the StandardQueryConfigHandler
+        throw new IllegalArgumentException("MultiTermRewriteMethodAttribute should be set
on the QueryConfigHandler");
+      }
+
+      //read the attribute value and use a TAG to take the value to the Builder
+      MultiTermQuery.RewriteMethod rewriteMethod = ((MultiTermRewriteMethodAttribute) getQueryConfigHandler()
+          .getAttribute(MultiTermRewriteMethodAttribute.class))
+          .getMultiTermRewriteMethod();
+
+      node.setTag(MultiTermRewriteMethodAttribute.TAG_ID, rewriteMethod);
+    }
+    
+    return node;
+  }
+
+  protected QueryNode preProcessNode(QueryNode node) {
+    return node;
+  }
+
+  protected List<QueryNode> setChildrenOrder(List<QueryNode> children) {
+    return children;
+  }
+}

Propchange: lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/MultiTermRewriteMethodProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/ParametricRangeQueryNodeProcessor.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/ParametricRangeQueryNodeProcessor.java?rev=805633&r1=805632&r2=805633&view=diff
==============================================================================
--- lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/ParametricRangeQueryNodeProcessor.java
(original)
+++ lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/ParametricRangeQueryNodeProcessor.java
Wed Aug 19 00:09:41 2009
@@ -35,12 +35,10 @@
 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.MultiTermRewriteMethodAttribute;
 import org.apache.lucene.queryParser.standard.config.DateResolutionAttribute;
 import org.apache.lucene.queryParser.standard.config.LocaleAttribute;
 import org.apache.lucene.queryParser.standard.config.RangeCollatorAttribute;
 import org.apache.lucene.queryParser.standard.nodes.RangeQueryNode;
-import org.apache.lucene.search.MultiTermQuery;
 
 /**
  * This processor converts {@link ParametricRangeQueryNode} objects to
@@ -85,16 +83,6 @@
       DateTools.Resolution dateRes = null;
       boolean inclusive = false;
 
-      if (!getQueryConfigHandler().hasAttribute(
-          MultiTermRewriteMethodAttribute.class)) {
-        throw new IllegalArgumentException(
-            "MultiTermRewriteMethodAttribute should be set on the QueryConfigHandler");
-      }
-
-      MultiTermQuery.RewriteMethod rewriteMethod = ((MultiTermRewriteMethodAttribute) getQueryConfigHandler()
-          .getAttribute(MultiTermRewriteMethodAttribute.class))
-          .getMultiTermRewriteMethod();
-
       if (getQueryConfigHandler().hasAttribute(RangeCollatorAttribute.class)) {
         collator = ((RangeCollatorAttribute) getQueryConfigHandler()
             .getAttribute(RangeCollatorAttribute.class)).getRangeCollator();
@@ -164,7 +152,7 @@
       lower.setText(part1);
       upper.setText(part2);
 
-      return new RangeQueryNode(lower, upper, collator, rewriteMethod);
+      return new RangeQueryNode(lower, upper, collator);
 
     }
 

Modified: lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/PrefixWildcardQueryNodeProcessor.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/PrefixWildcardQueryNodeProcessor.java?rev=805633&r1=805632&r2=805633&view=diff
==============================================================================
--- lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/PrefixWildcardQueryNodeProcessor.java
(original)
+++ lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/PrefixWildcardQueryNodeProcessor.java
Wed Aug 19 00:09:41 2009
@@ -1,72 +0,0 @@
-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.util.List;
-
-import org.apache.lucene.queryParser.core.QueryNodeException;
-import org.apache.lucene.queryParser.core.nodes.PrefixWildcardQueryNode;
-import org.apache.lucene.queryParser.core.nodes.QueryNode;
-import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorImpl;
-import org.apache.lucene.queryParser.standard.parser.StandardSyntaxParser;
-import org.apache.lucene.search.PrefixQuery;
-
-/**
- * The {@link StandardSyntaxParser} creates {@link PrefixWildcardQueryNode} nodes which
- * have values containing the prefixed wildcard. However, Lucene
- * {@link PrefixQuery} cannot contain the prefixed wildcard. So, this processor
- * basically removed the prefixed wildcard from the
- * {@link PrefixWildcardQueryNode} value. <br/>
- * 
- * @see PrefixQuery
- * @see PrefixWildcardQueryNode
- */
-public class PrefixWildcardQueryNodeProcessor extends QueryNodeProcessorImpl {
-
-  public PrefixWildcardQueryNodeProcessor() {
-    // empty constructor
-  }
-
-  protected QueryNode postProcessNode(QueryNode node) throws QueryNodeException {
-
-    if (node instanceof PrefixWildcardQueryNode) {
-      PrefixWildcardQueryNode prefixWildcardNode = (PrefixWildcardQueryNode) node;
-      CharSequence text = prefixWildcardNode.getText();
-
-      prefixWildcardNode.setText(text.subSequence(0, text.length() - 1));
-
-    }
-
-    return node;
-
-  }
-
-  protected QueryNode preProcessNode(QueryNode node) throws QueryNodeException {
-
-    return node;
-
-  }
-
-  protected List<QueryNode> setChildrenOrder(List<QueryNode> children)
-      throws QueryNodeException {
-
-    return children;
-
-  }
-
-}

Modified: lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/StandardQueryNodeProcessorPipeline.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/StandardQueryNodeProcessorPipeline.java?rev=805633&r1=805632&r2=805633&view=diff
==============================================================================
--- lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/StandardQueryNodeProcessorPipeline.java
(original)
+++ lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/StandardQueryNodeProcessorPipeline.java
Wed Aug 19 00:09:41 2009
@@ -48,13 +48,13 @@
   public StandardQueryNodeProcessorPipeline(QueryConfigHandler queryConfig) {
     super(queryConfig);
 
+    addProcessor(new WildcardQueryNodeProcessor());    
     addProcessor(new MultiFieldQueryNodeProcessor());
     addProcessor(new FuzzyQueryNodeProcessor());
     addProcessor(new MatchAllDocsQueryNodeProcessor());
     addProcessor(new LowercaseExpandedTermsQueryNodeProcessor());
     addProcessor(new ParametricRangeQueryNodeProcessor());
-    addProcessor(new AllowLeadingWildcardProcessor());
-    addProcessor(new PrefixWildcardQueryNodeProcessor());
+    addProcessor(new AllowLeadingWildcardProcessor());    
     addProcessor(new AnalyzerQueryNodeProcessor());
     addProcessor(new PhraseSlopQueryNodeProcessor());
     addProcessor(new GroupQueryNodeProcessor());
@@ -63,9 +63,8 @@
     addProcessor(new RemoveEmptyNonLeafQueryNodeProcessor());
     addProcessor(new BooleanSingleChildOptimizationQueryNodeProcessor());
     addProcessor(new DefaultPhraseSlopQueryNodeProcessor());
-    addProcessor(new BoostQueryNodeProcessor());
-    addProcessor(new MultiTermRewriteDefaultProcessor());
-
+    addProcessor(new BoostQueryNodeProcessor());    
+    addProcessor(new MultiTermRewriteMethodProcessor());
   }
 
 }

Added: lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/WildcardQueryNodeProcessor.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/WildcardQueryNodeProcessor.java?rev=805633&view=auto
==============================================================================
--- lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/WildcardQueryNodeProcessor.java
(added)
+++ lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/WildcardQueryNodeProcessor.java
Wed Aug 19 00:09:41 2009
@@ -0,0 +1,136 @@
+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.util.List;
+
+import org.apache.lucene.queryParser.core.QueryNodeException;
+import org.apache.lucene.queryParser.core.nodes.FieldQueryNode;
+import org.apache.lucene.queryParser.core.nodes.FuzzyQueryNode;
+import org.apache.lucene.queryParser.core.nodes.ParametricQueryNode;
+import org.apache.lucene.queryParser.core.nodes.QueryNode;
+import org.apache.lucene.queryParser.core.nodes.QuotedFieldQueryNode;
+import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorImpl;
+import org.apache.lucene.queryParser.core.util.UnescapedCharSequence;
+import org.apache.lucene.queryParser.standard.nodes.PrefixWildcardQueryNode;
+import org.apache.lucene.queryParser.standard.nodes.WildcardQueryNode;
+import org.apache.lucene.queryParser.standard.parser.StandardSyntaxParser;
+import org.apache.lucene.search.PrefixQuery;
+
+/**
+ * The {@link StandardSyntaxParser} creates {@link PrefixWildcardQueryNode} nodes which
+ * have values containing the prefixed wildcard. However, Lucene
+ * {@link PrefixQuery} cannot contain the prefixed wildcard. So, this processor
+ * basically removed the prefixed wildcard from the
+ * {@link PrefixWildcardQueryNode} value. <br/>
+ * 
+ * @see PrefixQuery
+ * @see PrefixWildcardQueryNode
+ */
+public class WildcardQueryNodeProcessor extends QueryNodeProcessorImpl {
+
+  public WildcardQueryNodeProcessor() {
+    // empty constructor
+  }
+
+  protected QueryNode postProcessNode(QueryNode node) throws QueryNodeException {
+
+    // the old Lucene Parser ignores FuzzyQueryNode that are also PrefixWildcardQueryNode
or WildcardQueryNode
+    // we do the same here, also ignore empty terms
+    if (node instanceof FieldQueryNode || node instanceof FuzzyQueryNode) {      
+      FieldQueryNode fqn = (FieldQueryNode) node;      
+      CharSequence text = fqn.getText(); 
+      
+      // do not process wildcards for ParametricQueryNode and 
+      // QuotedFieldQueryNode to reproduce the old parser behavior
+      if (fqn instanceof ParametricQueryNode 
+          || fqn instanceof QuotedFieldQueryNode 
+          || text.length() <= 0){
+        // Ignore empty terms
+        return node;
+      }
+      
+      // Code below simulates the old lucene parser behavior for wildcards
+      
+      if (isPrefixWildcard(text)) {        
+        PrefixWildcardQueryNode prefixWildcardQN = new PrefixWildcardQueryNode(fqn);
+        return prefixWildcardQN;
+        
+      } else if (isWildcard(text)){
+        WildcardQueryNode wildcardQN = new WildcardQueryNode(fqn);
+        return wildcardQN;
+      }
+             
+    }
+
+    return node;
+
+  }
+
+  private boolean isWildcard(CharSequence text) {
+    if (text ==null || text.length() <= 0) return false;
+    
+    // If a un-escaped '*' or '?' if found return true
+    // start at the end since it's more common to put wildcards at the end
+    for(int i=text.length()-1; i>=0; i--){
+      if ((text.charAt(i) == '*' || text.charAt(i) == '?') && !UnescapedCharSequence.wasEscaped(text,
i)){
+        return true;
+      }
+    }
+    
+    return false;
+  }
+
+  private boolean isPrefixWildcard(CharSequence text) {
+    if (text == null || text.length() <= 0 || !isWildcard(text)) return false;
+    
+    // Validate last character is a '*' and was not escaped
+    // If single '*' is is a wildcard not prefix to simulate old queryparser
+    if (text.charAt(text.length()-1) != '*') return false;
+    if (UnescapedCharSequence.wasEscaped(text, text.length()-1)) return false;
+    if (text.length() == 1) return false;
+      
+    // Only make a prefix if there is only one single star at the end and no '?' or '*' characters
+    // If single wildcard return false to mimic old queryparser
+    for(int i=0; i<text.length(); i++){
+      if (text.charAt(i) == '?') return false;
+      if (text.charAt(i) == '*' && !UnescapedCharSequence.wasEscaped(text, i)){ 
      
+        if (i == text.length()-1) 
+          return true;
+        else 
+          return false;
+      }
+    }
+    
+    return false;
+  }
+
+  protected QueryNode preProcessNode(QueryNode node) throws QueryNodeException {
+
+    return node;
+
+  }
+
+  protected List<QueryNode> setChildrenOrder(List<QueryNode> children)
+      throws QueryNodeException {
+
+    return children;
+
+  }
+
+}

Propchange: lucene/java/trunk/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/processors/WildcardQueryNodeProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: lucene/java/trunk/contrib/queryparser/src/test/org/apache/lucene/queryParser/spans/TestSpanQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/queryparser/src/test/org/apache/lucene/queryParser/spans/TestSpanQueryParser.java?rev=805633&r1=805632&r2=805633&view=diff
==============================================================================
--- lucene/java/trunk/contrib/queryparser/src/test/org/apache/lucene/queryParser/spans/TestSpanQueryParser.java
(original)
+++ lucene/java/trunk/contrib/queryparser/src/test/org/apache/lucene/queryParser/spans/TestSpanQueryParser.java
Wed Aug 19 00:09:41 2009
@@ -27,6 +27,7 @@
 import org.apache.lucene.queryParser.core.parser.SyntaxParser;
 import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorPipeline;
 import org.apache.lucene.queryParser.standard.parser.StandardSyntaxParser;
+import org.apache.lucene.queryParser.standard.processors.WildcardQueryNodeProcessor;
 import org.apache.lucene.search.spans.SpanOrQuery;
 import org.apache.lucene.search.spans.SpanQuery;
 import org.apache.lucene.search.spans.SpanTermQuery;
@@ -115,13 +116,11 @@
     this.spansQueryTreeBuilder = new SpansQueryTreeBuilder();
 
     // set up the processor pipeline
-    this.spanProcessorPipeline
-        .setQueryConfigHandler(this.spanQueryConfigHandler);
+    this.spanProcessorPipeline.setQueryConfigHandler(this.spanQueryConfigHandler);
 
-    this.spanProcessorPipeline
-        .addProcessor(new SpansValidatorQueryNodeProcessor());
-    this.spanProcessorPipeline
-        .addProcessor(new UniqueFieldQueryNodeProcessor());
+    this.spanProcessorPipeline.addProcessor(new WildcardQueryNodeProcessor());
+    this.spanProcessorPipeline.addProcessor(new SpansValidatorQueryNodeProcessor());
+    this.spanProcessorPipeline.addProcessor(new UniqueFieldQueryNodeProcessor());
 
   }
 

Modified: lucene/java/trunk/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java?rev=805633&r1=805632&r2=805633&view=diff
==============================================================================
--- lucene/java/trunk/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java
(original)
+++ lucene/java/trunk/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java
Wed Aug 19 00:09:41 2009
@@ -54,10 +54,10 @@
 import org.apache.lucene.queryParser.core.messages.QueryParserMessages;
 import org.apache.lucene.queryParser.core.nodes.FuzzyQueryNode;
 import org.apache.lucene.queryParser.core.nodes.QueryNode;
-import org.apache.lucene.queryParser.core.nodes.WildcardQueryNode;
 import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorImpl;
 import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorPipeline;
 import org.apache.lucene.queryParser.standard.config.DefaultOperatorAttribute.Operator;
+import org.apache.lucene.queryParser.standard.nodes.WildcardQueryNode;
 import org.apache.lucene.search.BooleanQuery;
 import org.apache.lucene.search.FuzzyQuery;
 import org.apache.lucene.search.IndexSearcher;
@@ -759,6 +759,8 @@
      * "foo \\AND bar");
      */
 
+    assertQueryEquals("\\*", a, "*");
+    
     assertQueryEquals("\\a", a, "a");
 
     assertQueryEquals("a\\-b:c", a, "a-b:c");
@@ -938,13 +940,13 @@
   }
 
   public void testException() throws Exception {
+    assertQueryNodeException("*leadingWildcard"); // disallowed by default
     assertQueryNodeException("\"some phrase");
     assertQueryNodeException("(foo bar");
     assertQueryNodeException("foo bar))");
     assertQueryNodeException("field:term:with:colon some more terms");
     assertQueryNodeException("(sub query)^5.0^2.0 plus more");
-    assertQueryNodeException("secret AND illegal) AND access:confidential");
-    assertQueryNodeException("*leadingWildcard"); // disallowed by default
+    assertQueryNodeException("secret AND illegal) AND access:confidential");    
   }
 
   public void testCustomQueryParserWildcard() {

Modified: lucene/java/trunk/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java?rev=805633&r1=805632&r2=805633&view=diff
==============================================================================
--- lucene/java/trunk/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java
(original)
+++ lucene/java/trunk/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java
Wed Aug 19 00:09:41 2009
@@ -51,9 +51,10 @@
 import org.apache.lucene.queryParser.core.messages.QueryParserMessages;
 import org.apache.lucene.queryParser.core.nodes.FuzzyQueryNode;
 import org.apache.lucene.queryParser.core.nodes.QueryNode;
-import org.apache.lucene.queryParser.core.nodes.WildcardQueryNode;
 import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorImpl;
 import org.apache.lucene.queryParser.core.processors.QueryNodeProcessorPipeline;
+import org.apache.lucene.queryParser.standard.nodes.WildcardQueryNode;
+import org.apache.lucene.queryParser.standard.processors.WildcardQueryNodeProcessor;
 import org.apache.lucene.search.BooleanQuery;
 import org.apache.lucene.search.FuzzyQuery;
 import org.apache.lucene.search.IndexSearcher;
@@ -159,6 +160,7 @@
 
       QueryNodeProcessorPipeline newProcessorPipeline = new QueryNodeProcessorPipeline(
           getQueryProcessor().getQueryConfigHandler());
+      newProcessorPipeline.addProcessor(new WildcardQueryNodeProcessor());
       newProcessorPipeline.addProcessor(new QPTestParserQueryNodeProcessor());
       newProcessorPipeline.addProcessor(getQueryProcessor());
 



Mime
View raw message