Search in sources :

Example 6 with Mapping

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;
}
Also used : Mapping(org.janusgraph.core.schema.Mapping)

Example 7 with Mapping

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);
}
Also used : Mapping(org.janusgraph.core.schema.Mapping)

Example 8 with Mapping

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));
}
Also used : Parameter(org.janusgraph.core.schema.Parameter) Mapping(org.janusgraph.core.schema.Mapping) KeyInformation(org.janusgraph.diskstorage.indexing.KeyInformation)

Example 9 with Mapping

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;
}
Also used : Instant(java.time.Instant) Geoshape(org.janusgraph.core.attribute.Geoshape) Mapping(org.janusgraph.core.schema.Mapping) Date(java.util.Date)

Example 10 with Mapping

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);
    }
}
Also used : IndexQuery(org.janusgraph.diskstorage.indexing.IndexQuery) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) Mapping(org.janusgraph.core.schema.Mapping) IndexMapping(org.janusgraph.diskstorage.es.IndexMappings.IndexMapping) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) KeyInformation(org.janusgraph.diskstorage.indexing.KeyInformation)

Aggregations

Mapping (org.janusgraph.core.schema.Mapping)17 Instant (java.time.Instant)8 UUID (java.util.UUID)6 Geoshape (org.janusgraph.core.attribute.Geoshape)6 IndexMapping (org.janusgraph.diskstorage.es.IndexMappings.IndexMapping)6 IOException (java.io.IOException)4 UncheckedIOException (java.io.UncheckedIOException)4 Cmp (org.janusgraph.core.attribute.Cmp)4 PermanentBackendException (org.janusgraph.diskstorage.PermanentBackendException)4 Date (java.util.Date)3 Geo (org.janusgraph.core.attribute.Geo)3 KeyInformation (org.janusgraph.diskstorage.indexing.KeyInformation)3 JanusGraphPredicate (org.janusgraph.graphdb.query.JanusGraphPredicate)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 JanusGraphException (org.janusgraph.core.JanusGraphException)2 Parameter (org.janusgraph.core.schema.Parameter)2 BackendException (org.janusgraph.diskstorage.BackendException)2 TemporaryBackendException (org.janusgraph.diskstorage.TemporaryBackendException)2