use of com.tuplejump.stargate.lucene.Properties in project stargate-core by tuplejump.
the class PhraseCondition method query.
/**
* {@inheritDoc}
*/
@Override
public Query query(Options schema) {
if (field == null || field.trim().isEmpty()) {
throw new IllegalArgumentException("Field name required");
}
if (values == null) {
throw new IllegalArgumentException("Field values required");
}
if (slop == null) {
throw new IllegalArgumentException("Slop required");
}
if (slop < 0) {
throw new IllegalArgumentException("Slop must be positive");
}
Properties properties = schema.getProperties(field);
Type fieldType = properties != null ? properties.getType() : Type.text;
if (fieldType.isCharSeq()) {
Analyzer analyzer = schema.analyzer;
PhraseQuery.Builder query = new PhraseQuery.Builder();
query.setSlop(slop);
int count = 0;
for (String value : values) {
if (value != null) {
String analyzedValue = analyze(field, value, analyzer);
if (analyzedValue != null) {
Term term = new Term(field, analyzedValue);
query.add(term, count);
}
}
count++;
}
return query.build();
}
String message = String.format("Phrase queries cannot be supported until mapping is defined");
throw new UnsupportedOperationException(message);
}
use of com.tuplejump.stargate.lucene.Properties 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.Properties 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.Properties in project stargate-core by tuplejump.
the class AggregateFunction method load.
public void load(Tuple tuple, IndexEntryCollector.IndexEntry entry) {
for (String field : positions.keySet()) {
Type validator = options.types.get(field);
load(tuple, entry, field, validator);
if (validator == null) {
Iterator<String> fieldNameParts = Constants.dotSplitter.split(field).iterator();
String columnName = fieldNameParts.next();
if (options.nestedFields.contains(columnName)) {
Properties columnProps = options.fields.get(columnName);
Properties fieldProps;
if (columnProps.getType() == Type.map) {
fieldProps = columnProps.getFields().get("_value");
} else {
fieldProps = columnProps.getFields().get(fieldNameParts.next());
}
load(tuple, entry, field, fieldProps.getType());
}
}
}
}
use of com.tuplejump.stargate.lucene.Properties in project stargate-core by tuplejump.
the class JsonDocumentTest method shouldParseJsonAndGetFields.
@Test
public void shouldParseJsonAndGetFields() throws Exception {
Properties jsonColProps = new Properties();
jsonColProps.setType(Type.object);
Properties ageProps = new Properties();
ageProps.setType(Type.integer);
//json fields mapping
jsonColProps.setFields(Collections.singletonMap("age", ageProps));
Properties rootProps = new Properties();
rootProps.setFields(Collections.singletonMap("jsoncol", jsonColProps));
StringWriter sw = new StringWriter();
PrintWriter writer = new PrintWriter(sw);
//formatJsonNode(kid, writer, 0);
formatJsonNode(jsonVal, writer, 0);
writer.flush();
String json = sw.toString();
JsonDocument jsonDocument = new StreamingJsonDocument(json, rootProps, "jsoncol");
List<Field> fields = jsonDocument.getFields();
System.out.println(fields);
System.out.println("Overall fields:" + fields.size());
Assert.assertEquals(75, fields.size());
Assert.assertEquals(5, numberOfFieldsWithKey("name", fields));
Assert.assertEquals(15, numberOfFieldsWithPrefix("friends", fields));
Assert.assertEquals(15, numberOfFieldsWithKey("friends.name", fields));
Assert.assertEquals(15, numberOfFieldsWithKey("tags", fields));
Assert.assertEquals(5, numberOfFieldsWithNumericType(FieldType.NumericType.INT, fields));
MemIndex memIndex = new MemIndex(rootProps);
List<JsonNode> kids = jsonVal.getElements();
for (JsonNode kid : kids) {
StringWriter kidSWriter = new StringWriter();
PrintWriter kidWriter = new PrintWriter(kidSWriter);
formatJsonNode(kid, kidWriter, 0);
kidWriter.flush();
String kidJson = kidSWriter.toString();
JsonDocument kidDoc = new StreamingJsonDocument(kidJson, rootProps, "jsoncol");
memIndex.add(kidDoc.getFields());
}
Assert.assertEquals(1, memIndex.hits("age:40", "jsoncol"));
Assert.assertEquals(2, memIndex.hits("eyeColor:blue", "jsoncol"));
Assert.assertEquals(2, memIndex.hits("gender:female", "jsoncol"));
}
Aggregations