@Test public void testQueryEmpty() { Schema schema = schema().build(); BooleanCondition condition = bool().boost(0.4).build(); BooleanQuery query = (BooleanQuery) condition.query(schema); assertEquals(0, query.getClauses().length); assertEquals(0.4f, query.getBoost(), 0f); }
@Test public void testQueryPureNot() { Schema schema = schema().mapper("name", stringMapper()).build(); BooleanCondition condition = bool().not(match("name", "jonathan")).boost(0.4).build(); BooleanQuery query = (BooleanQuery) condition.query(schema); assertEquals(2, query.getClauses().length); assertEquals(0.4f, query.getBoost(), 0f); }
@Test public void testToString() { BooleanCondition condition = bool() .must(match("name", "jonathan"), match("age", 18)) .should(match("color", "green")) .not(match("country", "england")) .boost(0.5f) .build(); assertEquals( "BooleanCondition{boost=0.5, " + "must=[MatchCondition{boost=1.0, field=name, value=jonathan}, " + "MatchCondition{boost=1.0, field=age, value=18}], " + "should=[MatchCondition{boost=1.0, field=color, value=green}], " + "not=[MatchCondition{boost=1.0, field=country, value=england}]}", condition.toString()); }
@Test public void testQuery() { Schema schema = schema() .mapper("name", stringMapper()) .mapper("color", stringMapper()) .mapper("country", stringMapper()) .mapper("age", integerMapper()) .defaultAnalyzer("default") .build(); BooleanCondition condition = bool() .must(match("name", "jonathan"), range("age").lower(18).includeLower(true)) .should(match("color", "green"), match("color", "blue")) .not(match("country", "england")) .boost(0.4f) .build(); BooleanQuery query = (BooleanQuery) condition.query(schema); assertEquals(5, query.getClauses().length); assertEquals(0.4f, query.getBoost(), 0f); }