use of org.janusgraph.core.schema.Mapping in project janusgraph by JanusGraph.
the class SolrIndex method supports.
@Override
public boolean supports(KeyInformation information) {
final Class<?> dataType = information.getDataType();
final Mapping mapping = Mapping.getMapping(information);
if (Number.class.isAssignableFrom(dataType) || dataType == Date.class || dataType == Instant.class || dataType == Boolean.class || dataType == UUID.class) {
return mapping == Mapping.DEFAULT;
} else if (AttributeUtil.isString(dataType)) {
return mapping == Mapping.DEFAULT || mapping == Mapping.TEXT || mapping == Mapping.STRING;
} else if (AttributeUtil.isGeo(dataType)) {
return mapping == Mapping.DEFAULT || mapping == Mapping.PREFIX_TREE;
}
return false;
}
use of org.janusgraph.core.schema.Mapping in project janusgraph by JanusGraph.
the class LuceneIndex method addToDocument.
private void addToDocument(String store, String docID, Document doc, List<IndexEntry> content, Map<String, Shape> geoFields, KeyInformation.IndexRetriever information) {
Preconditions.checkNotNull(doc);
for (final IndexEntry e : content) {
Preconditions.checkArgument(!e.hasMetaData(), "Lucene index does not support indexing meta data: %s", e);
if (log.isTraceEnabled())
log.trace("Adding field [{}] on document [{}]", e.field, docID);
if (doc.getField(e.field) != null)
doc.removeFields(e.field);
if (e.value instanceof Number) {
final Field field;
final Field sortField;
if (AttributeUtil.isWholeNumber((Number) e.value)) {
field = new LongPoint(e.field, ((Number) e.value).longValue());
sortField = new NumericDocValuesField(e.field, ((Number) e.value).longValue());
} else {
// double or float
field = new DoublePoint(e.field, ((Number) e.value).doubleValue());
sortField = new DoubleDocValuesField(e.field, ((Number) e.value).doubleValue());
}
doc.add(field);
doc.add(sortField);
} else if (AttributeUtil.isString(e.value)) {
final String str = (String) e.value;
final Mapping mapping = Mapping.getMapping(store, e.field, information);
final Field field;
switch(mapping) {
case DEFAULT:
case TEXT:
// lowering the case for case insensitive text search
field = new TextField(e.field, str.toLowerCase(), Field.Store.YES);
break;
case STRING:
// if this field uses a custom analyzer, it must be stored as a TextField
// (or the analyzer, even if it is a KeywordAnalyzer won't be used)
field = new TextField(e.field, str, Field.Store.YES);
break;
default:
throw new IllegalArgumentException("Illegal mapping specified: " + mapping);
}
doc.add(field);
} else if (e.value instanceof Geoshape) {
final Shape shape = ((Geoshape) e.value).getShape();
geoFields.put(e.field, shape);
doc.add(new StoredField(e.field, GEOID + e.value.toString()));
} else if (e.value instanceof Date) {
doc.add(new LongPoint(e.field, (((Date) e.value).getTime())));
} else if (e.value instanceof Instant) {
doc.add(new LongPoint(e.field, (((Instant) e.value).toEpochMilli())));
} else if (e.value instanceof Boolean) {
doc.add(new IntPoint(e.field, ((Boolean) e.value) ? 1 : 0));
} else if (e.value instanceof UUID) {
// Solr stores UUIDs as strings, we we do the same.
final Field field = new StringField(e.field, e.value.toString(), Field.Store.YES);
doc.add(field);
} else {
throw new IllegalArgumentException("Unsupported type: " + e.value);
}
}
for (final Map.Entry<String, Shape> geo : geoFields.entrySet()) {
if (log.isTraceEnabled())
log.trace("Updating geo-indexes for key {}", geo.getKey());
final KeyInformation ki = information.get(store, geo.getKey());
final SpatialStrategy spatialStrategy = getSpatialStrategy(geo.getKey(), ki);
for (final IndexableField f : spatialStrategy.createIndexableFields(geo.getValue())) {
if (doc.getField(f.name()) != null) {
doc.removeFields(f.name());
}
doc.add(f);
if (spatialStrategy instanceof PointVectorStrategy) {
doc.add(new DoubleDocValuesField(f.name(), f.numericValue() == null ? null : f.numericValue().doubleValue()));
}
}
}
}
Aggregations