Example #1
0
  protected LegacyIndexHits query(
      Query query,
      String keyForDirectLookup,
      Object valueForDirectLookup,
      QueryContext additionalParametersOrNull) {
    List<Long> ids = new ArrayList<>();
    Collection<Long> removedIds = Collections.emptySet();
    IndexSearcher additionsSearcher = null;
    if (transaction != null) {
      if (keyForDirectLookup != null) {
        ids.addAll(transaction.getAddedIds(this, keyForDirectLookup, valueForDirectLookup));
      } else {
        additionsSearcher = transaction.getAdditionsAsSearcher(this, additionalParametersOrNull);
      }
      removedIds =
          keyForDirectLookup != null
              ? transaction.getRemovedIds(this, keyForDirectLookup, valueForDirectLookup)
              : transaction.getRemovedIds(this, query);
    }
    LegacyIndexHits idIterator = null;
    IndexReference searcher = null;
    dataSource.getReadLock();
    try {
      searcher = dataSource.getIndexSearcher(identifier);
    } finally {
      dataSource.releaseReadLock();
    }

    if (searcher != null) {
      boolean foundInCache = false;
      LruCache<String, Collection<Long>> cachedIdsMap = null;
      if (keyForDirectLookup != null) {
        cachedIdsMap = dataSource.getFromCache(identifier, keyForDirectLookup);
        foundInCache =
            fillFromCache(cachedIdsMap, ids, valueForDirectLookup.toString(), removedIds);
      }

      if (!foundInCache) {
        DocToIdIterator searchedIds =
            new DocToIdIterator(
                search(searcher, query, additionalParametersOrNull, additionsSearcher, removedIds),
                removedIds,
                searcher);
        if (ids.isEmpty()) {
          idIterator = searchedIds;
        } else {
          Collection<LegacyIndexHits> iterators = new ArrayList<>();
          iterators.add(searchedIds);
          iterators.add(new ConstantScoreIterator(ids, Float.NaN));
          idIterator = new CombinedIndexHits(iterators);
        }
      }
    }

    idIterator = idIterator == null ? new ConstantScoreIterator(ids, 0) : idIterator;
    return idIterator;
  }
Example #2
0
 /**
  * See {@link Index#add(PropertyContainer, String, Object)} for more generic documentation.
  *
  * <p>Adds key/value to the {@code entity} in this index. Added values are searchable within the
  * transaction, but composite {@code AND} queries aren't guaranteed to return added values
  * correctly within that transaction. When the transaction has been committed all such queries are
  * guaranteed to return correct results.
  *
  * @param key the key in the key/value pair to associate with the entity.
  * @param value the value in the key/value pair to associate with the entity.
  */
 @Override
 public void addNode(long entityId, String key, Object value) {
   assertValidKey(key);
   for (Object oneValue : IoPrimitiveUtils.asArray(value)) {
     oneValue = getCorrectValue(oneValue);
     transaction.add(this, entityId, key, oneValue);
     commandFactory.addNode(identifier.indexName, entityId, key, oneValue);
   }
 }
Example #3
0
 /**
  * See {@link Index#remove(PropertyContainer, String, Object)} for more generic documentation.
  *
  * <p>Removes key/value to the {@code entity} in this index. Removed values are excluded within
  * the transaction, but composite {@code AND} queries aren't guaranteed to exclude removed values
  * correctly within that transaction. When the transaction has been committed all such queries are
  * guaranteed to return correct results.
  *
  * @param entity the entity (i.e {@link Node} or {@link Relationship}) to dissociate the key/value
  *     pair from.
  * @param key the key in the key/value pair to dissociate from the entity.
  * @param value the value in the key/value pair to dissociate from the entity.
  */
 @Override
 public void remove(long entity, String key, Object value) {
   assertValidKey(key);
   for (Object oneValue : IoPrimitiveUtils.asArray(value)) {
     oneValue = getCorrectValue(oneValue);
     transaction.remove(this, entity, key, oneValue);
     addRemoveCommand(entity, key, oneValue);
   }
 }
Example #4
0
  @Override
  Collection<Long> getOrphans(String key) {
    if (!hasOrphans) {
      return null;
    }

    Set<Object> orphans = idCollection(null, null, false);
    Set<Object> keyOrphans = idCollection(key, null, false);
    Collection<Long> orphanLongs = orphans != null ? toLongs(orphans) : null;
    Collection<Long> keyOrphanLongs = keyOrphans != null ? toLongs(keyOrphans) : null;
    return LuceneTransactionState.merge(orphanLongs, keyOrphanLongs);
  }
 @Override
 public void close() {
   luceneTransaction.close();
 }
Example #6
0
 @Override
 public void drop() {
   transaction.delete(this);
 }
Example #7
0
 @Override
 public void remove(long entity) {
   transaction.remove(this, entity);
   addRemoveCommand(entity, null, null);
 }
Example #8
0
 @Override
 public void remove(long entity, String key) {
   assertValidKey(key);
   transaction.remove(this, entity, key);
   addRemoveCommand(entity, key, null);
 }