use of org.apache.lucene.spatial.SpatialStrategy in project janusgraph by JanusGraph.
the class LuceneIndex method buildIndexFields.
private List<IndexableField> buildIndexFields(final Document doc, final KeyInformation.StoreRetriever information) {
List<IndexableField> fields = new ArrayList<>();
for (IndexableField field : doc.getFields()) {
String fieldName = field.name();
if (fieldName.equals(DOCID)) {
continue;
}
KeyInformation ki = information.get(getOrigFieldName(fieldName));
boolean isPossibleSortIndex = ki.getCardinality() == Cardinality.SINGLE;
Class<?> dataType = ki.getDataType();
if (AttributeUtils.isWholeNumber(dataType)) {
long value = field.numericValue().longValue();
fields.add(new LongPoint(fieldName, value));
if (isPossibleSortIndex) {
fields.add(new NumericDocValuesField(fieldName, value));
}
} else if (AttributeUtils.isDecimal(dataType)) {
double value = field.numericValue().doubleValue();
fields.add(new DoublePoint(fieldName, value));
if (isPossibleSortIndex) {
fields.add(new DoubleDocValuesField(fieldName, value));
}
} else if (AttributeUtils.isString(dataType)) {
final Mapping mapping = Mapping.getMapping(ki);
if ((mapping == Mapping.STRING || mapping == Mapping.TEXTSTRING) && isPossibleSortIndex) {
fields.add(new SortedDocValuesField(fieldName, new BytesRef(field.stringValue())));
}
} else if (AttributeUtils.isGeo(dataType)) {
if (log.isTraceEnabled())
log.trace("Updating geo-indexes for key {}", fieldName);
Shape shape;
try {
shape = Geoshape.fromWkt(field.stringValue().substring(GEOID.length())).getShape();
} catch (java.text.ParseException e) {
throw new IllegalArgumentException("Geoshape was not parsable", e);
}
final SpatialStrategy spatialStrategy = getSpatialStrategy(fieldName, ki);
Collections.addAll(fields, spatialStrategy.createIndexableFields(shape));
} else if (dataType.equals(Date.class) || dataType.equals(Instant.class)) {
long value = field.numericValue().longValue();
fields.add(new LongPoint(fieldName, value));
if (isPossibleSortIndex) {
fields.add(new NumericDocValuesField(fieldName, value));
}
} else if (dataType.equals(Boolean.class)) {
fields.add(new IntPoint(fieldName, field.numericValue().intValue() == 1 ? 1 : 0));
if (isPossibleSortIndex) {
fields.add(new NumericDocValuesField(fieldName, field.numericValue().intValue()));
}
}
}
return fields;
}
use of org.apache.lucene.spatial.SpatialStrategy in project titan by thinkaurelius.
the class LuceneExample method getSpatialStrategy.
private SpatialStrategy getSpatialStrategy(String key) {
SpatialStrategy strategy = spatial.get(key);
if (strategy == null) {
final int maxLevels = 11;
SpatialPrefixTree grid = new GeohashPrefixTree(ctx, maxLevels);
strategy = new RecursivePrefixTreeStrategy(grid, key);
spatial.put(key, strategy);
}
return strategy;
}
Aggregations