SolrIndex 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(information.getCardinality() != Cardinality.SINGLE) { return false; } if (Number.class.isAssignableFrom(dataType)) { return titanPredicate instanceof Cmp; } 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; } } 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; } SolrIndex(final Configuration config); @Override void register(String store, String key, KeyInformation information, BaseTransaction tx); @Override void mutate(Map<String, Map<String, IndexMutation>> mutations, KeyInformation.IndexRetriever informations, BaseTransaction tx); @Override void restore(Map<String, Map<String, List<IndexEntry>>> documents, KeyInformation.IndexRetriever informations, BaseTransaction tx); @Override List<String> query(IndexQuery query, KeyInformation.IndexRetriever informations, BaseTransaction tx); @Override Iterable<RawQuery.Result<String>> query(RawQuery query, KeyInformation.IndexRetriever informations, BaseTransaction tx); String buildQueryFilter(Condition<TitanElement> condition, KeyInformation.StoreRetriever informations); @Override BaseTransactionConfigurable beginTransaction(BaseTransactionConfig config); @Override void close(); @Override void clearStorage(); @Override boolean supports(KeyInformation information, TitanPredicate titanPredicate); @Override boolean supports(KeyInformation information); @Override String mapKey2Field(String key, KeyInformation keyInfo); @Override IndexFeatures getFeatures(); static final ConfigNamespace SOLR_NS; static final ConfigOption<String> SOLR_MODE; static final ConfigOption<Boolean> DYNAMIC_FIELDS; static final ConfigOption<String[]> KEY_FIELD_NAMES; static final ConfigOption<String> TTL_FIELD; static final ConfigOption<String> ZOOKEEPER_URL; static final ConfigOption<Integer> NUM_SHARDS; static final ConfigOption<Integer> MAX_SHARDS_PER_NODE; static final ConfigOption<Integer> REPLICATION_FACTOR; static final ConfigOption<String> SOLR_DEFAULT_CONFIG; static final ConfigOption<String[]> HTTP_URLS; static final ConfigOption<Integer> HTTP_CONNECTION_TIMEOUT; static final ConfigOption<Boolean> HTTP_ALLOW_COMPRESSION; static final ConfigOption<Integer> HTTP_MAX_CONNECTIONS_PER_HOST; static final ConfigOption<Integer> HTTP_GLOBAL_MAX_CONNECTIONS; static final ConfigOption<Boolean> WAIT_SEARCHER; }
@Test public void testSupport() { assertTrue(index.supports(of(String.class, Cardinality.SINGLE))); assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.TEXT)))); assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.STRING)))); assertFalse(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.TEXTSTRING)))); assertTrue(index.supports(of(Double.class, Cardinality.SINGLE))); assertFalse(index.supports(of(Double.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.TEXT)))); assertTrue(index.supports(of(Long.class, Cardinality.SINGLE))); assertTrue(index.supports(of(Long.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.DEFAULT)))); assertTrue(index.supports(of(Integer.class, Cardinality.SINGLE))); assertTrue(index.supports(of(Short.class, Cardinality.SINGLE))); assertTrue(index.supports(of(Byte.class, Cardinality.SINGLE))); assertTrue(index.supports(of(Float.class, Cardinality.SINGLE))); assertTrue(index.supports(of(Geoshape.class, Cardinality.SINGLE))); assertFalse(index.supports(of(Object.class, Cardinality.SINGLE))); assertFalse(index.supports(of(Exception.class, Cardinality.SINGLE))); assertTrue(index.supports(of(String.class, Cardinality.SINGLE), Text.CONTAINS)); assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.DEFAULT)), 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.TEXTSTRING)), Text.REGEX)); assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.TEXT)), Text.CONTAINS)); assertFalse(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.DEFAULT)), Text.PREFIX)); 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)); assertFalse(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.TEXTSTRING)), Cmp.NOT_EQUAL)); assertTrue(index.supports(of(Double.class, Cardinality.SINGLE), Cmp.EQUAL)); assertTrue(index.supports(of(Double.class, Cardinality.SINGLE), Cmp.GREATER_THAN_EQUAL)); assertTrue(index.supports(of(Double.class, Cardinality.SINGLE), Cmp.LESS_THAN)); assertTrue(index.supports(of(Double.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.DEFAULT)), Cmp.LESS_THAN)); assertFalse(index.supports(of(Double.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.TEXT)), Cmp.LESS_THAN)); assertTrue(index.supports(of(Geoshape.class, Cardinality.SINGLE), Geo.WITHIN)); assertFalse(index.supports(of(Double.class, Cardinality.SINGLE), Geo.INTERSECT)); assertFalse(index.supports(of(Long.class, Cardinality.SINGLE), Text.CONTAINS)); assertFalse(index.supports(of(Geoshape.class, Cardinality.SINGLE), Geo.DISJOINT)); 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)); }