Package org.apache.lucene.search

Examples of org.apache.lucene.search.BooleanFilter


  {
    this.factory=factory;
  }

  public Filter getFilter(Element e) throws ParserException {
    BooleanFilter bf=new BooleanFilter();
    NodeList nl = e.getChildNodes();
   
    for(int i=0;i<nl.getLength();i++)
    {
      Node node = nl.item(i);
      if(node.getNodeName().equals("Clause"))
      {
        Element clauseElem=(Element) node;
        BooleanClause.Occur occurs=BooleanQueryBuilder.getOccursValue(clauseElem);
     
         Element clauseFilter=DOMUtils.getFirstChildOrFail(clauseElem);
         Filter f=factory.getFilter(clauseFilter);
         bf.add(new FilterClause(f,occurs));
      }
    }
   
    return bf;
  }
View Full Code Here


    return tf;
  }
   
  public void testShould() throws Throwable
  {
    BooleanFilter booleanFilter = new BooleanFilter();
    booleanFilter.add(new FilterClause(getTermsFilter("price","030"),BooleanClause.Occur.SHOULD));
    BitSet bits = booleanFilter.bits(reader);
    assertEquals("Should retrieves only 1 doc",1,bits.cardinality());
  }
View Full Code Here

    assertEquals("Should retrieves only 1 doc",1,bits.cardinality());
  }
 
  public void testShoulds() throws Throwable
  {
    BooleanFilter booleanFilter = new BooleanFilter();
    booleanFilter.add(new FilterClause(getRangeFilter("price","010", "020"),BooleanClause.Occur.SHOULD));
    booleanFilter.add(new FilterClause(getRangeFilter("price","020", "030"),BooleanClause.Occur.SHOULD));
    BitSet bits = booleanFilter.bits(reader);
    assertEquals("Shoulds are Ored together",5,bits.cardinality());
  }
View Full Code Here

    BitSet bits = booleanFilter.bits(reader);
    assertEquals("Shoulds are Ored together",5,bits.cardinality());
  }
  public void testShouldsAndMustNot() throws Throwable
  {
    BooleanFilter booleanFilter = new BooleanFilter();
    booleanFilter.add(new FilterClause(getRangeFilter("price","010", "020"),BooleanClause.Occur.SHOULD));
    booleanFilter.add(new FilterClause(getRangeFilter("price","020", "030"),BooleanClause.Occur.SHOULD));
    booleanFilter.add(new FilterClause(getTermsFilter("inStock", "N"),BooleanClause.Occur.MUST_NOT));
    BitSet bits = booleanFilter.bits(reader);
    assertEquals("Shoulds Ored but AndNot",4,bits.cardinality());

    booleanFilter.add(new FilterClause(getTermsFilter("inStock", "Maybe"),BooleanClause.Occur.MUST_NOT));
    bits = booleanFilter.bits(reader);
    assertEquals("Shoulds Ored but AndNots",3,bits.cardinality());
   
  }
View Full Code Here

    assertEquals("Shoulds Ored but AndNots",3,bits.cardinality());
   
  }
  public void testShouldsAndMust() throws Throwable
  {
    BooleanFilter booleanFilter = new BooleanFilter();
    booleanFilter.add(new FilterClause(getRangeFilter("price","010", "020"),BooleanClause.Occur.SHOULD));
    booleanFilter.add(new FilterClause(getRangeFilter("price","020", "030"),BooleanClause.Occur.SHOULD));
    booleanFilter.add(new FilterClause(getTermsFilter("accessRights", "admin"),BooleanClause.Occur.MUST));
    BitSet bits = booleanFilter.bits(reader);
    assertEquals("Shoulds Ored but MUST",3,bits.cardinality());
  }
View Full Code Here

    BitSet bits = booleanFilter.bits(reader);
    assertEquals("Shoulds Ored but MUST",3,bits.cardinality());
  }
  public void testShouldsAndMusts() throws Throwable
  {
    BooleanFilter booleanFilter = new BooleanFilter();
    booleanFilter.add(new FilterClause(getRangeFilter("price","010", "020"),BooleanClause.Occur.SHOULD));
    booleanFilter.add(new FilterClause(getRangeFilter("price","020", "030"),BooleanClause.Occur.SHOULD));
    booleanFilter.add(new FilterClause(getTermsFilter("accessRights", "admin"),BooleanClause.Occur.MUST));
    booleanFilter.add(new FilterClause(getRangeFilter("date","20040101", "20041231"),BooleanClause.Occur.MUST));
    BitSet bits = booleanFilter.bits(reader);
    assertEquals("Shoulds Ored but MUSTs ANDED",1,bits.cardinality());
  }
View Full Code Here

    BitSet bits = booleanFilter.bits(reader);
    assertEquals("Shoulds Ored but MUSTs ANDED",1,bits.cardinality());
  }
  public void testShouldsAndMustsAndMustNot() throws Throwable
  {
    BooleanFilter booleanFilter = new BooleanFilter();
    booleanFilter.add(new FilterClause(getRangeFilter("price","030", "040"),BooleanClause.Occur.SHOULD));
    booleanFilter.add(new FilterClause(getTermsFilter("accessRights", "admin"),BooleanClause.Occur.MUST));
    booleanFilter.add(new FilterClause(getRangeFilter("date","20050101", "20051231"),BooleanClause.Occur.MUST));
    booleanFilter.add(new FilterClause(getTermsFilter("inStock","N"),BooleanClause.Occur.MUST_NOT));
    BitSet bits = booleanFilter.bits(reader);
    assertEquals("Shoulds Ored but MUSTs ANDED and MustNot",0,bits.cardinality());
  }
View Full Code Here

    assertEquals("Shoulds Ored but MUSTs ANDED and MustNot",0,bits.cardinality());
  }
 
  public void testJustMust() throws Throwable
  {
    BooleanFilter booleanFilter = new BooleanFilter();
    booleanFilter.add(new FilterClause(getTermsFilter("accessRights", "admin"),BooleanClause.Occur.MUST));
    BitSet bits = booleanFilter.bits(reader);
    assertEquals("MUST",3,bits.cardinality());
  }
View Full Code Here

    BitSet bits = booleanFilter.bits(reader);
    assertEquals("MUST",3,bits.cardinality());
  }
  public void testJustMustNot() throws Throwable
  {
    BooleanFilter booleanFilter = new BooleanFilter();
    booleanFilter.add(new FilterClause(getTermsFilter("inStock","N"),BooleanClause.Occur.MUST_NOT));
    BitSet bits = booleanFilter.bits(reader);
    assertEquals("MUST_NOT",4,bits.cardinality());
  }
View Full Code Here

    BitSet bits = booleanFilter.bits(reader);
    assertEquals("MUST_NOT",4,bits.cardinality());
  }
  public void testMustAndMustNot() throws Throwable
  {
    BooleanFilter booleanFilter = new BooleanFilter();
    booleanFilter.add(new FilterClause(getTermsFilter("inStock","N"),BooleanClause.Occur.MUST));
    booleanFilter.add(new FilterClause(getTermsFilter("price","030"),BooleanClause.Occur.MUST_NOT));
    BitSet bits = booleanFilter.bits(reader);
    assertEquals("MUST_NOT wins over MUST for same docs",0,bits.cardinality());
  }
View Full Code Here

TOP

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

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.