org.janusgraph.core.schema.Mapping Java Examples

The following examples show how to use org.janusgraph.core.schema.Mapping. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Solr6Index.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
    public boolean supports(KeyInformation information, JanusGraphPredicate predicate) {
        final Class<?> dataType = information.getDataType();
        final Mapping mapping = Mapping.getMapping(information);
        if (mapping!=Mapping.DEFAULT && !AttributeUtils.isString(dataType) &&
                !(mapping==Mapping.PREFIX_TREE && AttributeUtils.isGeo(dataType))) return false;

        if (Number.class.isAssignableFrom(dataType)) {
            return predicate instanceof Cmp;
        } else if (dataType == Geoshape.class) {
            switch(mapping) {
                case DEFAULT:
                    return predicate == Geo.WITHIN || predicate == Geo.INTERSECT;
                case PREFIX_TREE:
                    return predicate == Geo.INTERSECT || predicate == Geo.WITHIN || predicate == Geo.CONTAINS;
            }
        } else if (AttributeUtils.isString(dataType)) {
            switch(mapping) {
                case DEFAULT:
                case TEXT:
                    return predicate == Text.CONTAINS || predicate == Text.CONTAINS_PREFIX
                            || predicate == Text.CONTAINS_REGEX || predicate == Text.CONTAINS_FUZZY;
                case STRING:
                    return predicate instanceof Cmp || predicate==Text.REGEX || predicate==Text.PREFIX  || predicate == Text.FUZZY;
//                case TEXTSTRING:
//                    return (janusgraphPredicate instanceof Text) || janusgraphPredicate == Cmp.EQUAL || janusgraphPredicate==Cmp.NOT_EQUAL;
            }
        } else if (dataType == Date.class || dataType == Instant.class) {
            return predicate instanceof Cmp;
        } else if (dataType == Boolean.class) {
            return predicate == Cmp.EQUAL || predicate == Cmp.NOT_EQUAL;
        } else if (dataType == UUID.class) {
            return predicate == Cmp.EQUAL || predicate==Cmp.NOT_EQUAL;
        }
        return false;
    }
 
Example #2
Source File: Solr6Index.java    From atlas with Apache License 2.0 5 votes vote down vote up
@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 (AttributeUtils.isString(dataType)) {
        return mapping == Mapping.DEFAULT || mapping == Mapping.TEXT || mapping == Mapping.STRING;
    } else if (AttributeUtils.isGeo(dataType)) {
        return mapping == Mapping.DEFAULT || mapping == Mapping.PREFIX_TREE;
    }
    return false;
}
 
Example #3
Source File: Schema.java    From janusgraph_tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * Create the user schema - vertex label, property and index.
 */
private void createUserSchema(){
  LOGGER.info("Create {} schema", USER);
  VertexLabel user = mgt.makeVertexLabel(USER).make();
  PropertyKey userName = mgt.makePropertyKey(USER_NAME).dataType(String.class).make();

  mgt.buildIndex(indexName(USER, USER_NAME), Vertex.class).
      addKey(userName, Mapping.STRING.asParameter()).
      indexOnly(user).
      buildMixedIndex(BACKING_INDEX);
}
 
Example #4
Source File: Schema.java    From janusgraph_tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * Create the statusUpdate schema - vertex label, property and full-text index.
 */
private void createStatusUpdateSchema(){
  LOGGER.info("Create {} schema", STATUS_UPDATE);
  VertexLabel statusUpdate = mgt.makeVertexLabel(STATUS_UPDATE).make();
  PropertyKey content = mgt.makePropertyKey(CONTENT).dataType(String.class).make();

  mgt.buildIndex(indexName(STATUS_UPDATE, CONTENT), Vertex.class).
      addKey(content, Mapping.TEXTSTRING.asParameter()).
      indexOnly(statusUpdate).
      buildMixedIndex(BACKING_INDEX);
}
 
Example #5
Source File: Solr6Index.java    From atlas with Apache License 2.0 4 votes vote down vote up
@Override
public String mapKey2Field(String key, KeyInformation keyInfo) {
    IndexProvider.checkKeyValidity(key);
    key = key.replace(' ', REPLACEMENT_CHAR);

    if (!dynFields) return key;
    if (ParameterType.MAPPED_NAME.hasParameter(keyInfo.getParameters())) return key;
    String postfix;
    final Class dataType = keyInfo.getDataType();
    if (AttributeUtils.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 (AttributeUtils.isWholeNumber(dataType)) {
        if (dataType.equals(Long.class)) postfix = "_l";
        else postfix = "_i";
    } else if (AttributeUtils.isDecimal(dataType)) {
        if (dataType.equals(Float.class)) postfix = "_f";
        else postfix = "_d";
    } else if (dataType.equals(BigInteger.class)) {
        postfix = "_bi";
    } else if (dataType.equals(BigDecimal.class)) {
        postfix = "_bd";
    } 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;
}
 
Example #6
Source File: Solr6Index.java    From atlas with Apache License 2.0 4 votes vote down vote up
private static Mapping getStringMapping(KeyInformation information) {
    assert AttributeUtils.isString(information.getDataType());
    Mapping map = Mapping.getMapping(information);
    if (map==Mapping.DEFAULT) map = Mapping.TEXT;
    return map;
}