Example usage for org.apache.lucene.search Query hashCode

List of usage examples for org.apache.lucene.search Query hashCode

Introduction

In this page you can find the example usage for org.apache.lucene.search Query hashCode.

Prototype

@Override
public abstract int hashCode();

Source Link

Document

Override and implement query hash code properly in a subclass.

Usage

From source file:com.sindicetech.siren.search.node.TestNodeTermRangeQuery.java

License:Open Source License

public void testEqualsHashcode() {
    Query query = NodeTermRangeQuery.newStringRange(DEFAULT_TEST_FIELD, "/computera", "/computerc", true, true);

    query.setBoost(1.0f);/*ww w  . ja  v  a2  s . c  o  m*/
    Query other = NodeTermRangeQuery.newStringRange(DEFAULT_TEST_FIELD, "/computera", "/computerc", true, true);
    other.setBoost(1.0f);

    assertEquals("query equals itself is true", query, query);
    assertEquals("equivalent queries are equal", query, other);
    assertEquals("hashcode must return same value when equals is true", query.hashCode(), other.hashCode());

    other.setBoost(2.0f);
    assertFalse("Different boost queries are not equal", query.equals(other));

    other = NodeTermRangeQuery.newStringRange("notcontent", "/computera", "/computerc", true, true);
    assertFalse("Different fields are not equal", query.equals(other));

    other = NodeTermRangeQuery.newStringRange(DEFAULT_TEST_FIELD, "/computerx", "/computerc", true, true);
    assertFalse("Different lower terms are not equal", query.equals(other));

    other = NodeTermRangeQuery.newStringRange(DEFAULT_TEST_FIELD, "/computera", "/computerz", true, true);
    assertFalse("Different upper terms are not equal", query.equals(other));

    query = NodeTermRangeQuery.newStringRange(DEFAULT_TEST_FIELD, null, "/computerc", true, true);
    other = NodeTermRangeQuery.newStringRange(DEFAULT_TEST_FIELD, null, "/computerc", true, true);
    assertEquals("equivalent queries with null lowerterms are equal()", query, other);
    assertEquals("hashcode must return same value when equals is true", query.hashCode(), other.hashCode());

    query = NodeTermRangeQuery.newStringRange(DEFAULT_TEST_FIELD, "/computerc", null, true, true);
    other = NodeTermRangeQuery.newStringRange(DEFAULT_TEST_FIELD, "/computerc", null, true, true);
    assertEquals("equivalent queries with null upperterms are equal()", query, other);
    assertEquals("hashcode returns same value", query.hashCode(), other.hashCode());

    query = NodeTermRangeQuery.newStringRange(DEFAULT_TEST_FIELD, null, "/computerc", true, true);
    other = NodeTermRangeQuery.newStringRange(DEFAULT_TEST_FIELD, "/computerc", null, true, true);
    assertFalse("queries with different upper and lower terms are not equal", query.equals(other));

    query = NodeTermRangeQuery.newStringRange(DEFAULT_TEST_FIELD, "/computera", "/computerc", false, false);
    other = NodeTermRangeQuery.newStringRange(DEFAULT_TEST_FIELD, "/computera", "/computerc", true, true);
    assertFalse("queries with different inclusive are not equal", query.equals(other));
}

From source file:org.apache.solr.search.QueryResultKey.java

License:Apache License

public QueryResultKey(Query query, List<Query> filters, Sort sort, int nc_flags) {
    this.query = query;
    this.sort = sort;
    this.filters = filters;
    this.nc_flags = nc_flags;

    int h = query.hashCode();

    if (filters != null) {
        for (Query filt : filters)
            h += filt.hashCode();/*  w ww .j av  a  2s .  com*/
    }

    sfields = (this.sort != null) ? this.sort.getSort() : defaultSort;
    for (SortField sf : sfields) {
        h = h * 29 + sf.hashCode();
    }

    hc = h;
}

From source file:org.elasticsearch.index.search.ESToParentBlockJoinQueryTests.java

License:Apache License

public void testEquals() {
    Query q1 = new ESToParentBlockJoinQuery(new TermQuery(new Term("is", "child")),
            new QueryBitSetProducer(new TermQuery(new Term("is", "parent"))), ScoreMode.Avg, "nested");

    Query q2 = new ESToParentBlockJoinQuery(new TermQuery(new Term("is", "child")),
            new QueryBitSetProducer(new TermQuery(new Term("is", "parent"))), ScoreMode.Avg, "nested");
    assertEquals(q1, q2);//from  www .  j a  va 2  s  . c om
    assertEquals(q1.hashCode(), q2.hashCode());

    Query q3 = new ESToParentBlockJoinQuery(new TermQuery(new Term("is", "not_child")),
            new QueryBitSetProducer(new TermQuery(new Term("is", "parent"))), ScoreMode.Avg, "nested");
    assertFalse(q1.equals(q3));
    assertFalse(q1.hashCode() == q3.hashCode());

    Query q4 = new ESToParentBlockJoinQuery(new TermQuery(new Term("is", "child")),
            new QueryBitSetProducer(new TermQuery(new Term("is", "other_parent"))), ScoreMode.Avg, "nested");
    assertFalse(q1.equals(q4));
    assertFalse(q1.hashCode() == q4.hashCode());

    Query q5 = new ESToParentBlockJoinQuery(new TermQuery(new Term("is", "child")),
            new QueryBitSetProducer(new TermQuery(new Term("is", "parent"))), ScoreMode.Total, "nested");
    assertFalse(q1.equals(q5));
    assertFalse(q1.hashCode() == q5.hashCode());

    Query q6 = new ESToParentBlockJoinQuery(new TermQuery(new Term("is", "child")),
            new QueryBitSetProducer(new TermQuery(new Term("is", "parent"))), ScoreMode.Avg, "nested2");
    assertFalse(q1.equals(q6));
    assertFalse(q1.hashCode() == q6.hashCode());
}

From source file:org.sindice.siren.search.TestSirenTermRangeQuery.java

License:Open Source License

public void testEqualsHashcode() {
    Query query = new SirenTermRangeQuery("content", "A", "C", true, true);

    query.setBoost(1.0f);//from w w  w  . j  a v  a 2s  . com
    Query other = new SirenTermRangeQuery("content", "A", "C", true, true);
    other.setBoost(1.0f);

    assertEquals("query equals itself is true", query, query);
    assertEquals("equivalent queries are equal", query, other);
    assertEquals("hashcode must return same value when equals is true", query.hashCode(), other.hashCode());

    other.setBoost(2.0f);
    assertFalse("Different boost queries are not equal", query.equals(other));

    other = new SirenTermRangeQuery("notcontent", "A", "C", true, true);
    assertFalse("Different fields are not equal", query.equals(other));

    other = new SirenTermRangeQuery("content", "X", "C", true, true);
    assertFalse("Different lower terms are not equal", query.equals(other));

    other = new SirenTermRangeQuery("content", "A", "Z", true, true);
    assertFalse("Different upper terms are not equal", query.equals(other));

    query = new SirenTermRangeQuery("content", null, "C", true, true);
    other = new SirenTermRangeQuery("content", null, "C", true, true);
    assertEquals("equivalent queries with null lowerterms are equal()", query, other);
    assertEquals("hashcode must return same value when equals is true", query.hashCode(), other.hashCode());

    query = new SirenTermRangeQuery("content", "C", null, true, true);
    other = new SirenTermRangeQuery("content", "C", null, true, true);
    assertEquals("equivalent queries with null upperterms are equal()", query, other);
    assertEquals("hashcode returns same value", query.hashCode(), other.hashCode());

    query = new SirenTermRangeQuery("content", null, "C", true, true);
    other = new SirenTermRangeQuery("content", "C", null, true, true);
    assertFalse("queries with different upper and lower terms are not equal", query.equals(other));

    query = new SirenTermRangeQuery("content", "A", "C", false, false);
    other = new SirenTermRangeQuery("content", "A", "C", true, true);
    assertFalse("queries with different inclusive are not equal", query.equals(other));

    query = new SirenTermRangeQuery("content", "A", "C", false, false);
    other = new SirenTermRangeQuery("content", "A", "C", false, false, Collator.getInstance());
    assertFalse("a query with a collator is not equal to one without", query.equals(other));
}