Package org.apache.lucene.search

Examples of org.apache.lucene.search.BooleanClause


   * @param boost boost
   */
  private static void add(final BooleanQuery q, final String name, final String value, final float boost) {
    Query tq = new TermQuery(new Term(name, value));
    tq.setBoost(boost);
    q.add(new BooleanClause(tq, BooleanClause.Occur.SHOULD));
  }
View Full Code Here


   * @param q query
   * @param name name
   * @param value value
   */
  private static void add(final BooleanQuery q, final String name, final String value) {
    q.add(new BooleanClause(new TermQuery(new Term(name, value)), BooleanClause.Occur.SHOULD));
  }
View Full Code Here

        Query replacedTerms = replaceTerms(clause.getQuery(), replacements);

        // we need to check if the query is null because
        // removeEmptyClauses returns null if there are no clauses in it (except empty ones)
        if (replacedTerms != null) {
          BooleanClause newClause = new BooleanClause(replacedTerms, clause.getOccur());
          newQuery.add(newClause);
        }
      }
      // if the query contains empty clauses we want them removed
      // if the query does not contain any non empty clauses this method returns null
View Full Code Here

    Query q1 = sq(rq_e("a.id_date", t1, t2));
    assertQuery(q1, q);
  }

  public static BooleanClause bc_m(Query q) {
    return new BooleanClause(q, Occur.MUST);
  }
View Full Code Here

  public static BooleanClause bc_m(Query q) {
    return new BooleanClause(q, Occur.MUST);
  }

  public static BooleanClause bc_n(Query q) {
    return new BooleanClause(q, Occur.MUST_NOT);
  }
View Full Code Here

  public static BooleanClause bc_n(Query q) {
    return new BooleanClause(q, Occur.MUST_NOT);
  }

  public static BooleanClause bc(Query q) {
    return new BooleanClause(q, Occur.SHOULD);
  }
View Full Code Here

     * @exception ParseException throw in overridden method to disallow
     */
    protected Query getSynonymQuery(String field, String termStr)
            throws ParseException {
        List<BooleanClause> synonyms = new ArrayList<BooleanClause>();
        synonyms.add(new BooleanClause(getFieldQuery(field, termStr),
                BooleanClause.Occur.SHOULD));
        if (synonymProvider != null) {
            for (String term : synonymProvider.getSynonyms(termStr)) {
                synonyms.add(new BooleanClause(getFieldQuery(field, term), BooleanClause.Occur.SHOULD));
            }
        }
        if (synonyms.size() == 1) {
            return synonyms.get(0).getQuery();
        } else {
View Full Code Here

    Query parentQueryWithRandomChild = createChildrenQueryWithOneParent(nextRandomChildNumber);
    ToParentBlockJoinQuery blockJoinQuery = new ToParentBlockJoinQuery(parentQueryWithRandomChild, parentsFilter, ScoreMode.None);
    // advance() method is used by ConjunctionScorer, so we need to create Boolean conjunction query
    BooleanQuery conjunctionQuery = new BooleanQuery();
    WildcardQuery childQuery = new WildcardQuery(new Term("child", createFieldValue(randomChildNumber)));
    conjunctionQuery.add(new BooleanClause(childQuery, BooleanClause.Occur.MUST));
    conjunctionQuery.add(new BooleanClause(blockJoinQuery, BooleanClause.Occur.MUST));

    thrown.expect(IllegalStateException.class);
    thrown.expectMessage("child query must only match non-parent docs");
    indexSearcher.search(conjunctionQuery, 1);
  }
View Full Code Here

    Query parentQueryWithRandomChild = createParentsQueryWithOneChild(nextRandomChildNumber);
    ToChildBlockJoinQuery blockJoinQuery = new ToChildBlockJoinQuery(parentQueryWithRandomChild, parentsFilter, false);
    // advance() method is used by ConjunctionScorer, so we need to create Boolean conjunction query
    BooleanQuery conjunctionQuery = new BooleanQuery();
    WildcardQuery childQuery = new WildcardQuery(new Term("child", createFieldValue(randomChildNumber)));
    conjunctionQuery.add(new BooleanClause(childQuery, BooleanClause.Occur.MUST));
    conjunctionQuery.add(new BooleanClause(blockJoinQuery, BooleanClause.Occur.MUST));

    thrown.expect(IllegalStateException.class);
    thrown.expectMessage(ToChildBlockJoinQuery.INVALID_QUERY_MESSAGE);
    indexSearcher.search(conjunctionQuery, 1);
  }
View Full Code Here

  private static Query createChildrenQueryWithOneParent(int childNumber) {
    TermQuery childQuery = new TermQuery(new Term("child", createFieldValue(childNumber)));
    Query randomParentQuery = new TermQuery(new Term("id", createFieldValue(getRandomParentId())));
    BooleanQuery childrenQueryWithRandomParent = new BooleanQuery();
    childrenQueryWithRandomParent.add(new BooleanClause(childQuery, BooleanClause.Occur.SHOULD));
    childrenQueryWithRandomParent.add(new BooleanClause(randomParentQuery, BooleanClause.Occur.SHOULD));
    return childrenQueryWithRandomParent;
  }
View Full Code Here

TOP

Related Classes of org.apache.lucene.search.BooleanClause

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.