public void testAllOptional() throws Exception {

    BooleanQuery q = new BooleanQuery();
    for (int i = 1; i <= 4; i++) {
      q.add(new TermQuery(new Term("data", "" + i)), BooleanClause.Occur.SHOULD); // false, false);
    }
    q.setMinimumNumberShouldMatch(2); // match at least two of 4
    verifyNrHits(q, 2);
  }
Esempio n. 2
0
 @Override
 public Query apply(Function input, Context context) {
   assert input != null;
   BooleanQuery query = new BooleanQuery();
   query.setMinimumNumberShouldMatch(1);
   for (Symbol symbol : input.arguments()) {
     query.add(process(symbol, context), BooleanClause.Occur.SHOULD);
   }
   return query;
 }
  public void testNoOptionalButMin2() throws Exception {

    /* one required, no optional */
    BooleanQuery q = new BooleanQuery();
    q.add(new TermQuery(new Term("all", "all")), BooleanClause.Occur.MUST); // true,  false);

    q.setMinimumNumberShouldMatch(1); // 1 of 0 optional

    verifyNrHits(q, 0);
  }
  public void testBQ20() throws Exception {
    BooleanQuery q = new BooleanQuery();
    q.setMinimumNumberShouldMatch(2);
    q.add(new TermQuery(new Term(FIELD, "QQQQQ")), BooleanClause.Occur.SHOULD);
    q.add(new TermQuery(new Term(FIELD, "yy")), BooleanClause.Occur.SHOULD);
    q.add(new TermQuery(new Term(FIELD, "zz")), BooleanClause.Occur.SHOULD);
    q.add(new TermQuery(new Term(FIELD, "w5")), BooleanClause.Occur.SHOULD);
    q.add(new TermQuery(new Term(FIELD, "w4")), BooleanClause.Occur.SHOULD);

    qtest(q, new int[] {0, 3});
  }
Esempio n. 5
0
 @Override
 protected Query applyArrayLiteral(Reference reference, Literal arrayLiteral, Context context)
     throws IOException {
   // col like ANY (['a', 'b']) --> or(like(col, 'a'), like(col, 'b'))
   BooleanQuery booleanQuery = new BooleanQuery();
   booleanQuery.setMinimumNumberShouldMatch(1);
   for (Object value : toIterable(arrayLiteral.value())) {
     booleanQuery.add(
         likeQuery.toQuery(reference, value, context), BooleanClause.Occur.SHOULD);
   }
   return booleanQuery;
 }
  public void testOneOptionalEqualToMin() throws Exception {

    /* two required, one optional */
    BooleanQuery q = new BooleanQuery();
    q.add(new TermQuery(new Term("all", "all")), BooleanClause.Occur.MUST); // true,  false);
    q.add(new TermQuery(new Term("data", "3")), BooleanClause.Occur.SHOULD); // false, false);
    q.add(new TermQuery(new Term("data", "2")), BooleanClause.Occur.MUST); // true,  false);

    q.setMinimumNumberShouldMatch(1); // 1 of 1 optional

    verifyNrHits(q, 1);
  }
Esempio n. 7
0
 @Override
 protected Query applyArrayLiteral(Reference reference, Literal arrayLiteral, Context context)
     throws IOException {
   // col < ANY ([1,2,3]) --> or(col<1, col<2, col<3)
   BooleanQuery booleanQuery = new BooleanQuery();
   booleanQuery.setMinimumNumberShouldMatch(1);
   for (Object value : toIterable(arrayLiteral.value())) {
     booleanQuery.add(
         inverseRangeQuery.toQuery(reference, reference.valueType(), value),
         BooleanClause.Occur.SHOULD);
   }
   return booleanQuery;
 }
  public void testOneProhibAndSomeOptional() throws Exception {

    /* one prohibited, some optional */
    BooleanQuery q = new BooleanQuery();
    q.add(new TermQuery(new Term("data", "1")), BooleanClause.Occur.SHOULD); // false, false);
    q.add(new TermQuery(new Term("data", "2")), BooleanClause.Occur.SHOULD); // false, false);
    q.add(new TermQuery(new Term("data", "3")), BooleanClause.Occur.MUST_NOT); // false, true );
    q.add(new TermQuery(new Term("data", "4")), BooleanClause.Occur.SHOULD); // false, false);

    q.setMinimumNumberShouldMatch(2); // 2 of 3 optional

    verifyNrHits(q, 1);
  }
  public void testOneReqAndSomeOptional() throws Exception {

    /* one required, some optional */
    BooleanQuery q = new BooleanQuery();
    q.add(new TermQuery(new Term("all", "all")), BooleanClause.Occur.MUST); // true,  false);
    q.add(new TermQuery(new Term("data", "5")), BooleanClause.Occur.SHOULD); // false, false);
    q.add(new TermQuery(new Term("data", "4")), BooleanClause.Occur.SHOULD); // false, false);
    q.add(new TermQuery(new Term("data", "3")), BooleanClause.Occur.SHOULD); // false, false);

    q.setMinimumNumberShouldMatch(2); // 2 of 3 optional

    verifyNrHits(q, 5);
  }
Esempio n. 10
0
      @Override
      protected Query applyArrayReference(
          Reference arrayReference, Literal literal, Context context) throws IOException {
        // 1 != any ( col ) -->  gt 1 or lt 1
        String columnName = arrayReference.info().ident().columnIdent().fqn();
        Object value = literal.value();

        QueryBuilderHelper builder = QueryBuilderHelper.forType(arrayReference.valueType());
        BooleanQuery query = new BooleanQuery();
        query.setMinimumNumberShouldMatch(1);
        query.add(
            builder.rangeQuery(columnName, value, null, false, false), BooleanClause.Occur.SHOULD);
        query.add(
            builder.rangeQuery(columnName, null, value, false, false), BooleanClause.Occur.SHOULD);
        return query;
      }
  public void testSomeReqOneProhibAndSomeOptional() throws Exception {

    /* two required, one prohibited, some optional */
    BooleanQuery q = new BooleanQuery();
    q.add(new TermQuery(new Term("all", "all")), BooleanClause.Occur.MUST); // true,  false);
    q.add(new TermQuery(new Term("data", "6")), BooleanClause.Occur.MUST); // true,  false);
    q.add(new TermQuery(new Term("data", "5")), BooleanClause.Occur.SHOULD); // false, false);
    q.add(new TermQuery(new Term("data", "4")), BooleanClause.Occur.SHOULD); // false, false);
    q.add(new TermQuery(new Term("data", "3")), BooleanClause.Occur.MUST_NOT); // false, true );
    q.add(new TermQuery(new Term("data", "2")), BooleanClause.Occur.SHOULD); // false, false);
    q.add(new TermQuery(new Term("data", "1")), BooleanClause.Occur.SHOULD); // false, false);

    q.setMinimumNumberShouldMatch(3); // 3 of 4 optional

    verifyNrHits(q, 1);
  }
  public void testMinHigherThenNumOptional() throws Exception {

    /* two required, two prohibited, some optional */
    BooleanQuery q = new BooleanQuery();
    q.add(new TermQuery(new Term("all", "all")), BooleanClause.Occur.MUST); // true,  false);
    q.add(new TermQuery(new Term("data", "6")), BooleanClause.Occur.MUST); // true,  false);
    q.add(new TermQuery(new Term("data", "5")), BooleanClause.Occur.SHOULD); // false, false);
    q.add(new TermQuery(new Term("data", "4")), BooleanClause.Occur.SHOULD); // false, false);
    q.add(new TermQuery(new Term("data", "3")), BooleanClause.Occur.MUST_NOT); // false, true );
    q.add(new TermQuery(new Term("data", "2")), BooleanClause.Occur.SHOULD); // false, false);
    q.add(new TermQuery(new Term("data", "1")), BooleanClause.Occur.SHOULD); // false, false);
    q.add(new TermQuery(new Term("data", "C")), BooleanClause.Occur.MUST_NOT); // false, true );

    q.setMinimumNumberShouldMatch(90); // 90 of 4 optional ?!?!?!

    verifyNrHits(q, 0);
  }