Apache Solr open-source search software
SOLR-4642: QueryResultKey is not calculating the correct hashCode for filters.
Mark Robert Millerb4e22c267dde
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 677df42a4f3..49794c98ce0 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -253,6 +253,9 @@ Bug Fixes* SOLR-4640: CachingDirectoryFactory can fail to close directories in some raceconditions. (Mark Miller)+* SOLR-4642: QueryResultKey is not calculating the correct hashCode for filters.+ (Joel Bernstein via Mark Miller)+Optimizations----------------------diff --git a/solr/core/src/java/org/apache/solr/search/QueryResultKey.java b/solr/core/src/java/org/apache/solr/search/QueryResultKey.javaindex 003aae4c913..b439fe3ca0a 100644--- a/solr/core/src/java/org/apache/solr/search/QueryResultKey.java+++ b/solr/core/src/java/org/apache/solr/search/QueryResultKey.java@@ -47,7 +47,7 @@ public final class QueryResultKey {if (filters != null) {for (Query filt : filters)- h += filters.hashCode();+ h += filt.hashCode();}sfields = (this.sort !=null) ? this.sort.getSort() : defaultSort;diff --git a/solr/core/src/test/org/apache/solr/core/QueryResultKeyTest.java b/solr/core/src/test/org/apache/solr/core/QueryResultKeyTest.javanew file mode 100644index 00000000000..3702d254f54--- /dev/null+++ b/solr/core/src/test/org/apache/solr/core/QueryResultKeyTest.java@@ -0,0 +1,59 @@+/*+ * 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.+ */++package org.apache.solr.core;++import java.util.ArrayList;+import java.util.List;++import org.apache.lucene.index.Term;+import org.apache.lucene.search.BooleanClause.Occur;+import org.apache.lucene.search.BooleanQuery;+import org.apache.lucene.search.Query;+import org.apache.lucene.search.Sort;+import org.apache.lucene.search.SortField;+import org.apache.lucene.search.TermQuery;+import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.search.QueryResultKey;+import org.junit.Test;++public class QueryResultKeyTest extends SolrTestCaseJ4 {++ @Test+ public void testFiltersHashCode() {+ // the hashcode should be the same even when the list+ // of filters is in a different order++ Sort sort = new Sort(new SortField("test", SortField.Type.BYTE));+ List<Query> filters = new ArrayList<Query>();+ filters.add(new TermQuery(new Term("test", "field")));+ filters.add(new TermQuery(new Term("test2", "field2")));++ BooleanQuery query = new BooleanQuery();+ query.add(new TermQuery(new Term("test", "field")), Occur.MUST);++ QueryResultKey qrk1 = new QueryResultKey(query , filters, sort, 1);++ List<Query> filters2 = new ArrayList<Query>();+ filters2.add(new TermQuery(new Term("test2", "field2")));+ filters2.add(new TermQuery(new Term("test", "field")));+ QueryResultKey qrk2 = new QueryResultKey(query , filters2, sort, 1);++ assertEquals(qrk1.hashCode(), qrk2.hashCode());+ }++}