@Test(expected = UnsupportedOperationException.class)
 public void Title_Equals_Ignore_Case_Negation_Or_Rating_Equals_Ignore_Case() throws Exception {
   testQuery(
       title.equalsIgnoreCase("House").not().or(rating.equalsIgnoreCase("Good")),
       "-title:house rating:good",
       1);
 }
 @Test
 public void Eq_and_Eq_and_eq() throws Exception {
   testQuery(
       title.eq("Jurassic Park").and(year.eq(1990)).and(author.eq("Michael Crichton")),
       "+(+title:\"jurassic park\" +year:" + YEAR_PREFIX_CODED + ") +author:\"michael crichton\"",
       1);
 }
 @Test
 public void Precedence2() {
   StringPath str = cat.name;
   Predicate where =
       str.like("Bob%").and(str.like("%ob123").or(str.like("Ruth%"))).and(str.like("%uth123"));
   assertEquals(0l, query().from(cat).where(where).count());
 }
Esempio n. 4
0
 private List<Predicate> getValuePredicate(StoredQueryParam param, StringPath valuePath) {
   List<Predicate> predicates = new ArrayList<Predicate>();
   List<String> values;
   for (int i = 0, len = param.getNumberOfANDElements(); i < len; i++) {
     values =
         param.isMultiValue() ? param.getMultiValues(i) : Arrays.asList(param.getStringValue());
     BooleanBuilder predicate = new BooleanBuilder();
     List<String> eqValues = new ArrayList<String>();
     for (String v : values) {
       if (v.indexOf('%') != -1 || v.indexOf('_') != -1) {
         predicate.or(valuePath.like(v));
       } else {
         eqValues.add(v);
       }
     }
     if (eqValues.size() > 0) {
       if (eqValues.size() > 1) {
         predicate.or(valuePath.in(eqValues));
       } else {
         predicate.or(valuePath.eq(eqValues.get(0)));
       }
     }
     predicates.add(predicate);
   }
   return predicates;
 }
 @Test
 public void Eq_or_Eq_and_Eq_Does_Not_Find_Results() throws Exception {
   testQuery(
       title.eq("jeeves").or(rating.eq("superb")).and(author.eq("michael crichton")),
       "+(title:jeeves rating:superb) +author:\"michael crichton\"",
       0);
 }
 @Test
 public void Nothing_Found_With_Not_Equals_Or_Equals() throws Exception {
   testQuery(
       title.ne("jurassic park").or(rating.eq("lousy")),
       "(-title:\"jurassic park\" +*:*) rating:lousy",
       0);
 }
  @Test
  public void QueryElement() throws Exception {
    Query query1 = serializer.toQuery(author.like("Michael"), metadata);
    Query query2 = serializer.toQuery(text.like("Text"), metadata);

    BooleanExpression query =
        BooleanExpression.anyOf(new QueryElement(query1), new QueryElement(query2));
    testQuery(query, "author:michael text:text", 1);
  }
 @Test(expected = UnsupportedOperationException.class)
 public void Equals_Ignore_Case_And_Or() throws Exception {
   testQuery(
       title
           .equalsIgnoreCase("Jurassic Park")
           .and(rating.equalsIgnoreCase("Bad"))
           .or(author.equalsIgnoreCase("Michael Crichton")),
       "(+title:\"jurassic park\" +rating:bad) author:\"michael crichton\"",
       1);
 }
Esempio n. 9
0
  @Test
  public void RegexToLike() {
    assertEquals("%", like(ConstantImpl.create(".*")));
    assertEquals("_", like(ConstantImpl.create(".")));

    StringPath path = new StringPath("path");
    assertEquals("path + %", like(path.append(".*")));
    assertEquals("% + path", like(path.prepend(".*")));
    assertEquals("path + _", like(path.append(".")));
    assertEquals("_ + path", like(path.prepend(".")));
  }
Esempio n. 10
0
  @Test
  public void LikeToRegex() {
    assertEquals(".*", regex(ConstantImpl.create("%")));
    assertEquals(".", regex(ConstantImpl.create("_")));

    StringPath path = new StringPath("path");
    assertEquals("path + .*", regex(path.append("%")));
    assertEquals(".* + path", regex(path.prepend("%")));
    assertEquals("path + .", regex(path.append("_")));
    assertEquals(". + path", regex(path.prepend("_")));
  }
Esempio n. 11
0
 protected void addStatusMatch(
     BooleanBuilder builder, StringPath status, StoredQueryParam statusParam) {
   List<String> stati = statusParam.getMultiValues(0);
   if (stati == null) {
     builder.and(status.eq(statusParam.getStringValue()));
   } else if (stati.size() == 1) {
     builder.and(status.eq(stati.get(0)));
   } else if (stati.size() > 1) {
     builder.and(status.in(stati));
   }
 }
Esempio n. 12
0
 @Test(expected = UnsupportedOperationException.class)
 public void Title_Equals_Ignore_Case_Or_Year_Equals() throws Exception {
   testQuery(
       title.equalsIgnoreCase("House").or(year.eq(1990)),
       "title:house year:" + YEAR_PREFIX_CODED,
       1);
 }
Esempio n. 13
0
 @Test
 public void Eq_and_eq() throws Exception {
   testQuery(
       title.eq("Jurassic Park").and(year.eq(1990)),
       "+title:\"jurassic park\" +year:" + YEAR_PREFIX_CODED,
       1);
 }
Esempio n. 14
0
 @Test
 public void Goe_Not_Found() throws Exception {
   testQuery(rating.goe("Hood"), "rating:[hood TO *]", 0);
 }
Esempio n. 15
0
 @Test
 public void Goe_Equal() throws Exception {
   testQuery(rating.goe("Good"), "rating:[good TO *]", 1);
 }
Esempio n. 16
0
 @Test
 public void Goe() throws Exception {
   testQuery(rating.goe("Bad"), "rating:[bad TO *]", 1);
 }
Esempio n. 17
0
 @Test
 public void Gt_Not_In_Range_Because_Equal() throws Exception {
   testQuery(rating.gt("Good"), "rating:{good TO *}", 0);
 }
Esempio n. 18
0
 @Test
 public void Gt() throws Exception {
   testQuery(rating.gt("Bad"), "rating:{bad TO *}", 1);
 }
Esempio n. 19
0
 @Test
 public void Loe_Not_Found() throws Exception {
   testQuery(rating.loe("Bad"), "rating:[* TO bad]", 0);
 }
Esempio n. 20
0
 @Test
 public void Loe_Equal() throws Exception {
   testQuery(rating.loe("Good"), "rating:[* TO good]", 1);
 }
Esempio n. 21
0
 @Test
 public void Loe() throws Exception {
   testQuery(rating.loe("Superb"), "rating:[* TO superb]", 1);
 }
Esempio n. 22
0
 @Test
 public void Ends_With_Empty_String() throws Exception {
   testQuery(title.endsWith(""), "title:*", 1);
 }
Esempio n. 23
0
 @Test
 public void Contains_Empty_String() throws Exception {
   testQuery(title.contains(""), "title:**", 1);
 }
Esempio n. 24
0
 @Test
 public void Equals_Empty_String() throws Exception {
   testQuery(title.eq(""), "title:", 0);
 }
Esempio n. 25
0
 @Test
 public void Not_Equals_Empty_String() throws Exception {
   testQuery(title.ne(""), "-title: +*:*", 1);
 }
Esempio n. 26
0
 @Test
 public void In() throws Exception {
   testQuery(title.in(Arrays.asList("jurassic", "park")), "title:jurassic title:park", 1);
   testQuery(title.in("jurassic", "park"), "title:jurassic title:park", 1);
   testQuery(title.eq("jurassic").or(title.eq("park")), "title:jurassic title:park", 1);
 }
Esempio n. 27
0
 @Test
 public void Like_Empty_String() throws Exception {
   testQuery(title.like(""), "title:", 0);
 }
Esempio n. 28
0
 @Test
 public void Lt() throws Exception {
   testQuery(rating.lt("Superb"), "rating:{* TO superb}", 1);
 }
Esempio n. 29
0
 @Test
 public void Between_Empty_Strings() throws Exception {
   testQuery(title.between("", ""), "title:[ TO ]", 0);
 }
Esempio n. 30
0
 @Test
 public void Lt_Not_In_Range_Because_Equal() throws Exception {
   testQuery(rating.lt("Good"), "rating:{* TO good}", 0);
 }