use of org.polymap.recordstore.QueryExpression in project polymap4-core by Polymap4.
the class NumericValueCoder method searchQuery.
public Query searchQuery(QueryExpression exp) {
// EQUALS
if (exp instanceof QueryExpression.Equal) {
Equal equalExp = (QueryExpression.Equal) exp;
if (equalExp.value instanceof Number) {
String key = equalExp.key;
Number value = (Number) equalExp.value;
if (equalExp.value instanceof Integer) {
return NumericRangeQuery.newIntRange(key, value.intValue(), value.intValue(), true, true);
} else if (equalExp.value instanceof Long) {
return NumericRangeQuery.newLongRange(key, value.longValue(), value.longValue(), true, true);
} else if (equalExp.value instanceof Float) {
return NumericRangeQuery.newFloatRange(key, value.floatValue(), value.floatValue(), true, true);
} else if (equalExp.value instanceof Double) {
return NumericRangeQuery.newDoubleRange(key, value.doubleValue(), value.doubleValue(), true, true);
} else {
throw new RuntimeException("Unknown Number type: " + value.getClass());
}
}
} else // GREATER
if (exp instanceof QueryExpression.Greater) {
Greater greaterExp = (QueryExpression.Greater) exp;
if (greaterExp.value instanceof Number) {
String key = greaterExp.key;
Number value = (Number) greaterExp.value;
if (greaterExp.value instanceof Integer) {
return NumericRangeQuery.newIntRange(key, value.intValue(), null, false, false);
} else if (greaterExp.value instanceof Long) {
return NumericRangeQuery.newLongRange(key, value.longValue(), null, false, false);
} else if (greaterExp.value instanceof Float) {
return NumericRangeQuery.newFloatRange(key, value.floatValue(), null, false, false);
} else if (greaterExp.value instanceof Double) {
return NumericRangeQuery.newDoubleRange(key, value.doubleValue(), null, false, false);
} else {
throw new RuntimeException("Unknown Number type: " + value.getClass());
}
}
} else // GREATER OR EQUAL
if (exp instanceof QueryExpression.GreaterOrEqual) {
GreaterOrEqual greaterExp = (QueryExpression.GreaterOrEqual) exp;
if (greaterExp.value instanceof Number) {
String key = greaterExp.key;
Number value = (Number) greaterExp.value;
if (greaterExp.value instanceof Integer) {
return NumericRangeQuery.newIntRange(key, value.intValue(), null, true, false);
} else if (greaterExp.value instanceof Long) {
return NumericRangeQuery.newLongRange(key, value.longValue(), null, true, false);
} else if (greaterExp.value instanceof Float) {
return NumericRangeQuery.newFloatRange(key, value.floatValue(), null, true, false);
} else if (greaterExp.value instanceof Double) {
return NumericRangeQuery.newDoubleRange(key, value.doubleValue(), null, true, false);
} else {
throw new RuntimeException("Unknown Number type: " + value.getClass());
}
}
} else // LESS
if (exp instanceof QueryExpression.Less) {
Less lessExp = (QueryExpression.Less) exp;
if (lessExp.value instanceof Number) {
String key = lessExp.key;
Number value = (Number) lessExp.value;
if (lessExp.value instanceof Integer) {
return NumericRangeQuery.newIntRange(key, null, value.intValue(), false, false);
} else if (lessExp.value instanceof Long) {
return NumericRangeQuery.newLongRange(key, null, value.longValue(), false, false);
} else if (lessExp.value instanceof Float) {
return NumericRangeQuery.newFloatRange(key, null, value.floatValue(), false, false);
} else if (lessExp.value instanceof Double) {
return NumericRangeQuery.newDoubleRange(key, null, value.doubleValue(), false, false);
} else {
throw new RuntimeException("Unknown Number type: " + value.getClass());
}
}
} else // LESS or equal
if (exp instanceof QueryExpression.LessOrEqual) {
LessOrEqual lessExp = (QueryExpression.LessOrEqual) exp;
if (lessExp.value instanceof Number) {
String key = lessExp.key;
Number value = (Number) lessExp.value;
if (lessExp.value instanceof Integer) {
return NumericRangeQuery.newIntRange(key, null, value.intValue(), false, true);
} else if (lessExp.value instanceof Long) {
return NumericRangeQuery.newLongRange(key, null, value.longValue(), false, true);
} else if (lessExp.value instanceof Float) {
return NumericRangeQuery.newFloatRange(key, null, value.floatValue(), false, true);
} else if (lessExp.value instanceof Double) {
return NumericRangeQuery.newDoubleRange(key, null, value.doubleValue(), false, true);
} else {
throw new RuntimeException("Unknown Number type: " + value.getClass());
}
}
} else // MATCHES
if (exp instanceof QueryExpression.Match) {
Match matchExp = (Match) exp;
if (matchExp.value instanceof Number) {
throw new UnsupportedOperationException("MATCHES not supported for Number values.");
}
}
return null;
}
use of org.polymap.recordstore.QueryExpression in project polymap4-core by Polymap4.
the class LuceneRecordStore method find.
@Override
public ResultSet find(RecordQuery query) throws Exception {
assert !isClosed() : "Store is closed already.";
// SimpleQuery
if (query instanceof SimpleQuery) {
Query luceneQuery = null;
Collection<QueryExpression> expressions = ((SimpleQuery) query).expressions();
if (expressions.isEmpty()) {
luceneQuery = new MatchAllDocsQuery();
} else {
luceneQuery = new BooleanQuery();
for (QueryExpression exp : expressions) {
((BooleanQuery) luceneQuery).add(valueCoders.searchQuery(exp), BooleanClause.Occur.MUST);
}
}
return new LuceneRecordQuery(this, luceneQuery).setMaxResults(query.getMaxResults()).setFirstResult(query.getFirstResult()).sort(query.getSortKey(), query.getSortOrder(), query.getSortType()).execute();
} else // other
{
return query.execute();
}
}
Aggregations