Search in sources :

Example 1 with Constant

use of com.querydsl.core.types.Constant in project spring-data-commons by spring-projects.

the class QuerydslPredicateBuilderUnitTests method resolvesCommaSeparatedArgumentToArrayCorrectly.

// DATACMNS-734
@Test
@SuppressWarnings("unchecked")
public void resolvesCommaSeparatedArgumentToArrayCorrectly() {
    values.add("address.lonLat", "40.740337,-73.995146");
    Predicate predicate = builder.getPredicate(USER_TYPE, values, DEFAULT_BINDINGS);
    Constant<Object> constant = (Constant<Object>) ((List<?>) getField(getField(predicate, "mixin"), "args")).get(1);
    assertThat(constant.getConstant()).isEqualTo(new Double[] { 40.740337D, -73.995146D });
}
Also used : Constant(com.querydsl.core.types.Constant) Predicate(com.querydsl.core.types.Predicate) Test(org.junit.Test)

Example 2 with Constant

use of com.querydsl.core.types.Constant in project spring-data-commons by spring-projects.

the class QuerydslPredicateBuilderUnitTests method leavesCommaSeparatedArgumentUntouchedWhenTargetIsNotAnArray.

// DATACMNS-734
@Test
@SuppressWarnings("unchecked")
public void leavesCommaSeparatedArgumentUntouchedWhenTargetIsNotAnArray() {
    values.add("address.city", "rivers,two");
    Predicate predicate = builder.getPredicate(USER_TYPE, values, DEFAULT_BINDINGS);
    Constant<Object> constant = (Constant<Object>) ((List<?>) getField(getField(predicate, "mixin"), "args")).get(1);
    assertThat(constant.getConstant()).isEqualTo("rivers,two");
}
Also used : Constant(com.querydsl.core.types.Constant) Predicate(com.querydsl.core.types.Predicate) Test(org.junit.Test)

Example 3 with Constant

use of com.querydsl.core.types.Constant in project querydsl by querydsl.

the class LuceneSerializer method in.

protected Query in(Operation<?> operation, QueryMetadata metadata, boolean ignoreCase) {
    Path<?> path = getPath(operation.getArg(0));
    String field = toField(path);
    @SuppressWarnings("unchecked") Constant<Collection<?>> // this is the expected type
    expectedConstant = (Constant<Collection<?>>) operation.getArg(1);
    Collection<?> values = expectedConstant.getConstant();
    BooleanQuery bq = new BooleanQuery();
    if (Number.class.isAssignableFrom(path.getType())) {
        for (Object value : values) {
            TermQuery eq = new TermQuery(new Term(field, convertNumber((Number) value)));
            bq.add(eq, Occur.SHOULD);
        }
    } else {
        for (Object value : values) {
            String[] str = convert(path, value);
            bq.add(eq(field, str, ignoreCase), Occur.SHOULD);
        }
    }
    return bq;
}
Also used : BooleanQuery(org.apache.lucene.search.BooleanQuery) TermQuery(org.apache.lucene.search.TermQuery) Constant(com.querydsl.core.types.Constant) Collection(java.util.Collection) Term(org.apache.lucene.index.Term)

Example 4 with Constant

use of com.querydsl.core.types.Constant in project querydsl by querydsl.

the class LuceneSerializer method eq.

protected Query eq(Operation<?> operation, QueryMetadata metadata, boolean ignoreCase) {
    verifyArguments(operation);
    Path<?> path = getPath(operation.getArg(0));
    String field = toField(path);
    if (Number.class.isAssignableFrom(operation.getArg(1).getType())) {
        @SuppressWarnings("unchecked") Constant<? extends Number> // guarded by previous check
        rightArg = (Constant<? extends Number>) operation.getArg(1);
        return new TermQuery(new Term(field, convertNumber(rightArg.getConstant())));
    }
    return eq(field, convert(path, operation.getArg(1), metadata), ignoreCase);
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) Constant(com.querydsl.core.types.Constant) Term(org.apache.lucene.index.Term)

Example 5 with Constant

use of com.querydsl.core.types.Constant in project querydsl by querydsl.

the class LuceneSerializer method toQuery.

private Query toQuery(Operation<?> operation, QueryMetadata metadata) {
    Operator op = operation.getOperator();
    if (op == Ops.OR) {
        return toTwoHandSidedQuery(operation, Occur.SHOULD, metadata);
    } else if (op == Ops.AND) {
        return toTwoHandSidedQuery(operation, Occur.MUST, metadata);
    } else if (op == Ops.NOT) {
        BooleanQuery bq = new BooleanQuery();
        bq.add(new BooleanClause(toQuery(operation.getArg(0), metadata), Occur.MUST_NOT));
        bq.add(new BooleanClause(new MatchAllDocsQuery(), Occur.MUST));
        return bq;
    } else if (op == Ops.LIKE) {
        return like(operation, metadata);
    } else if (op == Ops.LIKE_IC) {
        throw new IgnoreCaseUnsupportedException();
    } else if (op == Ops.EQ) {
        return eq(operation, metadata, false);
    } else if (op == Ops.EQ_IGNORE_CASE) {
        throw new IgnoreCaseUnsupportedException();
    } else if (op == Ops.NE) {
        return ne(operation, metadata, false);
    } else if (op == Ops.STARTS_WITH) {
        return startsWith(metadata, operation, false);
    } else if (op == Ops.STARTS_WITH_IC) {
        throw new IgnoreCaseUnsupportedException();
    } else if (op == Ops.ENDS_WITH) {
        return endsWith(operation, metadata, false);
    } else if (op == Ops.ENDS_WITH_IC) {
        throw new IgnoreCaseUnsupportedException();
    } else if (op == Ops.STRING_CONTAINS) {
        return stringContains(operation, metadata, false);
    } else if (op == Ops.STRING_CONTAINS_IC) {
        throw new IgnoreCaseUnsupportedException();
    } else if (op == Ops.BETWEEN) {
        return between(operation, metadata);
    } else if (op == Ops.IN) {
        return in(operation, metadata, false);
    } else if (op == Ops.NOT_IN) {
        return notIn(operation, metadata, false);
    } else if (op == Ops.LT) {
        return lt(operation, metadata);
    } else if (op == Ops.GT) {
        return gt(operation, metadata);
    } else if (op == Ops.LOE) {
        return le(operation, metadata);
    } else if (op == Ops.GOE) {
        return ge(operation, metadata);
    } else if (op == LuceneOps.LUCENE_QUERY) {
        @SuppressWarnings("unchecked") Constant<Query> // this is the expected type
        expectedConstant = (Constant<Query>) operation.getArg(0);
        return expectedConstant.getConstant();
    }
    throw new UnsupportedOperationException("Illegal operation " + operation);
}
Also used : Operator(com.querydsl.core.types.Operator) BooleanClause(org.apache.lucene.search.BooleanClause) BooleanQuery(org.apache.lucene.search.BooleanQuery) Query(org.apache.lucene.search.Query) NumericRangeQuery(org.apache.lucene.search.NumericRangeQuery) PhraseQuery(org.apache.lucene.search.PhraseQuery) PrefixQuery(org.apache.lucene.search.PrefixQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) WildcardQuery(org.apache.lucene.search.WildcardQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) Constant(com.querydsl.core.types.Constant) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery)

Aggregations

Constant (com.querydsl.core.types.Constant)5 TermQuery (org.apache.lucene.search.TermQuery)3 Predicate (com.querydsl.core.types.Predicate)2 Term (org.apache.lucene.index.Term)2 BooleanQuery (org.apache.lucene.search.BooleanQuery)2 Test (org.junit.Test)2 Operator (com.querydsl.core.types.Operator)1 Collection (java.util.Collection)1 BooleanClause (org.apache.lucene.search.BooleanClause)1 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)1 NumericRangeQuery (org.apache.lucene.search.NumericRangeQuery)1 PhraseQuery (org.apache.lucene.search.PhraseQuery)1 PrefixQuery (org.apache.lucene.search.PrefixQuery)1 Query (org.apache.lucene.search.Query)1 TermRangeQuery (org.apache.lucene.search.TermRangeQuery)1 WildcardQuery (org.apache.lucene.search.WildcardQuery)1