lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yonik Seeley (JIRA)" <>
Subject [jira] [Commented] (SOLR-2716) QueryResultKey hashCode() and equals() is dependent on filter order
Date Thu, 25 Aug 2011 15:35:29 GMT


Yonik Seeley commented on SOLR-2716:

Although it does make sense, I wonder if the increased cost in equals() would be worth it...
the complete solr request (including filters) are normally generated by another system, not
a user, so one will normally see filters in the same order anyway.

Fixing hashCode for no performance impact is easy, and for equals() perhaps we can put the
comparison of filters last so it's often only executed when other components already match,
and optimize a number of cases (check length first, if lengths==1 then comparison is simple).
 The problem is when lengths!=1 - I don't see a simple way to quickly compare w/o adding more
state to the QueryCacheKey or doing a fair bit more CPU work.

> QueryResultKey hashCode() and equals() is dependent on filter order
> -------------------------------------------------------------------
>                 Key: SOLR-2716
>                 URL:
>             Project: Solr
>          Issue Type: Improvement
>          Components: search
>    Affects Versions: 3.3
>            Reporter: Neil Prosser
>            Priority: Minor
>         Attachments: SOLR-2716.patch
> The hashCode() and equals() methods of a QueryResultKey are dependent on the order of
the filters meaning that potentially identical result sets are missed when cached.
> Query query = new TermQuery(new Term("field1", "value1"));
> Query filter1 = new TermQuery(new Term("field2", "value2"));
> Query filter2 = new TermQuery(new Term("field3", "value3"));
> List<Query> filters1 = new ArrayList<Query>();
> filters1.add(filter1);
> filters1.add(filter2);
> List<Query> filters2 = new ArrayList<Query>();
> filters2.add(filter2);
> filters2.add(filter1);
> QueryResultKey key1 = new QueryResultKey(query, filters1, null, 0);
> QueryResultKey key2 = new QueryResultKey(query, filters2, null, 0);
> // Both the following assertions fail
> assert key1.equals(key2);
> assert key1.hashCode() == key2.hashCode();

This message is automatically generated by JIRA.
For more information on JIRA, see:


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message