use of org.neo4j.kernel.api.LegacyIndexHits in project neo4j by neo4j.
the class LuceneLegacyIndex method query.
protected LegacyIndexHits query(Query query, String keyForDirectLookup, Object valueForDirectLookup, QueryContext additionalParametersOrNull) {
List<EntityId> simpleTransactionStateIds = new ArrayList<>();
Collection<EntityId> removedIdsFromTransactionState = Collections.emptySet();
IndexSearcher fulltextTransactionStateSearcher = null;
if (transaction != null) {
if (keyForDirectLookup != null) {
simpleTransactionStateIds.addAll(transaction.getAddedIds(this, keyForDirectLookup, valueForDirectLookup));
} else {
fulltextTransactionStateSearcher = transaction.getAdditionsAsSearcher(this, additionalParametersOrNull);
}
removedIdsFromTransactionState = 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) {
try {
// Gather all added ids from fulltextTransactionStateSearcher and simpleTransactionStateIds.
PrimitiveLongSet idsModifiedInTransactionState = gatherIdsModifiedInTransactionState(simpleTransactionStateIds, fulltextTransactionStateSearcher, query);
// Do the combined search from store and fulltext tx state
DocToIdIterator hits = new DocToIdIterator(search(searcher, fulltextTransactionStateSearcher, query, additionalParametersOrNull, removedIdsFromTransactionState), removedIdsFromTransactionState, searcher, idsModifiedInTransactionState);
idIterator = simpleTransactionStateIds.isEmpty() ? hits : new CombinedIndexHits(Arrays.<LegacyIndexHits>asList(hits, new ConstantScoreIterator(simpleTransactionStateIds, Float.NaN)));
} catch (IOException e) {
throw new RuntimeException("Unable to query " + this + " with " + query, e);
}
}
// We've only got transaction state
idIterator = idIterator == null ? new ConstantScoreIterator(simpleTransactionStateIds, 0) : idIterator;
return idIterator;
}
use of org.neo4j.kernel.api.LegacyIndexHits in project neo4j by neo4j.
the class LuceneBatchInserterIndex method query.
private IndexHits<Long> query(Query query, final String key, final Object value) {
IndexSearcher searcher;
try {
searcher = searcherManager.acquire();
} catch (IOException e) {
throw new RuntimeException(e);
}
try {
DocValuesCollector collector = new DocValuesCollector(true);
searcher.search(query, collector);
IndexHits<Document> result = collector.getIndexHits(Sort.RELEVANCE);
LegacyIndexHits primitiveHits = null;
if (key == null || this.cache == null || !this.cache.containsKey(key)) {
primitiveHits = new DocToIdIterator(result, Collections.<EntityId>emptyList(), null, PrimitiveLongCollections.emptySet());
} else {
primitiveHits = new DocToIdIterator(result, Collections.<EntityId>emptyList(), null, PrimitiveLongCollections.emptySet()) {
private final Collection<EntityId> ids = new ArrayList<>();
@Override
protected boolean fetchNext() {
if (super.fetchNext()) {
ids.add(new EntityId.IdData(next));
return true;
}
addToCache(ids, key, value);
return false;
}
};
}
return wrapIndexHits(primitiveHits);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
try {
searcherManager.release(searcher);
} catch (IOException ignore) {
}
}
}
Aggregations