Search in sources :

Example 1 with Term

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));
}
Also used : TermQuery(org.opennms.newts.api.search.TermQuery) Query(org.opennms.newts.api.search.Query) TermQuery(org.opennms.newts.api.search.TermQuery) BooleanQuery(org.opennms.newts.api.search.BooleanQuery) Term(org.opennms.newts.api.search.Term) Test(org.junit.Test)

Example 2 with Term

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));
}
Also used : TermQuery(org.opennms.newts.api.search.TermQuery) Query(org.opennms.newts.api.search.Query) TermQuery(org.opennms.newts.api.search.TermQuery) BooleanQuery(org.opennms.newts.api.search.BooleanQuery) Term(org.opennms.newts.api.search.Term) Test(org.junit.Test)

Example 3 with Term

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));
}
Also used : BooleanQuery(org.opennms.newts.api.search.BooleanQuery) TermQuery(org.opennms.newts.api.search.TermQuery) Query(org.opennms.newts.api.search.Query) TermQuery(org.opennms.newts.api.search.TermQuery) BooleanQuery(org.opennms.newts.api.search.BooleanQuery) Term(org.opennms.newts.api.search.Term) Test(org.junit.Test)

Example 4 with Term

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));
    }
}
Also used : TermQuery(org.opennms.newts.api.search.TermQuery) Query(org.opennms.newts.api.search.Query) TermQuery(org.opennms.newts.api.search.TermQuery) BooleanQuery(org.opennms.newts.api.search.BooleanQuery) Term(org.opennms.newts.api.search.Term) Test(org.junit.Test)

Example 5 with Term

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));
}
Also used : BooleanQuery(org.opennms.newts.api.search.BooleanQuery) TermQuery(org.opennms.newts.api.search.TermQuery) Query(org.opennms.newts.api.search.Query) TermQuery(org.opennms.newts.api.search.TermQuery) BooleanQuery(org.opennms.newts.api.search.BooleanQuery) Term(org.opennms.newts.api.search.Term) Test(org.junit.Test)

Aggregations

BooleanQuery (org.opennms.newts.api.search.BooleanQuery)7 Term (org.opennms.newts.api.search.Term)7 TermQuery (org.opennms.newts.api.search.TermQuery)7 Test (org.junit.Test)6 Query (org.opennms.newts.api.search.Query)5 MetricRegistry (com.codahale.metrics.MetricRegistry)1 Context (org.opennms.newts.api.Context)1 Resource (org.opennms.newts.api.Resource)1 Sample (org.opennms.newts.api.Sample)1 Indexer (org.opennms.newts.api.search.Indexer)1 QueryBuilder (org.opennms.newts.api.search.QueryBuilder)1 Result (org.opennms.newts.api.search.SearchResults.Result)1 CassandraSession (org.opennms.newts.cassandra.CassandraSession)1 ContextConfigurations (org.opennms.newts.cassandra.ContextConfigurations)1