Java Code Examples for org.apache.lucene.index.Term#equals()

The following examples show how to use org.apache.lucene.index.Term#equals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/** SpanNearQuery([A, B], 0, true) = "A B" */
public void testSpanNearVersusPhrase() throws Exception {
  Term t1 = randomTerm();
  Term t2 = randomTerm();
  SpanQuery subquery[] = new SpanQuery[] { 
                           spanQuery(new SpanTermQuery(t1)), 
                           spanQuery(new SpanTermQuery(t2)) 
                         };
  SpanQuery q1 = spanQuery(new SpanNearQuery(subquery, 0, true));
  PhraseQuery q2 = new PhraseQuery(t1.field(), t1.bytes(), t2.bytes());
  if (t1.equals(t2)) {
    assertSameSet(q1, q2);
  } else {
    assertSameScores(q1, q2);
  }
}
 
Example 2
@Override
public boolean equals(final Object obj) {

    if (obj == null) {
        return false;
    }

    if (!(obj instanceof DependentTermQuery)) {
        return false;
    }

    final DependentTermQuery other = (DependentTermQuery) obj;
    final Term term = getTerm();

    if (!term.equals(other.getTerm())) {
        return false;
    }

    if (tqIndex != other.tqIndex)
        return false;

    return fieldBoost.equals(other.fieldBoost);

}
 
Example 3
public void testNestedConjunction() throws Exception {
  Term t1 = randomTerm();
  Term t2;
  do {
    t2 = randomTerm();
  } while (t1.equals(t2));
  Term t3 = randomTerm();
  TermQuery q1 = new TermQuery(t1);
  TermQuery q2 = new TermQuery(t2);
  TermQuery q3 = new TermQuery(t3);

  BooleanQuery.Builder bq1 = new BooleanQuery.Builder();
  bq1.add(q1, Occur.MUST);
  bq1.add(q2, Occur.MUST);

  BooleanQuery.Builder bq2 = new BooleanQuery.Builder();
  bq2.add(bq1.build(), Occur.MUST);
  bq2.add(q3, Occur.MUST);
  
  BooleanQuery.Builder bq3 = new BooleanQuery.Builder();
  bq3.add(new RandomApproximationQuery(q1, random()), Occur.MUST);
  bq3.add(new RandomApproximationQuery(q2, random()), Occur.MUST);

  BooleanQuery.Builder bq4 = new BooleanQuery.Builder();
  bq4.add(bq3.build(), Occur.MUST);
  bq4.add(q3, Occur.MUST);

  assertSameScores(bq2.build(), bq4.build());
}
 
Example 4
public void testNestedDisjunction() throws Exception {
  Term t1 = randomTerm();
  Term t2;
  do {
    t2 = randomTerm();
  } while (t1.equals(t2));
  Term t3 = randomTerm();
  TermQuery q1 = new TermQuery(t1);
  TermQuery q2 = new TermQuery(t2);
  TermQuery q3 = new TermQuery(t3);

  BooleanQuery.Builder bq1 = new BooleanQuery.Builder();
  bq1.add(q1, Occur.SHOULD);
  bq1.add(q2, Occur.SHOULD);

  BooleanQuery.Builder bq2 = new BooleanQuery.Builder();
  bq2.add(bq1.build(), Occur.SHOULD);
  bq2.add(q3, Occur.SHOULD);

  BooleanQuery.Builder bq3 = new BooleanQuery.Builder();
  bq3.add(new RandomApproximationQuery(q1, random()), Occur.SHOULD);
  bq3.add(new RandomApproximationQuery(q2, random()), Occur.SHOULD);

  BooleanQuery.Builder bq4 = new BooleanQuery.Builder();
  bq4.add(bq3.build(), Occur.SHOULD);
  bq4.add(q3, Occur.SHOULD);

  assertSameScores(bq2.build(), bq4.build());
}
 
Example 5
public void testDisjunctionInConjunction() throws Exception {
  Term t1 = randomTerm();
  Term t2;
  do {
    t2 = randomTerm();
  } while (t1.equals(t2));
  Term t3 = randomTerm();
  TermQuery q1 = new TermQuery(t1);
  TermQuery q2 = new TermQuery(t2);
  TermQuery q3 = new TermQuery(t3);

  BooleanQuery.Builder bq1 = new BooleanQuery.Builder();
  bq1.add(q1, Occur.SHOULD);
  bq1.add(q2, Occur.SHOULD);

  BooleanQuery.Builder bq2 = new BooleanQuery.Builder();
  bq2.add(bq1.build(), Occur.MUST);
  bq2.add(q3, Occur.MUST);

  BooleanQuery.Builder bq3 = new BooleanQuery.Builder();
  bq3.add(new RandomApproximationQuery(q1, random()), Occur.SHOULD);
  bq3.add(new RandomApproximationQuery(q2, random()), Occur.SHOULD);

  BooleanQuery.Builder bq4 = new BooleanQuery.Builder();
  bq4.add(bq3.build(), Occur.MUST);
  bq4.add(q3, Occur.MUST);

  assertSameScores(bq2.build(), bq4.build());
}
 
Example 6
public void testConjunctionInDisjunction() throws Exception {
  Term t1 = randomTerm();
  Term t2;
  do {
    t2 = randomTerm();
  } while (t1.equals(t2));
  Term t3 = randomTerm();
  TermQuery q1 = new TermQuery(t1);
  TermQuery q2 = new TermQuery(t2);
  TermQuery q3 = new TermQuery(t3);

  BooleanQuery.Builder bq1 = new BooleanQuery.Builder();
  bq1.add(q1, Occur.MUST);
  bq1.add(q2, Occur.MUST);

  BooleanQuery.Builder bq2 = new BooleanQuery.Builder();
  bq2.add(bq1.build(), Occur.SHOULD);
  bq2.add(q3, Occur.SHOULD);

  BooleanQuery.Builder bq3 = new BooleanQuery.Builder();
  bq3.add(new RandomApproximationQuery(q1, random()), Occur.MUST);
  bq3.add(new RandomApproximationQuery(q2, random()), Occur.MUST);

  BooleanQuery.Builder bq4 = new BooleanQuery.Builder();
  bq4.add(bq3.build(), Occur.SHOULD);
  bq4.add(q3, Occur.SHOULD);

  assertSameScores(bq2.build(), bq4.build());
}
 
Example 7
public void testReqOpt() throws Exception {
  Term t1 = randomTerm();
  Term t2;
  do {
    t2 = randomTerm();
  } while (t1.equals(t2));
  Term t3 = randomTerm();
  TermQuery q1 = new TermQuery(t1);
  TermQuery q2 = new TermQuery(t2);
  TermQuery q3 = new TermQuery(t3);

  BooleanQuery.Builder bq1 = new BooleanQuery.Builder();
  bq1.add(q1, Occur.MUST);
  bq1.add(q2, Occur.SHOULD);

  BooleanQuery.Builder bq2 = new BooleanQuery.Builder();
  bq2.add(bq1.build(), Occur.MUST);
  bq2.add(q3, Occur.MUST);
  
  BooleanQuery.Builder bq3 = new BooleanQuery.Builder();
  bq3.add(new RandomApproximationQuery(q1, random()), Occur.MUST);
  bq3.add(new RandomApproximationQuery(q2, random()), Occur.SHOULD);

  BooleanQuery.Builder bq4 = new BooleanQuery.Builder();
  bq4.add(bq3.build(), Occur.MUST);
  bq4.add(q3, Occur.MUST);

  assertSameScores(bq2.build(), bq4.build());
}
 
Example 8
/** "A B"~∞ = +A +B if A != B */
public void testSloppyPhraseVersusBooleanAnd() throws Exception {
  Term t1 = randomTerm();
  Term t2 = null;
  // semantics differ from SpanNear: SloppyPhrase handles repeats,
  // so we must ensure t1 != t2
  do {
    t2 = randomTerm();
  } while (t1.equals(t2));
  PhraseQuery q1 = new PhraseQuery(Integer.MAX_VALUE, t1.field(), t1.bytes(), t2.bytes());
  BooleanQuery.Builder q2 = new BooleanQuery.Builder();
  q2.add(new TermQuery(t1), Occur.MUST);
  q2.add(new TermQuery(t2), Occur.MUST);
  assertSameSet(q1, q2.build());
}
 
Example 9
public void testNestedExclusion() throws Exception {
  Term t1 = randomTerm();
  Term t2;
  do {
    t2 = randomTerm();
  } while (t1.equals(t2));
  Term t3 = randomTerm();
  TermQuery q1 = new TermQuery(t1);
  TermQuery q2 = new TermQuery(t2);
  TermQuery q3 = new TermQuery(t3);

  BooleanQuery.Builder bq1 = new BooleanQuery.Builder();
  bq1.add(q1, Occur.MUST);
  bq1.add(q2, Occur.MUST_NOT);

  BooleanQuery.Builder bq2 = new BooleanQuery.Builder();
  bq2.add(bq1.build(), Occur.MUST);
  bq2.add(q3, Occur.MUST);

  // Both req and excl have approximations
  BooleanQuery.Builder bq3 = new BooleanQuery.Builder();
  bq3.add(new RandomApproximationQuery(q1, random()), Occur.MUST);
  bq3.add(new RandomApproximationQuery(q2, random()), Occur.MUST_NOT);

  BooleanQuery.Builder bq4 = new BooleanQuery.Builder();
  bq4.add(bq3.build(), Occur.MUST);
  bq4.add(q3, Occur.MUST);

  assertSameScores(bq2.build(), bq4.build());

  // Only req has an approximation
  bq3 = new BooleanQuery.Builder();
  bq3.add(new RandomApproximationQuery(q1, random()), Occur.MUST);
  bq3.add(q2, Occur.MUST_NOT);

  bq4 = new BooleanQuery.Builder();
  bq4.add(bq3.build(), Occur.MUST);
  bq4.add(q3, Occur.MUST);

  assertSameScores(bq2.build(), bq4.build());

  // Only excl has an approximation
  bq3 = new BooleanQuery.Builder();
  bq3.add(q1, Occur.MUST);
  bq3.add(new RandomApproximationQuery(q2, random()), Occur.MUST_NOT);

  bq4 = new BooleanQuery.Builder();
  bq4.add(bq3.build(), Occur.MUST);
  bq4.add(q3, Occur.MUST);

  assertSameScores(bq2.build(), bq4.build());
}