use of org.opennms.newts.api.search.Term in project newts by OpenNMS.
the class QueryParserTest method canParseSimpleQuerys.
@Test
public void canParseSimpleQuerys() throws ParseException {
Query query = new TermQuery(new Term("beef"));
assertThat(parse(query), equalTo(query));
assertThat(parse("beef"), equalTo(query));
query = new TermQuery(new Term("meat", "beef"));
assertThat(parse(query), equalTo(query));
assertThat(parse("meat:beef"), equalTo(query));
}
use of org.opennms.newts.api.search.Term in project newts by OpenNMS.
the class QueryParserTest method canEscapeColons.
@Test
public void canEscapeColons() throws ParseException {
Query query = new TermQuery(new Term("meat", "be:ef\\"));
assertThat(parse(query), equalTo((Query) query));
assertThat(parse("meat:be\\:ef\\\\"), equalTo(query));
}
use of org.opennms.newts.api.search.Term in project newts by OpenNMS.
the class QueryParserTest method canParseCompoundQuerys.
@Test
public void canParseCompoundQuerys() throws ParseException {
BooleanQuery query = new BooleanQuery();
query.add(new TermQuery(new Term("meat", "beef")), Operator.OR);
query.add(new TermQuery(new Term("music", "rock")), Operator.OR);
assertThat(parse(query), equalTo((Query) query));
assertThat(parse("meat:beef music:rock"), equalTo((Query) query));
assertThat(parse("meat:beef OR music:rock"), equalTo((Query) query));
assertThat(parse("meat:beef || music:rock"), equalTo((Query) query));
query = new BooleanQuery();
query.add(new TermQuery(new Term("meat", "beef")), Operator.OR);
query.add(new TermQuery(new Term("music", "rock")), Operator.AND);
assertThat(parse(query), equalTo((Query) query));
assertThat(parse("meat:beef AND music:rock"), equalTo((Query) query));
assertThat(parse("meat:beef && music:rock"), equalTo((Query) query));
query = new BooleanQuery();
query.add(new TermQuery(new Term("meat", "beef")), Operator.OR);
query.add(new TermQuery(new Term("music", "rock")), Operator.AND);
query.add(new TermQuery(new Term("sauce")), Operator.OR);
assertThat(parse(query), equalTo((Query) query));
assertThat(parse("meat:beef AND music:rock OR sauce"), equalTo((Query) query));
assertThat(parse("meat:beef && music:rock || sauce"), equalTo((Query) query));
}
use of org.opennms.newts.api.search.Term in project newts by OpenNMS.
the class QueryParserTest method canParseQueriesWithSpecialCharacters.
@Test
public void canParseQueriesWithSpecialCharacters() throws ParseException {
char[] specialCharacters = new char[] { '-', '+', '!', '~', '*', '?', '^', '[', ']', '{', '}' };
for (char specialChar : specialCharacters) {
Query query = new TermQuery(new Term("meat", "ground" + specialChar + "beef"));
assertThat(parse(query), equalTo((Query) query));
assertThat(parse("meat:ground" + specialChar + "beef"), equalTo(query));
}
}
use of org.opennms.newts.api.search.Term in project newts by OpenNMS.
the class QueryParserTest method canParseGroupedQueries.
@Test
public void canParseGroupedQueries() throws ParseException {
BooleanQuery subQuery1 = new BooleanQuery();
subQuery1.add(new TermQuery(new Term("meat", "beef")), Operator.OR);
subQuery1.add(new TermQuery(new Term("music", "rock")), Operator.OR);
BooleanQuery subQuery2 = new BooleanQuery();
subQuery2.add(new TermQuery(new Term("meat", "chicken")), Operator.OR);
subQuery2.add(new TermQuery(new Term("music", "country")), Operator.AND);
TermQuery subQuery3 = new TermQuery(new Term("sauce"));
BooleanQuery query = new BooleanQuery();
query.add(subQuery1, Operator.OR);
query.add(subQuery2, Operator.OR);
query.add(subQuery3, Operator.AND);
assertThat(parse(query), equalTo((Query) query));
assertThat(parse("(meat:beef OR music:rock) OR (meat:chicken AND music:country) AND sauce"), equalTo((Query) query));
}
Aggregations