Package org.apache.lucene.search

Examples of org.apache.lucene.search.BooleanClause


    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


   * 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

    parser.setMultiFields(fields);
    parser.setDefaultOperator(StandardQueryConfigHandler.Operator.AND);
    parser.setAnalyzer(new MockAnalyzer(random()));

    BooleanQuery exp = new BooleanQuery();
    exp.add(new BooleanClause(new RegexpQuery(new Term("b", "ab.+")), BooleanClause.Occur.SHOULD));//TODO spezification? was "MUST"
    exp.add(new BooleanClause(new RegexpQuery(new Term("t", "ab.+")), BooleanClause.Occur.SHOULD));//TODO spezification? was "MUST"

    assertEquals(exp, parser.parse("/ab.+/", null));

    RegexpQuery regexpQueryexp = new RegexpQuery(new Term("test", "[abc]?[0-9]"));
View Full Code Here

  private final QueryCustomizer queryCustomizer;

  public ConnectedAllContext() {
    this.queryCustomizer = new QueryCustomizer();
    this.clauses = new ArrayList<BooleanClause>(5);
    this.clauses.add( new BooleanClause( new MatchAllDocsQuery(), BooleanClause.Occur.SHOULD ) );
  }
View Full Code Here

  }

  @Override
  public AllContext except(Query... queriesMatchingExcludedDocuments) {
    for ( Query query : queriesMatchingExcludedDocuments ) {
      clauses.add( new BooleanClause( query, BooleanClause.Occur.MUST_NOT ) );
    }
    return this;
  }
View Full Code Here

  }

  @Override
  public BooleanJunction not() {
    final int lastIndex = clauses.size() - 1;
    final BooleanClause last = clauses.get( lastIndex );
    if ( ! last.getOccur().equals( BooleanClause.Occur.MUST ) ) {
      throw new AssertionFailure( "Cannot negate class: " + last.getOccur() );
    }
    clauses.set( lastIndex, new BooleanClause( last.getQuery(), BooleanClause.Occur.MUST_NOT ) );
    return this;
  }
View Full Code Here

    return this;
  }

  @Override
  public BooleanJunction should(Query query) {
    clauses.add( new BooleanClause( query, BooleanClause.Occur.SHOULD ) );
    return this;
  }
View Full Code Here

    return this;
  }

  @Override
  public MustJunction must(Query query) {
    clauses.add( new BooleanClause( query, BooleanClause.Occur.MUST ) );
    return this;
  }
View Full Code Here

    final int nbrOfClauses = clauses.size();
    if ( nbrOfClauses == 0 ) {
      throw new AssertionFailure( "Cannot create an empty boolean query" );
    }
    else if ( nbrOfClauses == 1 ) {
      final BooleanClause uniqueClause = clauses.get( 0 );
      if ( uniqueClause.getOccur().equals( BooleanClause.Occur.MUST_NOT ) ) {
        //FIXME We have two choices here, raise an exception or combine with an All query. #2 is done atm.
        //TODO which normfield to use and how to pass it?
        should( new MatchAllDocsQuery() );
      }
      else {
        //optimize
        return queryCustomizer.setWrappedQuery( uniqueClause.getQuery() ).createQuery();
      }
    }

    BooleanQuery query = new BooleanQuery();
    for ( BooleanClause clause : clauses ) {
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.