diff --git a/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/NumericFieldCacheSource.java b/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/NumericFieldCacheSource.java index c0b17de19e7..fee2f63ab27 100644 --- a/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/NumericFieldCacheSource.java +++ b/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/NumericFieldCacheSource.java @@ -37,8 +37,8 @@ public abstract class NumericFieldCacheSource extends Fie if (o.getClass() != this.getClass()) return false; NumericFieldCacheSource other = (NumericFieldCacheSource) o; return super.equals(other) - && this.creator == null ? other.creator == null : - this.creator.getClass() == other.creator.getClass(); + && (this.creator == null ? other.creator == null : + this.creator.getClass() == other.creator.getClass()); } @Override diff --git a/solr/core/src/java/org/apache/solr/schema/LatLonType.java b/solr/core/src/java/org/apache/solr/schema/LatLonType.java index 6eb1d1f16a9..5071ded93ea 100644 --- a/solr/core/src/java/org/apache/solr/schema/LatLonType.java +++ b/solr/core/src/java/org/apache/solr/schema/LatLonType.java @@ -553,7 +553,7 @@ class SpatialDistanceQuery extends Query { /** Returns true if o 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 diff --git a/solr/core/src/test-files/solr/conf/schema.xml b/solr/core/src/test-files/solr/conf/schema.xml index 30369809232..c1f83d54c86 100644 --- a/solr/core/src/test-files/solr/conf/schema.xml +++ b/solr/core/src/test-files/solr/conf/schema.xml @@ -51,6 +51,9 @@ + + + @@ -457,6 +460,8 @@ + + @@ -572,6 +577,7 @@ + @@ -579,6 +585,11 @@ + + + + + diff --git a/solr/core/src/test/org/apache/solr/search/SpatialFilterTest.java b/solr/core/src/test/org/apache/solr/search/SpatialFilterTest.java index 0b1d971126c..d744b61df64 100644 --- a/solr/core/src/test/org/apache/solr/search/SpatialFilterTest.java +++ b/solr/core/src/test/org/apache/solr/search/SpatialFilterTest.java @@ -63,7 +63,7 @@ public class SpatialFilterTest extends SolrTestCaseJ4 { //large distance checkHits(fieldName, "33.0,-80.0", 5000, 13); } - + @Test public void testGeoHash() throws Exception { String fieldName = "home_gh"; @@ -117,6 +117,21 @@ public class SpatialFilterTest extends SolrTestCaseJ4 { // 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) { diff --git a/solr/core/src/test/org/apache/solr/search/TestValueSourceCache.java b/solr/core/src/test/org/apache/solr/search/TestValueSourceCache.java new file mode 100644 index 00000000000..99881020811 --- /dev/null +++ b/solr/core/src/test/org/apache/solr/search/TestValueSourceCache.java @@ -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.queryparser.classic.ParseException; +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"); + _func = QParser.getParser(null, FunctionQParserPlugin.NAME, lrf.makeRequest()); + } + + static QParser _func; + + Query getQuery(String query) throws ParseException { + _func.setString(query); + return _func.parse(); + } + + // This is actually also tested by the tests for val_d1 below, but the bug was reported against geodist()... + @Test + public void testGeodistSource() throws ParseException { + Query q_home = getQuery("geodist(home_ll, 45.0, 43.0)"); + Query q_work = getQuery("geodist(work_ll, 45.0, 43.0)"); + Query q_home2 = getQuery("geodist(home_ll, 45.0, 43.0)"); + QueryUtils.checkUnequal(q_work, q_home); + QueryUtils.checkEqual(q_home, q_home2); + } + + @Test + public void testNumerics() throws ParseException { + 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) throws ParseException { + 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]); + } + + //SolrQueryRequest req1 = req( "q","*:*", "fq", s1); + + Query q1 = getQuery(s1); + Query q2 = getQuery(s2); + Query q3 = getQuery(s3); + QueryUtils.checkEqual(q1, q2); + QueryUtils.checkUnequal(q1, q3); + } + + // 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) throws ParseException { + 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 = getQuery(s1); + Query q2 = getQuery(s2); + QueryUtils.checkUnequal(q1, q2); + } +}