use of com.tuplejump.stargate.lucene.Type in project stargate-core by tuplejump.
the class RegexpCondition method query.
/**
* {@inheritDoc}
*/
@Override
public Query query(Options schema) {
if (field == null || field.trim().isEmpty()) {
throw new IllegalArgumentException("Field name required");
}
if (value == null || value.trim().isEmpty()) {
throw new IllegalArgumentException("Field value required");
}
Query query;
Properties properties = schema.getProperties(field);
Type fieldType = properties != null ? properties.getType() : Type.text;
if (fieldType.isCharSeq()) {
Term term = new Term(field, value);
query = new RegexpQuery(term);
} else {
String message = String.format("Regexp queries are not supported by %s mapper", fieldType);
throw new UnsupportedOperationException(message);
}
return query;
}
use of com.tuplejump.stargate.lucene.Type in project stargate-core by tuplejump.
the class WildcardCondition method query.
/**
* {@inheritDoc}
*/
@Override
public Query query(Options schema) {
if (field == null || field.trim().isEmpty()) {
throw new IllegalArgumentException("Field name required");
}
if (value == null || value.trim().isEmpty()) {
throw new IllegalArgumentException("Field value required");
}
Query query;
Properties properties = schema.getProperties(field);
Type fieldType = properties != null ? properties.getType() : Type.text;
if (fieldType.isCharSeq()) {
Term term = new Term(field, value);
query = new WildcardQuery(term);
} else {
String message = String.format("Wildcard queries are not supported by %s mapper", fieldType);
throw new UnsupportedOperationException(message);
}
return query;
}
use of com.tuplejump.stargate.lucene.Type in project stargate-core by tuplejump.
the class CassandraUtils method setFromAbstractType.
public static void setFromAbstractType(Properties properties, AbstractType type) {
if (properties.getType() != null)
return;
CQL3Type cqlType = type.asCQL3Type();
Type fromAbstractType = fromAbstractType(cqlType);
properties.setType(fromAbstractType);
}
use of com.tuplejump.stargate.lucene.Type in project stargate-core by tuplejump.
the class MatchCondition method query.
/**
* {@inheritDoc}
*/
@Override
public Query query(Options schema) throws Exception {
if (field == null || field.trim().isEmpty()) {
throw new IllegalArgumentException("Field name required");
}
if (value == null || value instanceof String && ((String) value).trim().isEmpty()) {
throw new IllegalArgumentException("Field value required");
}
NumericConfig numericConfig = schema.numericFieldOptions.get(field);
Properties properties = schema.getProperties(field);
Type fieldType = properties != null ? properties.getType() : Type.text;
Query query;
if (fieldType.isCharSeq() || fieldType == Type.bool) {
String analyzedValue = analyze(field, value.toString(), schema.analyzer);
if (analyzedValue == null) {
throw new IllegalArgumentException("Value discarded by analyzer");
}
Term term = new Term(field, analyzedValue);
query = new TermQuery(term);
} else if (fieldType == Type.integer) {
assert numericConfig != null;
Integer value = numericConfig.getNumberFormat().parse(this.value.toString()).intValue();
query = NumericRangeQuery.newIntRange(field, value, value, true, true);
} else if (fieldType == Type.bigint || fieldType == Type.date) {
assert numericConfig != null;
Long value = numericConfig.getNumberFormat().parse(this.value.toString()).longValue();
query = NumericRangeQuery.newLongRange(field, value, value, true, true);
} else if (fieldType == Type.decimal) {
assert numericConfig != null;
Float value = numericConfig.getNumberFormat().parse(this.value.toString()).floatValue();
query = NumericRangeQuery.newFloatRange(field, value, value, true, true);
} else if (fieldType == Type.bigdecimal) {
assert numericConfig != null;
Double value = numericConfig.getNumberFormat().parse(this.value.toString()).doubleValue();
query = NumericRangeQuery.newDoubleRange(field, value, value, true, true);
} else {
String message = String.format("Match queries are not supported by %s field type", fieldType);
throw new UnsupportedOperationException(message);
}
return query;
}
use of com.tuplejump.stargate.lucene.Type in project stargate-core by tuplejump.
the class PrefixCondition method query.
/**
* {@inheritDoc}
*/
@Override
public Query query(Options schema) {
if (field == null || field.trim().isEmpty()) {
throw new IllegalArgumentException("Field name required");
}
if (value == null) {
throw new IllegalArgumentException("Field value required");
}
Query query;
Properties properties = schema.getProperties(field);
Type fieldType = properties != null ? properties.getType() : Type.text;
if (fieldType.isCharSeq()) {
Term term = new Term(field, value);
query = new PrefixQuery(term);
} else {
String message = String.format("Prefix queries are not supported by %s mapper", fieldType);
throw new UnsupportedOperationException(message);
}
return query;
}
Aggregations