Search in sources :

Example 6 with PrimitiveStatement

use of org.apache.cxf.jaxrs.ext.search.PrimitiveStatement in project cxf by apache.

the class LuceneQueryVisitor method visit.

public void visit(SearchCondition<T> sc) {
    if (state.get() == null) {
        reset();
    }
    PrimitiveStatement statement = sc.getStatement();
    if (statement != null) {
        if (statement.getProperty() != null) {
            state.get().peek().add(buildSimpleQuery(sc.getConditionType(), statement.getProperty(), statement.getValue()));
        }
    } else {
        state.get().push(new ArrayList<>());
        for (SearchCondition<T> condition : sc.getSearchConditions()) {
            condition.accept(this);
        }
        boolean orCondition = sc.getConditionType() == ConditionType.OR;
        List<Query> queries = state.get().pop();
        state.get().peek().add(createCompositeQuery(queries, orCondition));
    }
}
Also used : PrimitiveStatement(org.apache.cxf.jaxrs.ext.search.PrimitiveStatement) Query(org.apache.lucene.search.Query) NumericRangeQuery(org.apache.lucene.search.NumericRangeQuery) PhraseQuery(org.apache.lucene.search.PhraseQuery) WildcardQuery(org.apache.lucene.search.WildcardQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery)

Example 7 with PrimitiveStatement

use of org.apache.cxf.jaxrs.ext.search.PrimitiveStatement in project cxf by apache.

the class FiqlParserTest method testParseComplex2.

@Test
public void testParseComplex2() throws SearchParseException {
    SearchCondition<Condition> filter = parser.parse("name==ami*,level=gt=10");
    assertEquals(ConditionType.OR, filter.getConditionType());
    List<SearchCondition<Condition>> conditions = filter.getSearchConditions();
    assertEquals(2, conditions.size());
    PrimitiveStatement st1 = conditions.get(0).getStatement();
    PrimitiveStatement st2 = conditions.get(1).getStatement();
    assertTrue((ConditionType.EQUALS.equals(st1.getCondition()) && ConditionType.GREATER_THAN.equals(st2.getCondition())) || (ConditionType.EQUALS.equals(st2.getCondition()) && ConditionType.GREATER_THAN.equals(st1.getCondition())));
    assertTrue(filter.isMet(new Condition("ami", 0, new Date())));
    assertTrue(filter.isMet(new Condition("foo", 20, null)));
    assertFalse(filter.isMet(new Condition("foo", 0, null)));
}
Also used : SearchCondition(org.apache.cxf.jaxrs.ext.search.SearchCondition) SearchCondition(org.apache.cxf.jaxrs.ext.search.SearchCondition) PrimitiveStatement(org.apache.cxf.jaxrs.ext.search.PrimitiveStatement) Date(java.util.Date) Test(org.junit.Test)

Example 8 with PrimitiveStatement

use of org.apache.cxf.jaxrs.ext.search.PrimitiveStatement in project cxf by apache.

the class FiqlParserTest method testParseComplex1.

@Test
public void testParseComplex1() throws SearchParseException {
    SearchCondition<Condition> filter = parser.parse("name==ami*;level=gt=10");
    assertEquals(ConditionType.AND, filter.getConditionType());
    List<SearchCondition<Condition>> conditions = filter.getSearchConditions();
    assertEquals(2, conditions.size());
    PrimitiveStatement st1 = conditions.get(0).getStatement();
    PrimitiveStatement st2 = conditions.get(1).getStatement();
    assertTrue((ConditionType.EQUALS.equals(st1.getCondition()) && ConditionType.GREATER_THAN.equals(st2.getCondition())) || (ConditionType.EQUALS.equals(st2.getCondition()) && ConditionType.GREATER_THAN.equals(st1.getCondition())));
    assertTrue(filter.isMet(new Condition("amichalec", 12, new Date())));
    assertTrue(filter.isMet(new Condition("ami", 12, new Date())));
    assertFalse(filter.isMet(new Condition("ami", 8, null)));
    assertFalse(filter.isMet(new Condition("am", 20, null)));
}
Also used : SearchCondition(org.apache.cxf.jaxrs.ext.search.SearchCondition) SearchCondition(org.apache.cxf.jaxrs.ext.search.SearchCondition) PrimitiveStatement(org.apache.cxf.jaxrs.ext.search.PrimitiveStatement) Date(java.util.Date) Test(org.junit.Test)

Aggregations

PrimitiveStatement (org.apache.cxf.jaxrs.ext.search.PrimitiveStatement)8 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 SearchCondition (org.apache.cxf.jaxrs.ext.search.SearchCondition)2 Test (org.junit.Test)2 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)2 Restriction (org.opennms.core.criteria.restrictions.Restriction)2 SearchParseException (org.apache.cxf.jaxrs.ext.search.SearchParseException)1 Filter (org.apache.hadoop.hbase.filter.Filter)1 SingleColumnValueFilter (org.apache.hadoop.hbase.filter.SingleColumnValueFilter)1 BooleanQuery (org.apache.lucene.search.BooleanQuery)1 NumericRangeQuery (org.apache.lucene.search.NumericRangeQuery)1 PhraseQuery (org.apache.lucene.search.PhraseQuery)1 Query (org.apache.lucene.search.Query)1 TermQuery (org.apache.lucene.search.TermQuery)1 TermRangeQuery (org.apache.lucene.search.TermRangeQuery)1 WildcardQuery (org.apache.lucene.search.WildcardQuery)1 Alias (org.opennms.core.criteria.Alias)1 Criteria (org.opennms.core.criteria.Criteria)1