use of com.tuplejump.stargate.lucene.Properties in project stargate-core by tuplejump.
the class CassandraUtils method addFieldType.
private static void addFieldType(String columnName, AbstractType validator, Properties properties, Map<String, NumericConfig> numericFieldOptions, Map<String, FieldType> fieldDocValueTypes, Map<String, FieldType> collectionFieldDocValueTypes, Map<String, FieldType> fieldTypes, Map<String, FieldType[]> collectionFieldTypes) {
if (validator.isCollection()) {
if (validator instanceof MapType) {
properties.setType(Type.map);
MapType mapType = (MapType) validator;
AbstractType keyValidator = mapType.getKeysType();
AbstractType valueValidator = mapType.getValuesType();
Properties keyProps = properties.getFields().get("_key");
Properties valueProps = properties.getFields().get("_value");
if (keyProps == null) {
keyProps = new Properties();
keyProps.setAnalyzer(properties.getAnalyzer());
properties.getFields().put("_key", keyProps);
}
if (valueProps == null) {
valueProps = new Properties();
valueProps.setAnalyzer(properties.getAnalyzer());
properties.getFields().put("_value", valueProps);
}
setFromAbstractType(keyProps, keyValidator);
setFromAbstractType(valueProps, valueValidator);
FieldType keyFieldType = fieldType(keyProps, keyValidator);
FieldType valueFieldType = fieldType(valueProps, valueValidator);
if (valueProps.getStriped() == Properties.Striped.only || valueProps.getStriped() == Properties.Striped.also) {
FieldType docValueType = LuceneUtils.docValueTypeFrom(valueFieldType);
collectionFieldDocValueTypes.put(columnName, docValueType);
}
if (!(valueProps.getStriped() == Properties.Striped.only))
collectionFieldTypes.put(columnName, new FieldType[] { keyFieldType, valueFieldType });
} else if (validator instanceof ListType || validator instanceof SetType) {
AbstractType elementValidator;
if (validator instanceof SetType) {
SetType setType = (SetType) validator;
elementValidator = setType.getElementsType();
} else {
ListType listType = (ListType) validator;
elementValidator = listType.getElementsType();
}
setFromAbstractType(properties, elementValidator);
FieldType elementFieldType = fieldType(properties, elementValidator);
if (properties.getStriped() == Properties.Striped.only || properties.getStriped() == Properties.Striped.also) {
FieldType docValueType = LuceneUtils.docValueTypeFrom(elementFieldType);
collectionFieldDocValueTypes.put(columnName, docValueType);
}
if (!(properties.getStriped() == Properties.Striped.only))
collectionFieldTypes.put(columnName, new FieldType[] { elementFieldType });
}
} else {
setFromAbstractType(properties, validator);
FieldType fieldType = fieldType(properties, validator);
if (fieldType.numericType() != null) {
numericFieldOptions.put(columnName, LuceneUtils.numericConfig(fieldType));
}
if (properties.getStriped() == Properties.Striped.only || properties.getStriped() == Properties.Striped.also) {
FieldType docValueType = LuceneUtils.docValueTypeFrom(fieldType);
fieldDocValueTypes.put(columnName, docValueType);
}
if (properties.getStriped() != Properties.Striped.only)
fieldTypes.put(columnName, fieldType);
}
}
use of com.tuplejump.stargate.lucene.Properties 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.Properties 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