Package org.apache.lucene.search

Examples of org.apache.lucene.search.BooleanClause


  protected Query getPrefixQuery(String field, String termStr) throws ParseException
  {
    if (field == null) {
      List clauses = new ArrayList();
      for (int i = 0; i < fields.length; i++) {
        clauses.add(new BooleanClause(getPrefixQuery(fields[i], termStr),
            BooleanClause.Occur.SHOULD));
      }
      return getBooleanQuery(clauses, true);
    }
    return super.getPrefixQuery(field, termStr);
View Full Code Here


  protected Query getWildcardQuery(String field, String termStr) throws ParseException {
    if (field == null) {
      List clauses = new ArrayList();
      for (int i = 0; i < fields.length; i++) {
        clauses.add(new BooleanClause(getWildcardQuery(fields[i], termStr),
            BooleanClause.Occur.SHOULD));
      }
      return getBooleanQuery(clauses, true);
    }
    return super.getWildcardQuery(field, termStr);
View Full Code Here

  protected Query getRangeQuery(String field, String part1, String part2, boolean inclusive) throws ParseException {
    if (field == null) {
      List clauses = new ArrayList();
      for (int i = 0; i < fields.length; i++) {
        clauses.add(new BooleanClause(getRangeQuery(fields[i], part1, part2, inclusive),
            BooleanClause.Occur.SHOULD));
      }
      return getBooleanQuery(clauses, true);
    }
    return super.getRangeQuery(field, part1, part2, inclusive);
View Full Code Here

    boolean required, prohibited;

    // If this term is introduced by AND, make the preceding term required,
    // unless it's already prohibited
    if (clauses.size() > 0 && conj == CONJ_AND) {
      BooleanClause c = (BooleanClause) clauses.get(clauses.size()-1);
      if (!c.isProhibited())
        c.setOccur(BooleanClause.Occur.MUST);
    }

    if (clauses.size() > 0 && operator == AND_OPERATOR && conj == CONJ_OR) {
      // If this term is introduced by OR, make the preceding term optional,
      // unless it's prohibited (that means we leave -a OR b but +a OR b-->a OR b)
      // notice if the input is a OR b, first term is parsed as required; without
      // this modification a OR b would parsed as +a OR b
      BooleanClause c = (BooleanClause) clauses.get(clauses.size()-1);
      if (!c.isProhibited())
        c.setOccur(BooleanClause.Occur.SHOULD);
    }

    // We might have been passed a null query; the term might have been
    // filtered away by the analyzer.
    if (q == null)
View Full Code Here

  * @param q sub query
  * @param occur how this clause should occur when matching documents
  * @return new BooleanClause instance
  */
  protected BooleanClause newBooleanClause(Query q, BooleanClause.Occur occur) {
    return new BooleanClause(q, occur);
  }
View Full Code Here

  public void testNoPayload() throws Exception {
    PayloadTermQuery q1 = new PayloadTermQuery(new Term(PayloadHelper.NO_PAYLOAD_FIELD, "zero"),
            new MaxPayloadFunction());
    PayloadTermQuery q2 = new PayloadTermQuery(new Term(PayloadHelper.NO_PAYLOAD_FIELD, "foo"),
            new MaxPayloadFunction());
    BooleanClause c1 = new BooleanClause(q1, BooleanClause.Occur.MUST);
    BooleanClause c2 = new BooleanClause(q2, BooleanClause.Occur.MUST_NOT);
    BooleanQuery query = new BooleanQuery();
    query.add(c1);
    query.add(c2);
    TopDocs hits = searcher.search(query, null, 100);
    assertTrue("hits is null and it shouldn't be", hits != null);
View Full Code Here

   
    assertEquals("Expected " + originalValues.size() + " clauses.",
        originalValues.size(), clauses.size());
   
    for (int i = 0; i < clauses.size(); i++) {
      BooleanClause clause = clauses.get(i);
      TermQuery tq = (TermQuery) clause.getQuery();
      Float termBoost = originalValues.get(tq.getTerm().text());
      assertNotNull("Expected term " + tq.getTerm().text(), termBoost);
     
      float totalBoost = termBoost.floatValue() * boostFactor;
      assertEquals("Expected boost of " + totalBoost + " for term '"
View Full Code Here

    BooleanQuery query = (BooleanQuery) mlt.like(new StringReader(
        "lucene release"));
    List<BooleanClause> clauses = query.clauses();
   
    for (int i = 0; i < clauses.size(); i++) {
      BooleanClause clause = clauses.get(i);
      TermQuery tq = (TermQuery) clause.getQuery();
      originalValues.put(tq.getTerm().text(), Float.valueOf(tq.getBoost()));
    }
    return originalValues;
  }
View Full Code Here

      assertTrue("expected instance of BooleanQuery but was "
          + query.getClass(), query instanceof BooleanQuery);
      BooleanQuery bquery = (BooleanQuery) query;
      BooleanClause[] clauses = bquery.getClauses();
      assertEquals(2, clauses.length);
      BooleanClause booleanClause = clauses[0];
      query = booleanClause.getQuery();
      assertTrue("expected instance of TermQuery but was " + query.getClass(),
          query instanceof TermQuery);
      TermQuery tquery = (TermQuery) query;
      assertEquals("aField", tquery.getTerm()
          .field());
      assertEquals("foo", tquery.getTerm().text());

      booleanClause = clauses[1];
      query = booleanClause.getQuery();
      assertTrue("expected instance of TermQuery but was " + query.getClass(),
          query instanceof TermQuery);
      tquery = (TermQuery) query;
      assertEquals("field", tquery.getTerm().field());
      assertEquals("bar", tquery.getTerm().text());
View Full Code Here

            versionQ = getIndexer().constructQuery( MAVEN.VERSION, new SourcedSearchExpression( v ) );
        }

        BooleanQuery q = new BooleanQuery();

        q.add( new BooleanClause( groupIdQ, BooleanClause.Occur.MUST ) );

        if ( artifactIdQ != null )
        {
            q.add( new BooleanClause( artifactIdQ, BooleanClause.Occur.MUST ) );
        }

        if ( versionQ != null )
        {
            q.add( new BooleanClause( versionQ, BooleanClause.Occur.MUST ) );
        }

        IteratorSearchRequest searchRequest = new IteratorSearchRequest( q, request.getArtifactInfoFilter() );

        searchRequest.getContexts().add( request.getIndexingContext() );
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.