Package org.apache.lucene.search

Examples of org.apache.lucene.search.BooleanQuery


                    });
    //System.out.println(CountingHitCollector.getCount());
       
       
       
    BooleanQuery bq = new BooleanQuery();
    bq.add(q1,Occur.MUST);
    bq.add(q4,Occur.MUST);
       
    searcher.search(bq,
                    new CountingHitCollector() {
                      @Override
                      public final void collect(int doc) throws IOException {
View Full Code Here


    writer.close();

    searcher = new IndexSearcher(directory, true);

    // query for everything to make life easier
    BooleanQuery bq = new BooleanQuery();
    bq.add(new TermQuery(new Term("owner", "bob")), BooleanClause.Occur.SHOULD);
    bq.add(new TermQuery(new Term("owner", "sue")), BooleanClause.Occur.SHOULD);
    query = bq;

    // date filter matches everything too
    //Date pastTheEnd = parseDate("2099 Jan 1");
    // dateFilter = DateFilter.Before("date", pastTheEnd);
View Full Code Here

  public void testMatchAllDocs() throws Exception {
    QueryParser qp = new QueryParser(Version.LUCENE_CURRENT, "field", new WhitespaceAnalyzer());
    assertEquals(new MatchAllDocsQuery(), qp.parse("*:*"));
    assertEquals(new MatchAllDocsQuery(), qp.parse("(*:*)"));
    BooleanQuery bq = (BooleanQuery)qp.parse("+*:* -*:*");
    assertTrue(bq.getClauses()[0].getQuery() instanceof MatchAllDocsQuery);
    assertTrue(bq.getClauses()[1].getQuery() instanceof MatchAllDocsQuery);
  }
View Full Code Here

                results = searchAll( query, limits, indexes, null );
            }
            else
            {
                // AND the previous search terms
                BooleanQuery booleanQuery = new BooleanQuery();
                for ( String previousSearchTerm : previousSearchTerms )
                {
                    booleanQuery.add( parser.parse( previousSearchTerm ), BooleanClause.Occur.MUST );
                }

                query = new LuceneQuery( booleanQuery );
                Filter filter = new QueryWrapperFilter( parser.parse( term ) );
                results = searchAll( query, limits, indexes, filter );
View Full Code Here

    int numQueries = atLeast(10);
    for (int i = 0; i < numQueries; i++) {
      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

      List<TermAndFreq> highTerms = queueToList(highFreqQueue);
      List<TermAndFreq> lowTerms = queueToList(lowFreqQueue);
     
      IndexSearcher searcher = newSearcher(reader);
      Occur lowFreqOccur = randomOccur(random());
      BooleanQuery verifyQuery = new BooleanQuery();
      CommonTermsQuery cq = new CommonTermsQuery(randomOccur(random()),
          lowFreqOccur, highFreq - 1, random().nextBoolean());
      for (TermAndFreq termAndFreq : lowTerms) {
        cq.add(new Term(field, termAndFreq.term));
        verifyQuery.add(new BooleanClause(new TermQuery(new Term(field,
            termAndFreq.term)), lowFreqOccur));
      }
      for (TermAndFreq termAndFreq : highTerms) {
        cq.add(new Term(field, termAndFreq.term));
      }
View Full Code Here

    }
  }

  @Test
  public void testCustomExternalQuery() throws Exception {
    BooleanQuery q1 = new BooleanQuery();
    q1.add(new TermQuery(new Term(TEXT_FIELD, "first")), BooleanClause.Occur.SHOULD);
    q1.add(new TermQuery(new Term(TEXT_FIELD, "aid")), BooleanClause.Occur.SHOULD);
    q1.add(new TermQuery(new Term(TEXT_FIELD, "text")), BooleanClause.Occur.SHOULD);
   
    final Query q = new CustomExternalQuery(q1);
    log(q);

    IndexReader r = DirectoryReader.open(dir);
View Full Code Here

    FunctionQuery functionQuery = new FunctionQuery(valueSource);
    IndexReader r = DirectoryReader.open(dir);
    IndexSearcher s = newSearcher(r);

    // regular (boolean) query.
    BooleanQuery q1 = new BooleanQuery();
    q1.add(new TermQuery(new Term(TEXT_FIELD, "first")), BooleanClause.Occur.SHOULD);
    q1.add(new TermQuery(new Term(TEXT_FIELD, "aid")), BooleanClause.Occur.SHOULD);
    q1.add(new TermQuery(new Term(TEXT_FIELD, "text")), BooleanClause.Occur.SHOULD);
    log(q1);

    // custom query, that should score the same as q1.
    BooleanQuery q2CustomNeutral = new BooleanQuery(true);
    Query q2CustomNeutralInner = new CustomScoreQuery(q1);
    q2CustomNeutral.add(q2CustomNeutralInner, BooleanClause.Occur.SHOULD);
    // a little tricky: we split the boost across an outer BQ and CustomScoreQuery
    // this ensures boosting is correct across all these functions (see LUCENE-4935)
    q2CustomNeutral.setBoost((float)Math.sqrt(dboost));
    q2CustomNeutralInner.setBoost((float)Math.sqrt(dboost));
    log(q2CustomNeutral);

    // custom query, that should (by default) multiply the scores of q1 by that of the field
    CustomScoreQuery q3CustomMul = new CustomScoreQuery(q1, functionQuery);
View Full Code Here

    // this mean that every term boost factor will be multiplied by this
    // number
    float boostFactor = 5;
    mlt.setBoostFactor(boostFactor);
   
    BooleanQuery query = (BooleanQuery) mlt.like(new StringReader(
        "lucene release"), "text");
    List<BooleanClause> clauses = query.clauses();
   
    assertEquals("Expected " + originalValues.size() + " clauses.",
        originalValues.size(), clauses.size());

    for (BooleanClause clause : clauses) {
View Full Code Here

    mlt.setMinDocFreq(1);
    mlt.setMinTermFreq(1);
    mlt.setMinWordLen(1);
    mlt.setFieldNames(new String[] {"text"});
    mlt.setBoost(true);
    BooleanQuery query = (BooleanQuery) mlt.like(new StringReader(
        "lucene release"), "text");
    List<BooleanClause> clauses = query.clauses();

    for (BooleanClause clause : clauses) {
      TermQuery tq = (TermQuery) clause.getQuery();
      originalValues.put(tq.getTerm().text(), tq.getBoost());
    }
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.