You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by er...@apache.org on 2011/11/05 21:45:11 UTC

svn commit: r1198049 - in /lucene/dev/branches/branch_3x: ./ lucene/ solr/ solr/core/src/java/org/apache/solr/schema/ solr/core/src/java/org/apache/solr/search/function/ solr/core/src/test-files/solr/conf/ solr/core/src/test/org/apache/solr/search/

Author: erick
Date: Sat Nov  5 20:45:10 2011
New Revision: 1198049

URL: http://svn.apache.org/viewvc?rev=1198049&view=rev
Log:
Fixes for SOLR-2829. False hits for caches

Added:
    lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/search/TestValueSourceCache.java
Modified:
    lucene/dev/branches/branch_3x/   (props changed)
    lucene/dev/branches/branch_3x/lucene/   (props changed)
    lucene/dev/branches/branch_3x/solr/   (props changed)
    lucene/dev/branches/branch_3x/solr/CHANGES.txt
    lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/schema/LatLonType.java
    lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/function/ByteFieldSource.java
    lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/function/DoubleFieldSource.java
    lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/function/FloatFieldSource.java
    lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/function/IntFieldSource.java
    lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/function/LongFieldSource.java
    lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/function/ShortFieldSource.java
    lucene/dev/branches/branch_3x/solr/core/src/test-files/solr/conf/schema.xml
    lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/search/SpatialFilterTest.java

Modified: lucene/dev/branches/branch_3x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/CHANGES.txt?rev=1198049&r1=1198048&r2=1198049&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_3x/solr/CHANGES.txt Sat Nov  5 20:45:10 2011
@@ -93,6 +93,9 @@ Bug Fixes
 * SOLR-2861: Fix extremely rare race condition on commit that can result
   in a NPE (yonik)
 
+* SOLR-2829: Fix problem with false-positives due to incorrect
+  equals methods. (Yonik Seeley, Hossman, Erick Erickson. 
+  Marc Tinnemeyer caught the bug)
 
  Other Changes
 ----------------------

Modified: lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/schema/LatLonType.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/schema/LatLonType.java?rev=1198049&r1=1198048&r2=1198049&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/schema/LatLonType.java (original)
+++ lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/schema/LatLonType.java Sat Nov  5 20:45:10 2011
@@ -570,7 +570,7 @@ class SpatialDistanceQuery extends Query
   /** Returns true if <code>o</code> is equal to this. */
   @Override
   public boolean equals(Object o) {
-    if (SpatialDistanceQuery.class != o.getClass()) return false;
+    if (!super.equals(o)) return false;
     SpatialDistanceQuery other = (SpatialDistanceQuery)o;
     return     this.latCenter == other.latCenter
             && this.lonCenter == other.lonCenter

Modified: lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/function/ByteFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/function/ByteFieldSource.java?rev=1198049&r1=1198048&r2=1198049&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/function/ByteFieldSource.java (original)
+++ lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/function/ByteFieldSource.java Sat Nov  5 20:45:10 2011
@@ -102,8 +102,8 @@ public class ByteFieldSource extends Fie
     ByteFieldSource
             other = (ByteFieldSource) o;
     return super.equals(other)
-            && this.parser == null ? other.parser == null :
-            this.parser.getClass() == other.parser.getClass();
+            && (this.parser == null ? other.parser == null :
+            this.parser.getClass() == other.parser.getClass());
   }
 
   @Override
@@ -112,4 +112,4 @@ public class ByteFieldSource extends Fie
     h += super.hashCode();
     return h;
   }
-}
\ No newline at end of file
+}

Modified: lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/function/DoubleFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/function/DoubleFieldSource.java?rev=1198049&r1=1198048&r2=1198049&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/function/DoubleFieldSource.java (original)
+++ lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/function/DoubleFieldSource.java Sat Nov  5 20:45:10 2011
@@ -152,8 +152,8 @@ public class DoubleFieldSource extends F
     if (o.getClass() != DoubleFieldSource.class) return false;
     DoubleFieldSource other = (DoubleFieldSource) o;
     return super.equals(other)
-            && this.parser == null ? other.parser == null :
-            this.parser.getClass() == other.parser.getClass();
+            && (this.parser == null ? other.parser == null :
+            this.parser.getClass() == other.parser.getClass());
   }
 
   @Override

Modified: lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/function/FloatFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/function/FloatFieldSource.java?rev=1198049&r1=1198048&r2=1198049&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/function/FloatFieldSource.java (original)
+++ lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/function/FloatFieldSource.java Sat Nov  5 20:45:10 2011
@@ -92,8 +92,8 @@ public class FloatFieldSource extends Fi
     if (o.getClass() !=  FloatFieldSource.class) return false;
     FloatFieldSource other = (FloatFieldSource)o;
     return super.equals(other)
-           && this.parser==null ? other.parser==null :
-              this.parser.getClass() == other.parser.getClass();
+           && (this.parser==null ? other.parser==null :
+              this.parser.getClass() == other.parser.getClass());
   }
 
   @Override
@@ -101,6 +101,6 @@ public class FloatFieldSource extends Fi
     int h = parser==null ? Float.class.hashCode() : parser.getClass().hashCode();
     h += super.hashCode();
     return h;
-  };
+  }
 
 }
\ No newline at end of file

Modified: lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/function/IntFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/function/IntFieldSource.java?rev=1198049&r1=1198048&r2=1198049&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/function/IntFieldSource.java (original)
+++ lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/function/IntFieldSource.java Sat Nov  5 20:45:10 2011
@@ -126,8 +126,8 @@ public class IntFieldSource extends Fiel
     if (o.getClass() !=  IntFieldSource.class) return false;
     IntFieldSource other = (IntFieldSource)o;
     return super.equals(other)
-           && this.parser==null ? other.parser==null :
-              this.parser.getClass() == other.parser.getClass();
+           && (this.parser==null ? other.parser==null :
+              this.parser.getClass() == other.parser.getClass());
   }
 
   @Override
@@ -135,6 +135,6 @@ public class IntFieldSource extends Fiel
     int h = parser==null ? Integer.class.hashCode() : parser.getClass().hashCode();
     h += super.hashCode();
     return h;
-  };
+  }
 
 }

Modified: lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/function/LongFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/function/LongFieldSource.java?rev=1198049&r1=1198048&r2=1198049&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/function/LongFieldSource.java (original)
+++ lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/function/LongFieldSource.java Sat Nov  5 20:45:10 2011
@@ -133,8 +133,8 @@ public class LongFieldSource extends Fie
     if (o.getClass() != this.getClass()) return false;
     LongFieldSource other = (LongFieldSource) o;
     return super.equals(other)
-            && this.parser == null ? other.parser == null :
-            this.parser.getClass() == other.parser.getClass();
+            && (this.parser == null ? other.parser == null :
+            this.parser.getClass() == other.parser.getClass());
   }
 
   @Override

Modified: lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/function/ShortFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/function/ShortFieldSource.java?rev=1198049&r1=1198048&r2=1198049&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/function/ShortFieldSource.java (original)
+++ lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/function/ShortFieldSource.java Sat Nov  5 20:45:10 2011
@@ -99,8 +99,8 @@ public class ShortFieldSource extends Fi
     ShortFieldSource
             other = (ShortFieldSource) o;
     return super.equals(other)
-            && this.parser == null ? other.parser == null :
-            this.parser.getClass() == other.parser.getClass();
+            && (this.parser == null ? other.parser == null :
+            this.parser.getClass() == other.parser.getClass());
   }
 
   @Override

Modified: lucene/dev/branches/branch_3x/solr/core/src/test-files/solr/conf/schema.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/core/src/test-files/solr/conf/schema.xml?rev=1198049&r1=1198048&r2=1198049&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/core/src/test-files/solr/conf/schema.xml (original)
+++ lucene/dev/branches/branch_3x/solr/core/src/test-files/solr/conf/schema.xml Sat Nov  5 20:45:10 2011
@@ -51,6 +51,9 @@
     <fieldType name="float" class="solr.TrieFloatField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
     <fieldType name="long" class="solr.TrieLongField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
     <fieldType name="double" class="solr.TrieDoubleField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
+    <fieldType name="byte" class="solr.ByteField" omitNorms="true" positionIncrementGap="0"/>
+    <fieldType name="short" class="solr.ShortField" omitNorms="true" positionIncrementGap="0"/>
+
 
     <fieldType name="tint" class="solr.TrieIntField" precisionStep="8" omitNorms="true" positionIncrementGap="0"/>
     <fieldType name="tfloat" class="solr.TrieFloatField" precisionStep="8" omitNorms="true" positionIncrementGap="0"/>
@@ -430,6 +433,8 @@
    <field name="work" type="xy" indexed="true" stored="true" multiValued="false"/>
 
    <field name="home_ll" type="latLon" indexed="true" stored="true" multiValued="false"/>
+   <field name="work_ll" type="latLon" indexed="true" stored="true" multiValued="false"/>
+   
    <field name="home_gh" type="geohash" indexed="true" stored="true" multiValued="false"/>
 
 
@@ -542,6 +547,7 @@
    <dynamicField name="*_l1"  type="long"   indexed="true"  stored="true" multiValued="false"/>
    <dynamicField name="*_t"  type="text"    indexed="true"  stored="true"/>
    <dynamicField name="*_b"  type="boolean" indexed="true"  stored="true"/>
+   <dynamicField name="*_b1" type="boolean" indexed="true"  stored="true" multiValued="false"/>
    <dynamicField name="*_f"  type="float"  indexed="true"  stored="true"/>
    <dynamicField name="*_f1"  type="float"  indexed="true"  stored="true" multiValued="false"/>
    <dynamicField name="*_d"  type="double" indexed="true"  stored="true"/>
@@ -549,6 +555,11 @@
    <dynamicField name="*_dt" type="date"    indexed="true"  stored="true"/>
    <dynamicField name="*_dt1" type="date"    indexed="true"  stored="true" multiValued="false"/>
    <dynamicField name="*_bcd" type="bcdstr" indexed="true"  stored="true"/>
+   <dynamicField name="*_by"  type="byte"  indexed="true" stored="true"/>
+   <dynamicField name="*_by1" type="byte"  indexed="true" stored="true" multiValued="false"/>
+   <dynamicField name="*_sh" type="short"  indexed="true" stored="true"/>
+   <dynamicField name="*_sh1" type="short"  indexed="true" stored="true" multiValued="false"/>
+
 
       <!-- some trie-coded dynamic fields for faster range queries -->
    <dynamicField name="*_ti" type="tint"    indexed="true"  stored="true"/>

Modified: lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/search/SpatialFilterTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/search/SpatialFilterTest.java?rev=1198049&r1=1198048&r2=1198049&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/search/SpatialFilterTest.java (original)
+++ lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/search/SpatialFilterTest.java Sat Nov  5 20:45:10 2011
@@ -64,7 +64,7 @@ public class SpatialFilterTest extends S
     //large distance
     checkHits(fieldName, "33.0,-80.0", 5000, 13);
   }
-
+  
   @Test
   public void testGeoHash() throws Exception {
     String fieldName = "home_gh";
@@ -118,6 +118,21 @@ public class SpatialFilterTest extends S
     // falls outside of the real distance, but inside the bounding box   
     checkHits(fieldName, true, "43.517030,-96.789603", 110, 0);
     checkHits(fieldName, false, "43.517030,-96.789603", 110, 1, 17);
+    
+    
+	// Tests SOLR-2829
+	String fieldNameHome = "home_ll";
+	String fieldNameWork = "work_ll";
+
+	clearIndex();
+	assertU(adoc("id", "1", fieldNameHome, "52.67,7.30", fieldNameWork,"48.60,11.61"));
+	assertU(commit());
+
+	checkHits(fieldNameHome, "52.67,7.30", 1, 1);
+	checkHits(fieldNameWork, "48.60,11.61", 1, 1);
+	checkHits(fieldNameWork, "52.67,7.30", 1, 0);
+	checkHits(fieldNameHome, "48.60,11.61", 1, 0); 
+	  
   }
 
   private void checkHits(String fieldName, String pt, double distance, int count, int ... docIds) {
@@ -173,4 +188,4 @@ public class SpatialFilterTest extends S
             + NumericRangeQuery.class,
             query instanceof NumericRangeQuery);
     req.close();
-  }*/
\ No newline at end of file
+  }*/

Added: lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/search/TestValueSourceCache.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/search/TestValueSourceCache.java?rev=1198049&view=auto
==============================================================================
--- lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/search/TestValueSourceCache.java (added)
+++ lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/search/TestValueSourceCache.java Sat Nov  5 20:45:10 2011
@@ -0,0 +1,132 @@
+package org.apache.solr.search;
+
+/*
+ * 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.search.Query;
+import org.apache.lucene.search.QueryUtils;
+import org.apache.solr.SolrTestCaseJ4;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+// NOTE: this is a direct result of SOLR-2829
+public class TestValueSourceCache extends SolrTestCaseJ4 {
+
+  @BeforeClass
+  public static void beforeClass() throws Exception {
+    initCore("solrconfig.xml", "schema.xml");
+  }
+
+  // This is actually also tested by the tests for val_d1 below, but the bug was reported against geodist()...
+  @Test
+  public void testGeodistSource() {
+    try {
+      Query q_home = QueryParsing.parseFunction("geodist(home_ll, 45.0, 43.0)", h.getCore().getSchema());
+      Query q_work = QueryParsing.parseFunction("geodist(work_ll, 45.0, 43.0)", h.getCore().getSchema());
+      Query q_home2 = QueryParsing.parseFunction("geodist(home_ll, 45.0, 43.0)", h.getCore().getSchema());
+      QueryUtils.checkUnequal(q_work, q_home);
+      QueryUtils.checkEqual(q_home, q_home2);
+    } catch (Exception e) {
+      fail(e.toString());
+    }
+  }
+
+  @Test
+  public void testNumerics() {
+    String[] templates = new String[]{
+        "sum(#v0, #n0)",
+        "product(pow(#v0,#n0),#v1,#n1)",
+        "log(#v0)",
+        "log(sum(#n0,#v0,#v1,#n1))",
+        "scale(map(#v0,#n0,#n1,#n2),#n3,#n4)",
+    };
+    String[] numbers = new String[]{
+        "1,2,3,4,5",
+        "1.0,2.0,3.0,4.0,5.0",
+        "1,2.0,3,4.0,5",
+        "1.0,2,3.0,4,5.0",
+        "1000000,2000000,3000000,4000000,5000000"
+    };
+    String[] types = new String[]{
+        "val1_f1",
+        "val1_d1",
+        "val1_b1",
+        "val1_i1",
+        "val1_l1",
+        "val1_b1",
+        "val1_by1",
+        "val1_sh1"
+    };
+    for (String template : templates) {
+      for (String nums : numbers) {
+        for (String type : types) {
+          tryQuerySameTypes(template, nums, type);
+          tryQueryDiffTypes(template, nums, types);
+        }
+      }
+    }
+  }
+
+  // This test should will fail because q1 and q3 evaluate as equal unless
+  // fixes for bug 2829 are in place.
+  void tryQuerySameTypes(String template, String numbers, String type) {
+    try {
+      String s1 = template;
+      String s2 = template;
+      String s3 = template;
+
+      String[] numParts = numbers.split(",");
+      String type2 = type.replace("val1", "val2");
+      for (int idx = 0; s1.contains("#"); ++idx) {
+        String patV = "#v" + Integer.toString(idx);
+        String patN = "#n" + Integer.toString(idx);
+        s1 = s1.replace(patV, type).replace(patN, numParts[idx]);
+        s2 = s2.replace(patV, type).replace(patN, numParts[idx]);
+        s3 = s3.replace(patV, type2).replace(patN, numParts[idx]);
+      }
+      Query q1 = QueryParsing.parseFunction(s1, h.getCore().getSchema());
+      Query q2 = QueryParsing.parseFunction(s2, h.getCore().getSchema());
+      Query q3 = QueryParsing.parseFunction(s3, h.getCore().getSchema());
+      QueryUtils.checkEqual(q1, q2);
+      QueryUtils.checkUnequal(q1, q3);
+    } catch (Exception e) {
+      fail(e.toString());
+    }
+  }
+
+  // These should always and forever fail, and would have failed without the fixes for 2829, but why not make
+  // some more tests just in case???
+  void tryQueryDiffTypes(String template, String numbers, String[] types) {
+    try {
+      String s1 = template;
+      String s2 = template;
+
+      String[] numParts = numbers.split(",");
+      for (int idx = 0; s1.contains("#"); ++idx) {
+        String patV = "#v" + Integer.toString(idx);
+        String patN = "#n" + Integer.toString(idx);
+        s1 = s1.replace(patV, types[idx % types.length]).replace(patN, numParts[idx]);
+        s2 = s2.replace(patV, types[(idx + 1) % types.length]).replace(patN, numParts[idx]);
+      }
+      Query q1 = QueryParsing.parseFunction(s1, h.getCore().getSchema());
+      Query q2 = QueryParsing.parseFunction(s2, h.getCore().getSchema());
+      QueryUtils.checkUnequal(q1, q2);
+    } catch (Exception e) {
+      fail(e.toString());
+    }
+  }
+}