Java Code Examples for com.orientechnologies.orient.core.index.OIndex#remove()

The following examples show how to use com.orientechnologies.orient.core.index.OIndex#remove() . 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: OLuceneClassIndexManager.java    From orientdb-lucene with Apache License 2.0 5 votes vote down vote up
private static void processSingleIndexUpdate(final OIndex<?> index, final Set<String> dirtyFields, final ODocument iRecord) {
  final OIndexDefinition indexDefinition = index.getDefinition();
  final List<String> indexFields = indexDefinition.getFields();

  if (indexFields.isEmpty())
    return;

  final String indexField = indexFields.get(0);
  if (!dirtyFields.contains(indexField))
    return;

  final OMultiValueChangeTimeLine<?, ?> multiValueChangeTimeLine = iRecord.getCollectionTimeLine(indexField);
  if (multiValueChangeTimeLine != null) {
    final OIndexDefinitionMultiValue indexDefinitionMultiValue = (OIndexDefinitionMultiValue) indexDefinition;
    final Map<Object, Integer> keysToAdd = new HashMap<Object, Integer>();
    final Map<Object, Integer> keysToRemove = new HashMap<Object, Integer>();

    for (OMultiValueChangeEvent<?, ?> changeEvent : multiValueChangeTimeLine.getMultiValueChangeEvents()) {
      indexDefinitionMultiValue.processChangeEvent(changeEvent, keysToAdd, keysToRemove);
    }

    for (final Object keyToRemove : keysToRemove.keySet())
      index.remove(keyToRemove, iRecord);

    for (final Object keyToAdd : keysToAdd.keySet())
      index.put(keyToAdd, iRecord.placeholder());

  } else {
    final Object origValue = indexDefinition.createValue(iRecord.getOriginalValue(indexField));
    final Object newValue = indexDefinition.getDocumentValueToIndex(iRecord);

    processIndexUpdateFieldAssignment(index, iRecord, origValue, newValue);
  }
}
 
Example 2
Source File: OLuceneClassIndexManager.java    From orientdb-lucene with Apache License 2.0 5 votes vote down vote up
private static void processIndexUpdateFieldAssignment(OIndex<?> index, ODocument iRecord, final Object origValue,
    final Object newValue) {
  if ((origValue instanceof Collection) && (newValue instanceof Collection)) {
    final Set<Object> valuesToRemove = new HashSet<Object>((Collection<?>) origValue);
    final Set<Object> valuesToAdd = new HashSet<Object>((Collection<?>) newValue);

    valuesToRemove.removeAll((Collection<?>) newValue);
    valuesToAdd.removeAll((Collection<?>) origValue);

    for (final Object valueToRemove : valuesToRemove) {
      if (valueToRemove != null) {
        index.remove(valueToRemove, iRecord);
      }
    }

    for (final Object valueToAdd : valuesToAdd) {
      if (valueToAdd != null) {
        index.put(valueToAdd, iRecord);
      }
    }
  } else {
    deleteIndexKey(index, iRecord, origValue);

    if (newValue instanceof Collection) {
      for (final Object newValueItem : (Collection<?>) newValue) {
        index.put(newValueItem, iRecord.placeholder());
      }
    } else if (newValue != null) {
      index.put(newValue, iRecord.placeholder());
    }
  }
}
 
Example 3
Source File: OLuceneClassIndexManager.java    From orientdb-lucene with Apache License 2.0 5 votes vote down vote up
private static void deleteIndexKey(final OIndex<?> index, final ODocument iRecord, final Object origValue) {
  if (origValue instanceof Collection) {
    for (final Object valueItem : (Collection<?>) origValue) {
      if (valueItem != null)
        index.remove(valueItem, iRecord);
    }
  } else if (origValue != null) {
    index.remove(origValue, iRecord);
  }
}