/** * Create a query that allows for boolean combinations of other queries * @param minimumShouldMatch the minimum number of should clauses to match * @return the query * @since 1.1.0 */ public static JsonObject boolQuery(int minimumShouldMatch) { JsonObject r = boolQuery(); r.getJsonObject("bool") .put("minimum_should_match", 1); return r; }
/** * Enter a logical expression * @param l the logical operation */ private void enterLogical(Logical l) { JsonObject bqb = boolQuery(1); combine(bqb); result.push(bqb); currentLogical.push(l); }
/** * 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 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); }
JsonObject bqb = boolQuery(1); Logical l = currentLogical.peek(); switch (l) {
/** * 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); } }
JsonObject bqb = boolQuery(1); for (QueryCompiler f : queryCompilers) { MatchPriority mp = f.getQueryPriority(str);
JsonObject cq = ElasticsearchQueryHelper.termQuery("correlationId", value); if (result != null) { JsonObject bool = ElasticsearchQueryHelper.boolQuery(1); ElasticsearchQueryHelper.boolAddShould(bool, result); ElasticsearchQueryHelper.boolAddShould(bool, cq);