lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adrianocrest...@apache.org
Subject svn commit: r1060187 - in /lucene/java/branches/lucene_3_0/contrib: ./ queryparser/src/java/org/apache/lucene/queryParser/core/builders/ queryparser/src/test/org/apache/lucene/queryParser/core/builders/
Date Tue, 18 Jan 2011 04:25:12 GMT
Author: adrianocrestani
Date: Tue Jan 18 04:25:11 2011
New Revision: 1060187

URL: http://svn.apache.org/viewvc?rev=1060187&view=rev
Log:
LUCENE-2855: Contrib queryparser should not use CharSequence as Map key

Added:
    lucene/java/branches/lucene_3_0/contrib/queryparser/src/test/org/apache/lucene/queryParser/core/builders/
    lucene/java/branches/lucene_3_0/contrib/queryparser/src/test/org/apache/lucene/queryParser/core/builders/TestQueryTreeBuilder.java
  (with props)
Modified:
    lucene/java/branches/lucene_3_0/contrib/CHANGES.txt
    lucene/java/branches/lucene_3_0/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/builders/QueryTreeBuilder.java

Modified: lucene/java/branches/lucene_3_0/contrib/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_3_0/contrib/CHANGES.txt?rev=1060187&r1=1060186&r2=1060187&view=diff
==============================================================================
--- lucene/java/branches/lucene_3_0/contrib/CHANGES.txt (original)
+++ lucene/java/branches/lucene_3_0/contrib/CHANGES.txt Tue Jan 18 04:25:11 2011
@@ -2,7 +2,12 @@ Lucene contrib change Log
 
 ======================= 3.0 branch (not yet released) ==================
 
-No changes.
+Bug Fixes
+
+ * LUCENE-2855: contrib queryparser was using CharSequence as key in some internal 
+   Map instances, which was leading to incorrect behavior, since some CharSequence
+   implementors do not override hashcode and equals methods. Now the internal Maps 
+   are using String instead.
 
 ======================= Release 3.0.3 2010-12-03 =======================
 

Modified: lucene/java/branches/lucene_3_0/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/builders/QueryTreeBuilder.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_3_0/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/builders/QueryTreeBuilder.java?rev=1060187&r1=1060186&r2=1060187&view=diff
==============================================================================
--- lucene/java/branches/lucene_3_0/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/builders/QueryTreeBuilder.java
(original)
+++ lucene/java/branches/lucene_3_0/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/builders/QueryTreeBuilder.java
Tue Jan 18 04:25:11 2011
@@ -61,7 +61,7 @@ public class QueryTreeBuilder implements
 
   private HashMap<Class<? extends QueryNode>, QueryBuilder> queryNodeBuilders;
 
-  private HashMap<CharSequence, QueryBuilder> fieldNameBuilders;
+  private HashMap<String, QueryBuilder> fieldNameBuilders;
 
   /**
    * {@link QueryTreeBuilder} constructor.
@@ -73,28 +73,25 @@ public class QueryTreeBuilder implements
   /**
    * Associates a field name with a builder.
    * 
-   * @param fieldName
-   *          the field name
-   * @param builder
-   *          the builder to be associated
+   * @param fieldName the field name
+   * @param builder the builder to be associated
    */
   public void setBuilder(CharSequence fieldName, QueryBuilder builder) {
 
     if (this.fieldNameBuilders == null) {
-      this.fieldNameBuilders = new HashMap<CharSequence, QueryBuilder>();
+      this.fieldNameBuilders = new HashMap<String, QueryBuilder>();
     }
 
-    this.fieldNameBuilders.put(fieldName, builder);
+    this.fieldNameBuilders.put(fieldName.toString(), builder);
+
 
   }
 
   /**
    * Associates a class with a builder
    * 
-   * @param queryNodeClass
-   *          the class
-   * @param builder
-   *          the builder to be associated
+   * @param queryNodeClass the class
+   * @param builder the builder to be associated
    */
   public void setBuilder(Class<? extends QueryNode> queryNodeClass,
       QueryBuilder builder) {
@@ -135,8 +132,13 @@ public class QueryTreeBuilder implements
     QueryBuilder builder = null;
 
     if (this.fieldNameBuilders != null && node instanceof FieldableNode) {
+      CharSequence field = ((FieldableNode) node).getField();
+
+      if (field != null) {
+        field = field.toString();
+      }
 
-      builder = this.fieldNameBuilders.get(((FieldableNode) node).getField());
+      builder = this.fieldNameBuilders.get(field);
 
     }
 
@@ -203,14 +205,13 @@ public class QueryTreeBuilder implements
    * Builds some kind of object from a query tree. Each node in the query tree
    * is built using an specific builder associated to it.
    * 
-   * @param queryNode
-   *          the query tree root node
+   * @param queryNode the query tree root node
    * 
    * @return the built object
    * 
-   * @throws QueryNodeException
-   *           if some node builder throws a {@link QueryNodeException} or if
-   *           there is a node which had no builder associated to it
+   * @throws QueryNodeException if some node builder throws a
+   *         {@link QueryNodeException} or if there is a node which had no
+   *         builder associated to it
    */
   public Object build(QueryNode queryNode) throws QueryNodeException {
     process(queryNode);

Added: lucene/java/branches/lucene_3_0/contrib/queryparser/src/test/org/apache/lucene/queryParser/core/builders/TestQueryTreeBuilder.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_3_0/contrib/queryparser/src/test/org/apache/lucene/queryParser/core/builders/TestQueryTreeBuilder.java?rev=1060187&view=auto
==============================================================================
--- lucene/java/branches/lucene_3_0/contrib/queryparser/src/test/org/apache/lucene/queryParser/core/builders/TestQueryTreeBuilder.java
(added)
+++ lucene/java/branches/lucene_3_0/contrib/queryparser/src/test/org/apache/lucene/queryParser/core/builders/TestQueryTreeBuilder.java
Tue Jan 18 04:25:11 2011
@@ -0,0 +1,46 @@
+package org.apache.lucene.queryParser.core.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 junit.framework.Assert;
+
+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.UnescapedCharSequence;
+import org.apache.lucene.util.LuceneTestCase;
+
+public class TestQueryTreeBuilder extends LuceneTestCase {
+  
+  public void testSetFieldBuilder() throws QueryNodeException {
+    QueryTreeBuilder qtb = new QueryTreeBuilder();
+    qtb.setBuilder("field", new DummyBuilder());
+    Object result = qtb.build(new FieldQueryNode(new UnescapedCharSequence("field"), "foo",
0, 0));
+    Assert.assertEquals("OK", result);
+    
+  }
+  
+  private static class DummyBuilder implements QueryBuilder {
+
+    public Object build(QueryNode queryNode) throws QueryNodeException {
+      return "OK";
+    }
+    
+  }
+
+}

Propchange: lucene/java/branches/lucene_3_0/contrib/queryparser/src/test/org/apache/lucene/queryParser/core/builders/TestQueryTreeBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lucene/java/branches/lucene_3_0/contrib/queryparser/src/test/org/apache/lucene/queryParser/core/builders/TestQueryTreeBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message