SOLR-4642: QueryResultKey is not calculating the correct hashCode for filters.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1460803 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2013-03-25 18:16:14 +00:00
parent d1cbd22a65
commit b4e22c267d
3 changed files with 63 additions and 1 deletions

View File

@ -253,6 +253,9 @@ Bug Fixes
* SOLR-4640: CachingDirectoryFactory can fail to close directories in some race
conditions. (Mark Miller)
* SOLR-4642: QueryResultKey is not calculating the correct hashCode for filters.
(Joel Bernstein via Mark Miller)
Optimizations
----------------------

View File

@ -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;

View File

@ -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());
}
}