public String getMultiValueField() { if (multiValueDefinitionIndex >= 0) return indexDefinitions.get(multiValueDefinitionIndex).getFields().get(0); return null; }
/** * {@inheritDoc} */ public List<String> getFields() { final List<String> fields = new LinkedList<String>(); for (final OIndexDefinition indexDefinition : indexDefinitions) { fields.addAll(indexDefinition.getFields()); } return Collections.unmodifiableList(fields); }
private Object toBetweenIndexKey(OIndexDefinition definition, Object rightValue) { if (definition.getFields().size() == 1 && rightValue instanceof Collection) { rightValue = ((Collection) rightValue).iterator().next(); } rightValue = definition.createValue(rightValue); if (definition.getFields().size() > 1 && !(rightValue instanceof Collection)) { rightValue = Collections.singleton(rightValue); } return rightValue; }
@Override public Collection<OIndex<?>> getAllIndexes() { final Set<OIndex<?>> indexes = owner.getIndexes(); final List<OIndex<?>> indexList = new LinkedList<OIndex<?>>(); for (final OIndex<?> index : indexes) { final OIndexDefinition indexDefinition = index.getDefinition(); if (indexDefinition.getFields().contains(name)) indexList.add(index); } return indexList; }
@Override public OIndexInternal<?> create(OIndexDefinition indexDefinition, String clusterIndexName, Set<String> clustersToIndex, boolean rebuild, OProgressListener progressListener, OBinarySerializer valueSerializer) { if (indexDefinition.getFields().size() > 1) { throw new OIndexException(type + " indexes cannot be used as composite ones."); } return super.create(indexDefinition, clusterIndexName, clustersToIndex, rebuild, progressListener, valueSerializer); }
public Set<String> getIndexedKeys(String className) { Iterator<OIndex<?>> indexes = getIndexManager().getClassIndexes(className).iterator(); HashSet<String> indexedKeys = new HashSet<>(); indexes.forEachRemaining(index -> { index.getDefinition().getFields().forEach(indexedKeys::add); }); return indexedKeys; }
@Override public OIndexMultiValues create(String name, OIndexDefinition indexDefinition, String clusterIndexName, Set<String> clustersToIndex, boolean rebuild, OProgressListener progressListener) { if (indexDefinition.getFields().size() > 1) { throw new OIndexException(type + " indexes cannot be used as composite ones."); } return super.create(name, indexDefinition, clusterIndexName, clustersToIndex, rebuild, progressListener); }
private OLuceneFullTextIndex searchForIndex(String className, OCommandContext ctx, List<String> fieldNames) { OMetadata dbMetadata = ctx.getDatabase().activateOnCurrentThread().getMetadata(); List<OLuceneFullTextIndex> indices = dbMetadata.getSchema().getClass(className).getIndexes().stream() .filter(idx -> idx instanceof OLuceneFullTextIndex).map(idx -> (OLuceneFullTextIndex) idx) .filter(idx -> intersect(idx.getDefinition().getFields(), fieldNames)).collect(Collectors.toList()); if (indices.size() > 1) { throw new IllegalArgumentException("too many indices matching given field name: " + String.join(",", fieldNames)); } return indices.size() == 0 ? null : indices.get(0); }
private void updateFieldToStore(OIndexDefinition indexDefinition) { List<String> fields = indexDefinition.getFields(); for (String field : fields) { OProperty property = indexClass.getProperty(field); if (property.getType().isEmbedded() && property.getLinkedType() != null) { fieldsToStore.put(field, true); } else { fieldsToStore.put(field, false); } } }
public boolean isIndexChain(OCommandContext ctx, OClass clazz) { if (suffix != null && suffix.isBaseIdentifier()) { OProperty prop = clazz.getProperty(suffix.identifier.getStringValue()); if (prop == null) { return false; } Collection<OIndex<?>> allIndexes = prop.getAllIndexes(); return allIndexes != null && allIndexes.stream().anyMatch(idx -> idx.getDefinition().getFields().size() == 1); } return false; } }
@Override public void init(String indexName, String indexType, OIndexDefinition indexDefinition, boolean isAutomatic, ODocument metadata) { if (delegate == null) { if (OClass.INDEX_TYPE.SPATIAL.name().equalsIgnoreCase(indexType)) { if (indexDefinition.getFields().size() > 1) { delegate = new OLuceneLegacySpatialIndexEngine(storage, indexName, OShapeFactory.INSTANCE); } else { delegate = new OLuceneGeoSpatialIndexEngine(storage, indexName, OShapeFactory.INSTANCE); } } delegate.init(indexName, indexType, indexDefinition, isAutomatic, metadata); } }
private List<OIndex<?>> relatedIndexes(final String fieldName) { final List<OIndex<?>> result = new ArrayList<OIndex<?>>(); final ODatabaseDocument database = getDatabase(); for (final OIndex<?> oIndex : database.getMetadata().getIndexManager().getClassIndexes(className)) { if (OCollections.indexOf(oIndex.getDefinition().getFields(), fieldName, new OCaseInsentiveComparator()) > -1) { result.add(oIndex); } } return result; }
private List<OIndex<?>> relatedIndexes(final String fieldName, ODatabase database) { final List<OIndex<?>> result = new ArrayList<OIndex<?>>(); for (final OIndex<?> oIndex : database.getMetadata().getIndexManager().getClassIndexes(className.getStringValue())) { if (OCollections.indexOf(oIndex.getDefinition().getFields(), fieldName, new OCaseInsentiveComparator()) > -1) { result.add(oIndex); } } return result; }
public boolean remove(Object key, OIdentifiable value) { Query query = null; if (isCollectionDelete()) { query = OLuceneIndexType.createDeleteQuery(value, index.getFields(), key); } else { query = OLuceneIndexType.createQueryId(value); } if (query != null) deleteDocument(query); return true; }
@Override public Query deleteQuery(Object key, OIdentifiable value) { updateLastAccess(); openIfClosed(); if (isCollectionDelete()) { return OLuceneIndexType.createDeleteQuery(value, indexDefinition.getFields(), key); } return OLuceneIndexType.createQueryId(value); }
private void checkCollectionIndex(OIndexDefinition indexDefinition) { List<String> fields = indexDefinition.getFields(); OClass aClass = getDatabase().getMetadata().getSchema().getClass(indexDefinition.getClassName()); for (String field : fields) { OProperty property = aClass.getProperty(field); if (property.getType().isEmbedded() && property.getLinkedType() != null) { collectionFields.put(field, true); } else { collectionFields.put(field, false); } } }
private void checkCollectionIndex(OIndexDefinition indexDefinition) { List<String> fields = indexDefinition.getFields(); OClass aClass = getDatabase().getMetadata().getSchema().getClass(indexDefinition.getClassName()); for (String field : fields) { OProperty property = aClass.getProperty(field); if (property.getType().isEmbedded() && property.getLinkedType() != null) { collectionFields.put(field, true); } else { collectionFields.put(field, false); } } }
@Override protected OIndex<?> createInstance(OIndex proxy) { OSchema schema = OrientDbWebSession.get().getDatabase().getMetadata().getSchema(); OClass oClass = schema.getClass(proxy.getDefinition().getClassName()); String name = proxy.getName(); List<String> fields = proxy.getDefinition().getFields(); String type = proxy.getType(); if(name==null) name=oClass.getName()+"."+fields.get(0); ODocument metadata = proxy.getMetadata(); String algorithm = proxy.getAlgorithm(); values.keySet().retainAll(RW_ATTRS); return oClass.createIndex(name, type, null, metadata, algorithm, fields.toArray(new String[0])); }
@Override protected OIndex<?> createInstance(OIndex proxy) { OSchema schema = OrientDbWebSession.get().getDatabase().getMetadata().getSchema(); OClass oClass = schema.getClass(proxy.getDefinition().getClassName()); String name = proxy.getName(); List<String> fields = proxy.getDefinition().getFields(); String type = proxy.getType(); if(name==null) name=oClass.getName()+"."+fields.get(0); ODocument metadata = proxy.getMetadata(); String algorithm = proxy.getAlgorithm(); values.keySet().retainAll(RW_ATTRS); return oClass.createIndex(name, type, null, metadata, algorithm, fields.toArray(new String[0])); }
private void checkIndex(OIndex index) { List<String> fields = index.getDefinition().getFields(); String className = index.getDefinition().getClassName(); OClass clazz = database.getMetadata().getSchema().getClass(className); int[] clusterIds = clazz.getPolymorphicClusterIds(); for (int clusterId : clusterIds) { checkCluster(clusterId, index, fields); } }