Package org.apache.lucene.search

Examples of org.apache.lucene.search.BooleanClause


      Collections.shuffle(terms, random());
      int numTerms = 1 + random().nextInt(
          Math.min(BooleanQuery.getMaxClauseCount(), terms.size()));
      BooleanQuery bq = new BooleanQuery();
      for (int j = 0; j < numTerms; j++) {
        bq.add(new BooleanClause(new TermQuery(terms.get(j)), Occur.SHOULD));
      }
      TopDocs queryResult = searcher.search(new ConstantScoreQuery(bq), reader.maxDoc());
     
      MatchAllDocsQuery matchAll = new MatchAllDocsQuery();
      final TermsFilter filter = termsFilter(singleField, terms.subList(0, numTerms));;
View Full Code Here


   * Add a clause to a boolean query.
   */
  private static void add(BooleanQuery q, String name, String value, 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

  /**
   * Add a clause to a boolean query.
   */
  private static void add(BooleanQuery q, String name, String value) {
    q.add(new BooleanClause(new TermQuery(new Term(name, value)), BooleanClause.Occur.SHOULD));
  }
View Full Code Here

  private int countDocsWithClass() throws IOException {
    int docCount = MultiFields.getTerms(this.atomicReader, this.classFieldName).getDocCount();
    if (docCount == -1) { // in case codec doesn't support getDocCount
      TotalHitCountCollector totalHitCountCollector = new TotalHitCountCollector();
      BooleanQuery q = new BooleanQuery();
      q.add(new BooleanClause(new WildcardQuery(new Term(classFieldName, String.valueOf(WildcardQuery.WILDCARD_STRING))), BooleanClause.Occur.MUST));
      if (query != null) {
        q.add(query, BooleanClause.Occur.MUST);
      }
      indexSearcher.search(q,
          totalHitCountCollector);
View Full Code Here

  private int getWordFreqForClass(String word, BytesRef c) throws IOException {
    BooleanQuery booleanQuery = new BooleanQuery();
    BooleanQuery subQuery = new BooleanQuery();
    for (String textFieldName : textFieldNames) {
     subQuery.add(new BooleanClause(new TermQuery(new Term(textFieldName, word)), BooleanClause.Occur.SHOULD));
    }
    booleanQuery.add(new BooleanClause(subQuery, BooleanClause.Occur.MUST));
    booleanQuery.add(new BooleanClause(new TermQuery(new Term(classFieldName, c)), BooleanClause.Occur.MUST));
    if (query != null) {
      booleanQuery.add(query, BooleanClause.Occur.MUST);
    }
    TotalHitCountCollector totalHitCountCollector = new TotalHitCountCollector();
    indexSearcher.search(booleanQuery, totalHitCountCollector);
View Full Code Here

    if (mlt == null) {
      throw new IOException("You must first call Classifier#train");
    }
    BooleanQuery mltQuery = new BooleanQuery();
    for (String textFieldName : textFieldNames) {
      mltQuery.add(new BooleanClause(mlt.like(new StringReader(text), textFieldName), BooleanClause.Occur.SHOULD));
    }
    Query classFieldQuery = new WildcardQuery(new Term(classFieldName, "*"));
    mltQuery.add(new BooleanClause(classFieldQuery, BooleanClause.Occur.MUST));
    if (query != null) {
      mltQuery.add(query, BooleanClause.Occur.MUST);
    }
    TopDocs topDocs = indexSearcher.search(mltQuery, k);
    return selectClassFromNeighbors(topDocs);
View Full Code Here

   * automata that will match terms.
   */
  static CharacterRunAutomaton[] extractAutomata(Query query, String field) {
    List<CharacterRunAutomaton> list = new ArrayList<CharacterRunAutomaton>();
    if (query instanceof BooleanQuery) {
      BooleanClause clauses[] = ((BooleanQuery) query).getClauses();
      for (BooleanClause clause : clauses) {
        if (!clause.isProhibited()) {
          list.addAll(Arrays.asList(extractAutomata(clause.getQuery(), field)));
        }
      }
View Full Code Here

      baseQuery = clauses.get(0).getQuery();
      startIndex = 1;
    }

    for(int i=startIndex;i<clauses.size();i++) {
      BooleanClause clause = clauses.get(i);
      Query queryClause = clause.getQuery();
      Filter filter = getFilter(queryClause);
      if (filter != null) {
        filters.add(filter);
      } else {
        queries.add(queryClause);
View Full Code Here

    default:
      throw new RuntimeException("Occur [" + o + "] not supported");
    }
    QueryWritable queryWritable = new QueryWritable();
    queryWritable.readFields(in);
    booleanClause = new BooleanClause(queryWritable.getQuery(), occur);
  }
View Full Code Here

    BooleanQuery bq = (BooleanQuery) orig.rewrite(reader);

    BooleanClause[] clauses = bq.getClauses();
    SpanQuery[] sqs = new SpanQuery[clauses.length];
    for (int i = 0; i < clauses.length; i++) {
      BooleanClause clause = clauses[i];

      // Clauses from RegexQuery.rewrite are always TermQuery's
      TermQuery tq = (TermQuery) clause.getQuery();

      sqs[i] = new SpanTermQuery(tq.getTerm());
      sqs[i].setBoost(tq.getBoost());
    }
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.