ElasticSearchIndex implements IndexProvider { @Override public boolean supports(KeyInformation information, TitanPredicate titanPredicate) { Class<?> dataType = information.getDataType(); Mapping mapping = Mapping.getMapping(information); if (mapping!=Mapping.DEFAULT && !AttributeUtil.isString(dataType)) return false; if (Number.class.isAssignableFrom(dataType)) { if (titanPredicate instanceof Cmp) return true; } else if (dataType == Geoshape.class) { return titanPredicate == Geo.WITHIN; } else if (AttributeUtil.isString(dataType)) { switch(mapping) { case DEFAULT: case TEXT: return titanPredicate == Text.CONTAINS || titanPredicate == Text.CONTAINS_PREFIX || titanPredicate == Text.CONTAINS_REGEX; case STRING: return titanPredicate == Cmp.EQUAL || titanPredicate==Cmp.NOT_EQUAL || titanPredicate==Text.REGEX || titanPredicate==Text.PREFIX; case TEXTSTRING: return (titanPredicate instanceof Text) || titanPredicate == Cmp.EQUAL || titanPredicate==Cmp.NOT_EQUAL; } } else if (dataType == Date.class || dataType == Instant.class) { if (titanPredicate instanceof Cmp) return true; } else if (dataType == Boolean.class) { return titanPredicate == Cmp.EQUAL || titanPredicate == Cmp.NOT_EQUAL; } else if (dataType == UUID.class) { return titanPredicate == Cmp.EQUAL || titanPredicate==Cmp.NOT_EQUAL; } return false; } ElasticSearchIndex(Configuration config); @Override void register(String store, String key, KeyInformation information, BaseTransaction tx); XContentBuilder getNewDocument(final List<IndexEntry> additions, KeyInformation.StoreRetriever informations, int ttl); @Override void mutate(Map<String, Map<String, IndexMutation>> mutations, KeyInformation.IndexRetriever informations, BaseTransaction tx); void restore(Map<String,Map<String, List<IndexEntry>>> documents, KeyInformation.IndexRetriever informations, BaseTransaction tx); FilterBuilder getFilter(Condition<?> condition, KeyInformation.StoreRetriever informations); @Override List<String> query(IndexQuery query, KeyInformation.IndexRetriever informations, BaseTransaction tx); @Override Iterable<RawQuery.Result<String>> query(RawQuery query, KeyInformation.IndexRetriever informations, BaseTransaction tx); @Override boolean supports(KeyInformation information, TitanPredicate titanPredicate); @Override boolean supports(KeyInformation information); @Override String mapKey2Field(String key, KeyInformation information); @Override IndexFeatures getFeatures(); @Override BaseTransactionConfigurable beginTransaction(BaseTransactionConfig config); @Override void close(); @Override void clearStorage(); static final ImmutableList<String> DATA_SUBDIRS; static final ConfigNamespace ELASTICSEARCH_NS; static final ConfigOption<Boolean> CLIENT_ONLY; static final ConfigOption<String> CLUSTER_NAME; static final ConfigOption<Boolean> LOCAL_MODE; static final ConfigOption<Boolean> CLIENT_SNIFF; static final ConfigOption<String> INTERFACE; static final ConfigOption<Boolean> IGNORE_CLUSTER_NAME; static final ConfigOption<String> TTL_INTERVAL; static final ConfigOption<String> HEALTH_REQUEST_TIMEOUT; static final ConfigOption<Boolean> LOAD_DEFAULT_NODE_SETTINGS; static final ConfigOption<Boolean> USE_EDEPRECATED_IGNORE_UNMAPPED_OPTION; static final ConfigNamespace ES_EXTRAS_NS; static final ConfigNamespace ES_CREATE_NS; static final ConfigOption<Long> CREATE_SLEEP; static final ConfigNamespace ES_CREATE_EXTRAS_NS; static final int HOST_PORT_DEFAULT; }
@Test public void testSupport() { assertTrue(index.supports(of(String.class, Cardinality.SINGLE), Text.CONTAINS)); assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.TEXT)), Text.CONTAINS_PREFIX)); assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.TEXT)), Text.CONTAINS_REGEX)); assertFalse(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.TEXT)), Text.REGEX)); assertFalse(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.STRING)), Text.CONTAINS)); assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.STRING)), Text.PREFIX)); assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.STRING)), Text.REGEX)); assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.STRING)), Cmp.EQUAL)); assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.STRING)), Cmp.NOT_EQUAL)); assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.EQUAL)); assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.LESS_THAN_EQUAL)); assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.LESS_THAN)); assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.GREATER_THAN)); assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.GREATER_THAN_EQUAL)); assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.NOT_EQUAL)); assertTrue(index.supports(of(Boolean.class, Cardinality.SINGLE), Cmp.EQUAL)); assertTrue(index.supports(of(Boolean.class, Cardinality.SINGLE), Cmp.NOT_EQUAL)); assertTrue(index.supports(of(UUID.class, Cardinality.SINGLE), Cmp.EQUAL)); assertTrue(index.supports(of(UUID.class, Cardinality.SINGLE), Cmp.NOT_EQUAL)); }