private Parameter getStringMapping() { if (indexFeatures.supportsStringMapping(Mapping.STRING)) return Mapping.STRING.asParameter(); else if (indexFeatures.supportsStringMapping(Mapping.TEXTSTRING)) return Mapping.TEXTSTRING.asParameter(); throw new AssertionError("String mapping not supported"); }
public static Mapping getMapping(String store, String key, KeyInformation.IndexRetriever information) { KeyInformation ki = information.get(store, key); Preconditions.checkArgument(ki!=null,"Could not find key information for: %s",key); return getMapping(ki); }
public static Mapping getMapping(KeyInformation information) { Object value = ParameterType.MAPPING.findParameter(information.getParameters(),null); if (value==null) return DEFAULT; else { Preconditions.checkArgument((value instanceof Mapping || value instanceof String),"Invalid mapping specified: %s",value); if (value instanceof String) { value = Mapping.valueOf(value.toString().toUpperCase()); } return (Mapping)value; } }
private static Mapping getStringMapping(KeyInformation information) { assert AttributeUtil.isString(information.getDataType()); Mapping map = Mapping.getMapping(information); if (map==Mapping.DEFAULT) map = Mapping.TEXT; return map; }
private Parameter getTextMapping() { if (indexFeatures.supportsStringMapping(Mapping.TEXT)) return Mapping.TEXT.asParameter(); else if (indexFeatures.supportsStringMapping(Mapping.TEXTSTRING)) return Mapping.TEXTSTRING.asParameter(); throw new AssertionError("Text mapping not supported"); }
private static Mapping getStringMapping(KeyInformation information) { assert AttributeUtil.isString(information.getDataType()); Mapping map = Mapping.getMapping(information); if (map==Mapping.DEFAULT) map = Mapping.TEXT; return map; }
public static Map<String,KeyInformation> getMapping(final IndexFeatures indexFeatures, final String englishAnalyzerName, final String keywordAnalyzerName) { Preconditions.checkArgument(indexFeatures.supportsStringMapping(Mapping.TEXTSTRING) || (indexFeatures.supportsStringMapping(Mapping.TEXT) && indexFeatures.supportsStringMapping(Mapping.STRING)), "Index must support string and text mapping"); final Parameter<?> textParameter = indexFeatures.supportsStringMapping(Mapping.TEXT) ? Mapping.TEXT.asParameter() : Mapping.TEXTSTRING.asParameter(); final Parameter<?> stringParameter = indexFeatures.supportsStringMapping(Mapping.STRING) ? Mapping.STRING.asParameter() : Mapping.TEXTSTRING.asParameter(); return new HashMap<String,KeyInformation>() {{ put(TEXT,new StandardKeyInformation(String.class, Cardinality.SINGLE,textParameter)); put(TIME,new StandardKeyInformation(Long.class, Cardinality.SINGLE)); put(WEIGHT,new StandardKeyInformation(Double.class, Cardinality.SINGLE, Mapping.DEFAULT.asParameter())); put(LOCATION,new StandardKeyInformation(Geoshape.class, Cardinality.SINGLE)); put(BOUNDARY,new StandardKeyInformation(Geoshape.class, Cardinality.SINGLE, Mapping.PREFIX_TREE.asParameter())); put(NAME,new StandardKeyInformation(String.class, Cardinality.SINGLE,stringParameter)); if(indexFeatures.supportsCardinality(Cardinality.LIST)) { put(PHONE_LIST, new StandardKeyInformation(String.class, Cardinality.LIST, stringParameter)); } if(indexFeatures.supportsCardinality(Cardinality.SET)) { put(PHONE_SET, new StandardKeyInformation(String.class, Cardinality.SET, stringParameter)); } put(DATE,new StandardKeyInformation(Instant.class, Cardinality.SINGLE)); put(STRING, new StandardKeyInformation(String.class, Cardinality.SINGLE, stringParameter, new Parameter<>(ParameterType.STRING_ANALYZER.getName(), englishAnalyzerName))); put(ANALYZED, new StandardKeyInformation(String.class, Cardinality.SINGLE, textParameter, new Parameter<>(ParameterType.TEXT_ANALYZER.getName(), englishAnalyzerName))); if(indexFeatures.supportsStringMapping(Mapping.TEXTSTRING)){ put(FULL_TEXT, new StandardKeyInformation(String.class, Cardinality.SINGLE, Mapping.TEXTSTRING.asParameter(), new Parameter<>(ParameterType.STRING_ANALYZER.getName(), englishAnalyzerName), new Parameter<>(ParameterType.TEXT_ANALYZER.getName(), englishAnalyzerName))); } put(KEYWORD, new StandardKeyInformation(String.class, Cardinality.SINGLE, textParameter, new Parameter<>(ParameterType.TEXT_ANALYZER.getName(), keywordAnalyzerName))); }}; }
private String getAdditionScript(KeyInformation.IndexRetriever information, String storeName, IndexMutation mutation) throws PermanentBackendException { final StringBuilder script = new StringBuilder(); for (final IndexEntry e : mutation.getAdditions()) { final KeyInformation keyInformation = information.get(storeName).get(e.field); switch (keyInformation.getCardinality()) { case SET: case LIST: script.append("if(ctx._source[\"").append(e.field).append("\"] == null) ctx._source[\"").append(e.field).append("\"] = [];"); script.append("ctx._source[\"").append(e.field).append("\"].add(").append(convertToJsType(e.value, compat.scriptLang(), Mapping.getMapping(keyInformation))).append(");"); if (hasDualStringMapping(keyInformation)) { script.append("if(ctx._source[\"").append(getDualMappingName(e.field)).append("\"] == null) ctx._source[\"").append(getDualMappingName(e.field)).append("\"] = [];"); script.append("ctx._source[\"").append(getDualMappingName(e.field)).append("\"].add(").append(convertToJsType(e.value, compat.scriptLang(), Mapping.getMapping(keyInformation))).append(");"); } break; default: break; } } return script.toString(); }
if (index.supports(new StandardKeyInformation(String.class, Cardinality.SINGLE, Mapping.STRING.asParameter()), Text.REGEX)) { assertEquals(1, tx.queryStream(new IndexQuery(store, PredicateCondition.of(NAME, Text.REGEX, "Tomo[r]+ow is.*world"))).count()); assertEquals(0, tx.queryStream(new IndexQuery(store, PredicateCondition.of(NAME, Text.REGEX, "Tomorrow"))).count()); assertEquals(ImmutableSet.of("doc1","doc2"), ImmutableSet.copyOf(result)); if (index.supports(new StandardKeyInformation(Geoshape.class, Cardinality.SINGLE, Mapping.PREFIX_TREE.asParameter()), Geo.DISJOINT)) { result = tx.queryStream(new IndexQuery(store, PredicateCondition.of(BOUNDARY, Geo.DISJOINT, Geoshape.box(46.5, -0.5, 50.5, 10.5)))).collect(Collectors.toList()); assertEquals(0,result.size()); if (index.supports(new StandardKeyInformation(String.class, Cardinality.LIST, Mapping.STRING.asParameter()), Cmp.EQUAL)) { assertEquals("doc1", tx.queryStream(new IndexQuery(store, PredicateCondition.of(PHONE_LIST, Cmp.EQUAL, "1"))).findFirst().get()); assertEquals("doc1", tx.queryStream(new IndexQuery(store, PredicateCondition.of(PHONE_LIST, Cmp.EQUAL, "2"))).findFirst().get());
@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; }
final JanusGraphIndex mixed = mgmt.buildIndex("mixed", Vertex.class).addKey(name, Mapping.TEXTSTRING.asParameter()).buildMixedIndex(INDEX); mixed.name(); finishSchema();
@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.STRING || mapping == Mapping.TEXT || mapping == Mapping.TEXTSTRING; } else if (AttributeUtil.isGeo(dataType)) { return mapping == Mapping.DEFAULT || mapping == Mapping.PREFIX_TREE; } return false; }
@Test public void testSetUpdate() { if (!indexFeatures.supportsCardinality(Cardinality.SET)) { return; } final PropertyKey name = makeKey("name", String.class); final PropertyKey alias = mgmt.makePropertyKey("alias").dataType(String.class).cardinality(Cardinality.SET).make(); mgmt.buildIndex("namev", Vertex.class).addKey(name).addKey(alias, indexFeatures.supportsStringMapping(Mapping.TEXTSTRING) ?Mapping.TEXTSTRING.asParameter(): Mapping.DEFAULT.asParameter()).buildMixedIndex(INDEX); finishSchema(); JanusGraphVertex v = tx.addVertex("name", "Marko Rodriguez"); assertCount(1, tx.query().has("name", Text.CONTAINS, "marko").vertices()); clopen(); assertCount(1, tx.query().has("name", Text.CONTAINS, "marko").vertices()); v = getOnlyVertex(tx.query().has("name", Text.CONTAINS, "marko")); v.property(VertexProperty.Cardinality.set, "alias", "Marko"); assertCount(1, tx.query().has("alias", Text.CONTAINS, "Marko").vertices()); clopen(); assertCount(1, tx.query().has("alias", Text.CONTAINS, "Marko").vertices()); v = getOnlyVertex(tx.query().has("name", Text.CONTAINS, "marko")); v.property(VertexProperty.Cardinality.set, "alias", "mRodriguez"); assertCount(1, tx.query().has("alias", Text.CONTAINS, "mRodriguez").vertices()); clopen(); assertCount(1, tx.query().has("alias", Text.CONTAINS, "Marko").vertices()); assertCount(1, tx.query().has("alias", Text.CONTAINS, "mRodriguez").vertices()); if (indexFeatures.supportsStringMapping(Mapping.TEXTSTRING)) { assertCount(1, tx.query().has("alias", Cmp.EQUAL, "Marko").vertices()); assertCount(1, tx.query().has("alias", Cmp.EQUAL, "mRodriguez").vertices()); } }
private Map<String,Object> getAdditionDoc(KeyInformation.IndexRetriever information, String store, IndexMutation mutation) throws PermanentBackendException { final Map<String,Object> doc = new HashMap<>(); for (final IndexEntry e : mutation.getAdditions()) { final KeyInformation keyInformation = information.get(store).get(e.field); if (keyInformation.getCardinality() == Cardinality.SINGLE) { doc.put(e.field, convertToEsType(e.value, Mapping.getMapping(keyInformation))); if (hasDualStringMapping(keyInformation)) { doc.put(getDualMappingName(e.field), convertToEsType(e.value, Mapping.getMapping(keyInformation))); } } } return doc; }
mgmt.buildIndex("namev", Vertex.class).addKey(name).addKey(alias, indexFeatures.supportsStringMapping(Mapping.TEXTSTRING) ?Mapping.TEXTSTRING.asParameter(): Mapping.DEFAULT.asParameter()).buildMixedIndex(INDEX); finishSchema(); JanusGraphVertex v = tx.addVertex("name", "Marko Rodriguez");
case SINGLE: value = convertToEsType(Iterators.getLast(add.getValue().iterator()).value, Mapping.getMapping(keyInformation)); break; case SET: case LIST: value = add.getValue().stream() .map(v -> convertToEsType(v.value, Mapping.getMapping(keyInformation))) .filter(v -> { Preconditions.checkArgument(!(v instanceof byte[]),
mgmt.buildIndex("blablub", Vertex.class).addKey(text, Mapping.TEXT.asParameter()).buildCompositeIndex(); fail(); } catch (IllegalArgumentException ignored) { mgmt.buildIndex("blablub", Vertex.class).addKey(text, Mapping.TEXT.asParameter()).buildCompositeIndex(); fail(); } catch (IllegalArgumentException ignored) {
case SET: case LIST: final String jsValue = convertToJsType(deletion.value, compat.scriptLang(), Mapping.getMapping(keyInformation)); String index = INDEX_NAME + i++; script.append("def ")
/** * 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); }
KeyInformation information) throws AssertionError, PermanentBackendException, BackendException { final Class<?> dataType = information.getDataType(); Mapping map = Mapping.getMapping(information); final Map<String,Object> properties = new HashMap<>(); if (AttributeUtil.isString(dataType)) {