use of org.janusgraph.core.schema.Mapping in project janusgraph by JanusGraph.
the class LuceneIndex method supports.
@Override
public boolean supports(KeyInformation information, JanusGraphPredicate janusgraphPredicate) {
if (information.getCardinality() != Cardinality.SINGLE)
return false;
final Class<?> dataType = information.getDataType();
final Mapping mapping = Mapping.getMapping(information);
if (mapping != Mapping.DEFAULT && !AttributeUtil.isString(dataType) && !(mapping == Mapping.PREFIX_TREE && AttributeUtil.isGeo(dataType)))
return false;
if (Number.class.isAssignableFrom(dataType)) {
return janusgraphPredicate instanceof Cmp;
} else if (dataType == Geoshape.class) {
return janusgraphPredicate == Geo.INTERSECT || janusgraphPredicate == Geo.WITHIN || janusgraphPredicate == Geo.CONTAINS;
} else if (AttributeUtil.isString(dataType)) {
switch(mapping) {
case DEFAULT:
case TEXT:
// || janusgraphPredicate == Text.CONTAINS_REGEX;
return janusgraphPredicate == Text.CONTAINS || janusgraphPredicate == Text.CONTAINS_PREFIX || janusgraphPredicate == Text.CONTAINS_FUZZY;
case STRING:
return janusgraphPredicate instanceof Cmp || janusgraphPredicate == Text.PREFIX || janusgraphPredicate == Text.REGEX || janusgraphPredicate == Text.FUZZY;
}
} else if (dataType == Date.class || dataType == Instant.class) {
return janusgraphPredicate instanceof Cmp;
} else if (dataType == Boolean.class) {
return janusgraphPredicate == Cmp.EQUAL || janusgraphPredicate == Cmp.NOT_EQUAL;
} else if (dataType == UUID.class) {
return janusgraphPredicate == Cmp.EQUAL || janusgraphPredicate == Cmp.NOT_EQUAL;
}
return false;
}
use of org.janusgraph.core.schema.Mapping in project janusgraph by JanusGraph.
the class LuceneIndex method register.
@Override
public void register(String store, String key, KeyInformation information, BaseTransaction tx) throws BackendException {
final Class<?> dataType = information.getDataType();
final Mapping map = Mapping.getMapping(information);
Preconditions.checkArgument(map == Mapping.DEFAULT || AttributeUtil.isString(dataType) || (map == Mapping.PREFIX_TREE && AttributeUtil.isGeo(dataType)), "Specified illegal mapping [%s] for data type [%s]", map, dataType);
}
use of org.janusgraph.core.schema.Mapping in project janusgraph by JanusGraph.
the class LuceneCustomAnalyzer method getWrappedAnalyzer.
@Override
protected final Analyzer getWrappedAnalyzer(String fieldName) {
final KeyInformation keyInformation = informations.get(store, fieldName);
if (keyInformation == null || !String.class.isAssignableFrom(keyInformation.getDataType())) {
return analyzerFor(STANDARD_ANALYZER);
}
final Parameter[] parameters = keyInformation.getParameters();
// if mapping isn't present in parameters, we use Mapping.DEFAULT
final Mapping mapping = ParameterType.MAPPING.findParameter(parameters, Mapping.DEFAULT);
// everything else falls through a StandardAnalyzer as was the case before
return analyzerFor(analyzerNameFor(parameters, mapping, KEYWORD_ANALYZER, STANDARD_ANALYZER));
}
use of org.janusgraph.core.schema.Mapping in project janusgraph by JanusGraph.
the class SolrIndex method mapKey2Field.
@Override
public String mapKey2Field(String key, KeyInformation keyInfo) {
Preconditions.checkArgument(!StringUtils.containsAny(key, new char[] { ' ' }), "Invalid key name provided: %s", key);
if (!dynFields)
return key;
if (ParameterType.MAPPED_NAME.hasParameter(keyInfo.getParameters()))
return key;
String postfix;
final Class dataType = keyInfo.getDataType();
if (AttributeUtil.isString(dataType)) {
final Mapping map = getStringMapping(keyInfo);
switch(map) {
case TEXT:
postfix = "_t";
break;
case STRING:
postfix = "_s";
break;
default:
throw new IllegalArgumentException("Unsupported string mapping: " + map);
}
} else if (AttributeUtil.isWholeNumber(dataType)) {
if (dataType.equals(Long.class))
postfix = "_l";
else
postfix = "_i";
} else if (AttributeUtil.isDecimal(dataType)) {
if (dataType.equals(Float.class))
postfix = "_f";
else
postfix = "_d";
} else if (dataType.equals(Geoshape.class)) {
postfix = "_g";
} else if (dataType.equals(Date.class) || dataType.equals(Instant.class)) {
postfix = "_dt";
} else if (dataType.equals(Boolean.class)) {
postfix = "_b";
} else if (dataType.equals(UUID.class)) {
postfix = "_uuid";
} else
throw new IllegalArgumentException("Unsupported data type [" + dataType + "] for field: " + key);
if (keyInfo.getCardinality() == Cardinality.SET || keyInfo.getCardinality() == Cardinality.LIST) {
postfix += "s";
}
return key + postfix;
}
use of org.janusgraph.core.schema.Mapping in project janusgraph by JanusGraph.
the class ElasticSearchIndex method query.
@Override
public Stream<String> query(IndexQuery query, KeyInformation.IndexRetriever informations, BaseTransaction tx) throws BackendException {
final ElasticSearchRequest sr = new ElasticSearchRequest();
final Map<String, Object> esQuery = getFilter(query.getCondition(), informations.get(query.getStore()));
sr.setQuery(compat.prepareQuery(esQuery));
if (!query.getOrder().isEmpty()) {
final List<IndexQuery.OrderEntry> orders = query.getOrder();
for (final IndexQuery.OrderEntry orderEntry : orders) {
final String order = orderEntry.getOrder().name();
final KeyInformation information = informations.get(query.getStore()).get(orderEntry.getKey());
final Mapping mapping = Mapping.getMapping(information);
final Class<?> datatype = orderEntry.getDatatype();
sr.addSort(orderEntry.getKey(), order.toLowerCase(), convertToEsDataType(datatype, mapping));
}
}
sr.setFrom(0);
if (query.hasLimit()) {
sr.setSize(Math.min(query.getLimit(), batchSize));
} else {
sr.setSize(batchSize);
}
ElasticSearchResponse response;
try {
final String indexStoreName = getIndexStoreName(query.getStore());
final String indexType = useMultitypeIndex ? query.getStore() : null;
response = client.search(indexStoreName, indexType, compat.createRequestBody(sr, NULL_PARAMETERS), sr.getSize() >= batchSize);
log.debug("First Executed query [{}] in {} ms", query.getCondition(), response.getTook());
final ElasticSearchScroll resultIterator = new ElasticSearchScroll(client, response, sr.getSize());
final Stream<RawQuery.Result<String>> toReturn = StreamSupport.stream(Spliterators.spliteratorUnknownSize(resultIterator, Spliterator.ORDERED), false);
return (query.hasLimit() ? toReturn.limit(query.getLimit()) : toReturn).map(RawQuery.Result::getResult);
} catch (final IOException | UncheckedIOException e) {
throw new PermanentBackendException(e);
}
}
Aggregations