@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 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); }
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)); } }
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 Various() { StringPath str = user.lastName; List<Predicate> predicates = new ArrayList<Predicate>(); predicates.add(str.between("a", "b")); predicates.add(str.contains("a")); predicates.add(str.containsIgnoreCase("a")); predicates.add(str.endsWith("a")); predicates.add(str.endsWithIgnoreCase("a")); predicates.add(str.eq("a")); predicates.add(str.equalsIgnoreCase("a")); predicates.add(str.goe("a")); predicates.add(str.gt("a")); predicates.add(str.in("a", "b", "c")); predicates.add(str.isEmpty()); predicates.add(str.isNotNull()); predicates.add(str.isNull()); // predicates.add(str.like("a")); predicates.add(str.loe("a")); predicates.add(str.lt("a")); predicates.add(str.matches("a")); predicates.add(str.ne("a")); predicates.add(str.notBetween("a", "b")); predicates.add(str.notIn("a", "b", "c")); predicates.add(str.startsWith("a")); predicates.add(str.startsWithIgnoreCase("a")); for (Predicate predicate : predicates) { where(predicate).count(); where(predicate.not()).count(); } }
@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); }
@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 Ne_and_eq() throws Exception { testQuery(title.ne("house").and(rating.eq("good")), "+(-title:house +*:*) +rating:good", 1); }
@Test public void Eq_and_Eq_not_Does_Not_Find_Results_Because_Second_Expression_Finds_Nothing() throws Exception { testQuery( rating.eq("superb").and(title.eq("house").not()), "+rating:superb +(-title:house +*:*)", 0); }
@Test public void Title_Equals_Not_House() throws Exception { testQuery(title.eq("house").not(), "-title:house +*:*", 1); }
@Test public void Eq_not_Does_Not_Find_Results() throws Exception { testQuery(title.eq("Jurassic Park").not(), "-title:\"jurassic park\" +*:*", 0); }
@Test public void Eq_Phrase_Does_Not_Find_Results_Because_Word_In_Middle() throws Exception { testQuery(title.eq("Jurassic Amusement Park"), "title:\"jurassic amusement park\"", 0); }
@Test public void Eq_Phrase_Should_Not_Find_Results_But_LuceNe_Semantics_Differs_From_Querydsls() throws Exception { testQuery(text.eq("UNIX System"), "text:\"unix system\"", 1); }
@Test @Ignore("Not easily done in Lucene!") public void Publisher_Equals_Empty_String() throws Exception { testQuery(publisher.eq(""), "publisher:", 1); }
@Test public void Multiple_Field_Search_From_Movies() throws Exception { StringPath movie = new StringPath("movie"); testQuery(movie.in("Interview with the Vampire"), "movie:Interview with the Vampire", 1); testQuery(movie.eq("Up in the Air"), "movie:Up in the Air", 1); }
@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); }
@Test public void Eq() throws Exception { testQuery(rating.eq("good"), "rating:good", 1); }
@Test public void Equals_Ignores_Case() throws Exception { testQuery(title.eq("Jurassic"), "title:jurassic", 1); }
@Test public void Eq_with_deep_path() throws Exception { StringPath deepPath = entityPath.get("property1", Object.class).getString("property2"); testQuery(deepPath.eq("good"), "property1.property2:good", 0); }
@Test public void Equals_Empty_String() throws Exception { testQuery(title.eq(""), "title:", 0); }
@Test public void Eq_Phrase() throws Exception { testQuery(title.eq("Jurassic Park"), "title:\"jurassic park\"", 1); }