Uploaded image for project: 'Solr'
  1. Solr
  2. SOLR-2716

QueryResultKey hashCode() and equals() is dependent on filter order

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Duplicate
    • Affects Version/s: 3.3
    • Fix Version/s: None
    • Component/s: search
    • Labels:
      None

      Description

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

        Attachments

        1. SOLR-2716.patch
          5 kB
          Neil Prosser

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                neilprosser Neil Prosser
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: