Package org.apache.lucene.search

Examples of org.apache.lucene.search.BooleanQuery


      return luceneQuery;
    }
    else {
      //A query filter is more practical than a manual class filtering post query (esp on scrollable resultsets)
      //it also probably minimise the memory footprint 
      BooleanQuery classFilter = new BooleanQuery();
      //annihilate the scoring impact of DocumentBuilder.CLASS_FIELDNAME
      classFilter.setBoost( 0 );
      for ( Class clazz : classesAndSubclasses ) {
        Term t = new Term( DocumentBuilder.CLASS_FIELDNAME, clazz.getName() );
        TermQuery termQuery = new TermQuery( t );
        classFilter.add( termQuery, BooleanClause.Occur.SHOULD );
      }
      BooleanQuery filteredQuery = new BooleanQuery();
      filteredQuery.add( luceneQuery, BooleanClause.Occur.MUST );
      filteredQuery.add( classFilter, BooleanClause.Occur.MUST );
      return filteredQuery;
    }
  }
View Full Code Here


  public void performWork(LuceneWork work, IndexWriter writer) {
    final Class<?> entityType = work.getEntityClass();
    log.trace( "Removing {}#{} by query.", entityType, work.getId() );
    DocumentBuilder<?> builder = workspace.getDocumentBuilder( entityType );

    BooleanQuery entityDeletionQuery = new BooleanQuery();

    TermQuery idQueryTerm = new TermQuery( builder.getTerm( work.getId() ) );
    entityDeletionQuery.add( idQueryTerm, BooleanClause.Occur.MUST );

    Term classNameQueryTerm =  new Term( DocumentBuilder.CLASS_FIELDNAME, entityType.getName() );
    TermQuery classNameQuery = new TermQuery( classNameQueryTerm );
    entityDeletionQuery.add( classNameQuery, BooleanClause.Occur.MUST );

    try {
      writer.deleteDocuments( entityDeletionQuery );
    }
    catch ( Exception e ) {
View Full Code Here

    } else {
      if (severalTokensAtSamePosition) {
        if (positionCount == 1) {
          // no phrase query:
          // BooleanQuery q = newBooleanQuery(true);
          BooleanQuery q = new BooleanQuery(true);
          for (int i = 0; i < numTokens; i++) {
            String term = null;
            try {
              boolean hasNext = buffer.incrementToken();
              assert hasNext == true;
              term = termAtt.toString();
            } catch (IOException e) {
              // safe to ignore, because we know the number of tokens
            }

            // Query currentQuery = newTermQuery(new Term(field, term));
            Query currentQuery = new TermQuery(new Term(field, term));
            q.add(currentQuery, BooleanClause.Occur.SHOULD);
          }
          return q;
        }
        else {
          // phrase query:
View Full Code Here

    }
   
    /* the main query we will execute.  we disable the coord because
     * this query is an artificial construct
     */
    BooleanQuery query = new BooleanQuery(true);

    addMainQuery(query, solrParams);
    addBoostQuery(query, solrParams);
    addBoostFunctions(query, solrParams);

View Full Code Here

    String minShouldMatch = solrParams.get(DisMaxParams.MM, "100%");
    Query dis = up.parse(userQuery);
    Query query = dis;

    if (dis instanceof BooleanQuery) {
      BooleanQuery t = new BooleanQuery();
      SolrPluginUtils.flattenBooleanQuery(t, (BooleanQuery) dis);
      SolrPluginUtils.setMinShouldMatch(t, minShouldMatch);
      query = t;
    }
    return query;
View Full Code Here

public class QueryUtils {

  /** return true if this query has no positive components */
  public static boolean isNegative(Query q) {
    if (!(q instanceof BooleanQuery)) return false;
    BooleanQuery bq = (BooleanQuery)q;
    List<BooleanClause> clauses = bq.clauses();
    if (clauses.size()==0) return false;
    for (BooleanClause clause : clauses) {
      if (!clause.isProhibited()) return false;
    }
    return true;
View Full Code Here

      newQ.setWrappedQuery(absSubQ);
      return newQ;
    }

    if (!(q instanceof BooleanQuery)) return q;
    BooleanQuery bq = (BooleanQuery)q;

    List<BooleanClause> clauses = bq.clauses();
    if (clauses.size()==0) return q;


    for (BooleanClause clause : clauses) {
      if (!clause.isProhibited()) return q;
    }

    if (clauses.size()==1) {
      // if only one clause, dispense with the wrapping BooleanQuery
      Query negClause = clauses.get(0).getQuery();
      // we shouldn't need to worry about adjusting the boosts since the negative
      // clause would have never been selected in a positive query, and hence would
      // not contribute to a score.
      return negClause;
    } else {
      BooleanQuery newBq = new BooleanQuery(bq.isCoordDisabled());
      newBq.setBoost(bq.getBoost());
      // ignore minNrShouldMatch... it doesn't make sense for a negative query

      // the inverse of -a -b is a OR b
      for (BooleanClause clause : clauses) {
        newBq.add(clause.getQuery(), BooleanClause.Occur.SHOULD);
      }
      return newBq;
    }
  }
View Full Code Here

  /** Fixes a negative query by adding a MatchAllDocs query clause.
   * The query passed in *must* be a negative query.
   */
  public static Query fixNegativeQuery(Query q) {
    BooleanQuery newBq = (BooleanQuery)q.clone();
    newBq.add(new MatchAllDocsQuery(), BooleanClause.Occur.MUST);
    return newBq;   
  }
View Full Code Here

    public Query getRealMLTQuery(){
      return realMLTQuery;
    }
   
    private Query getBoostedQuery(Query mltquery) {
      BooleanQuery boostedQuery = (BooleanQuery)mltquery.clone();
      if (boostFields.size() > 0) {
        List clauses = boostedQuery.clauses();
        for( Object o : clauses ) {
          TermQuery q = (TermQuery)((BooleanClause)o).getQuery();
          Float b = this.boostFields.get(q.getTerm().field());
          if (b != null) {
            q.setBoost(b*q.getBoost());
 
View Full Code Here

      if( terms != null ) {
        fillInterestingTermsFromMLTQuery( rawMLTQuery, terms );
      }

      // exclude current document from results
      realMLTQuery = new BooleanQuery();
      realMLTQuery.add(boostedMLTQuery, BooleanClause.Occur.MUST);
      realMLTQuery.add(
          new TermQuery(new Term(uniqueKeyField.getName(), uniqueKeyField.getType().storedToIndexed(doc.getFieldable(uniqueKeyField.getName())))),
            BooleanClause.Occur.MUST_NOT);
     
View Full Code Here

TOP

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

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.