boolAddShould(qi, termQuery("path", path)); boolAddShould(qi, prefixQuery("path", prefix)); filter.add(qi); boolAddShould(qr, qb); filter.forEach(q -> boolAddMust(qr, q));
switch (l) { case OR: boolAddShould(b, other); break; case AND: switch (l) { case OR: boolAddShould(bqb, b); boolAddShould(bqb, other); break; case AND:
/** * Test that {@link ElasticsearchQueryHelper#boolAddShould(JsonObject, JsonObject)} * does not add duplicated queries */ @Test public void testBoolAddShouldNoDuplicate() { JsonObject s = new JsonObject() .put("term", new JsonObject() .put("tags", "Fraunhofer IGD")); JsonObject q = boolQuery(); boolAddShould(q, s); boolAddShould(q, s); JsonObject expected = new JsonObject() .put("bool", new JsonObject() .put("should", s)); assertEquals(expected, q); }
/** * Test {@link ElasticsearchQueryHelper#boolAddShould(JsonObject, JsonObject)} */ @Test public void testBoolAddShould() { JsonObject s = new JsonObject() .put("term", new JsonObject() .put("tags", "Fraunhofer IGD")); JsonObject q = boolQuery(); boolAddShould(q, s); JsonObject expected = new JsonObject() .put("bool", new JsonObject() .put("should", s)); assertEquals(expected, q); }
/** * Test that {@link ElasticsearchQueryHelper#boolAddShould(JsonObject, JsonObject)} * does not add queries specified multiple times */ @Test public void testBoolAddShouldNoMultiple() { JsonObject s = new JsonObject() .put("term", new JsonObject() .put("tags", "Fraunhofer IGD")); JsonObject s2 = new JsonObject() .put("term", new JsonObject() .put("tags", "Elvis")); JsonObject q = boolQuery(); boolAddShould(q, s); boolAddShould(q, s2); boolAddShould(q, s); boolAddShould(q, s); JsonObject expected = new JsonObject() .put("bool", new JsonObject() .put("should", new JsonArray() .add(s) .add(s2))); assertEquals(expected, q); } }
return f.compileQuery(str); case SHOULD: boolAddShould(bqb, f.compileQuery(str)); break; case MUST:
if (result != null) { JsonObject bool = ElasticsearchQueryHelper.boolQuery(1); ElasticsearchQueryHelper.boolAddShould(bool, result); ElasticsearchQueryHelper.boolAddShould(bool, cq); result = bool; } else {