use of org.neo4j.kernel.api.impl.index.collector.DocValuesCollector in project neo4j by neo4j.
the class LuceneLegacyIndex method gatherIdsModifiedInTransactionState.
private PrimitiveLongSet gatherIdsModifiedInTransactionState(List<EntityId> simpleTransactionStateIds, IndexSearcher fulltextTransactionStateSearcher, Query query) throws IOException {
// If there's no state them don't bother gathering it
if (simpleTransactionStateIds.isEmpty() && fulltextTransactionStateSearcher == null) {
return PrimitiveLongCollections.emptySet();
}
// There's potentially some state
DocValuesCollector docValuesCollector = null;
int fulltextSize = 0;
if (fulltextTransactionStateSearcher != null) {
docValuesCollector = new DocValuesCollector();
fulltextTransactionStateSearcher.search(query, docValuesCollector);
fulltextSize = docValuesCollector.getTotalHits();
// Nah, no state
if (simpleTransactionStateIds.isEmpty() && fulltextSize == 0) {
return PrimitiveLongCollections.emptySet();
}
}
PrimitiveLongSet set = longSet(simpleTransactionStateIds.size() + fulltextSize);
// Add from simple tx state
for (EntityId id : simpleTransactionStateIds) {
set.add(id.id());
}
if (docValuesCollector != null) {
// Add from fulltext tx state
PrimitiveLongIterator valuesIterator = docValuesCollector.getValuesIterator(LuceneLegacyIndex.KEY_DOC_ID);
while (valuesIterator.hasNext()) {
set.add(valuesIterator.next());
}
}
return set;
}
use of org.neo4j.kernel.api.impl.index.collector.DocValuesCollector in project neo4j by neo4j.
the class PageOfRangesIteratorTest method shouldReadPagesOfDocumentsFromSearcher.
@Test
public void shouldReadPagesOfDocumentsFromSearcher() throws Exception {
final int labelId = 7;
final int pageSize = 2;
// given
Query query = mock(Query.class);
IndexSearcher searcher = mock(IndexSearcher.class);
NumericDocValues rangeNDV = mock(NumericDocValues.class);
when(rangeNDV.get(11)).thenReturn(0x1L);
when(rangeNDV.get(16)).thenReturn(0x2L);
when(rangeNDV.get(37)).thenReturn(0x3L);
NumericDocValues labelNDV = mock(NumericDocValues.class);
when(labelNDV.get(11)).thenReturn(0x01L);
when(labelNDV.get(16)).thenReturn(0x03L);
when(labelNDV.get(37)).thenReturn(0x30L);
Map<String, NumericDocValues> docValues = MapUtil.genericMap("range", rangeNDV, "7", labelNDV);
IndexReaderStub reader = new IndexReaderStub(docValues);
reader.setElements(new String[] { "11", "16", "37" });
final LeafReaderContext context = reader.getContext();
doAnswer(invocation -> {
DocValuesCollector collector = (DocValuesCollector) invocation.getArguments()[1];
collector.doSetNextReader(context);
collector.collect(11);
collector.collect(16);
collector.collect(37);
return null;
}).when(searcher).search(same(query), any(DocValuesCollector.class));
PrimitiveLongIterator iterator = concat(new PageOfRangesIterator(format, searcher, pageSize, query, Occur.MUST, labelId));
// when
List<Long> longs = PrimitiveLongCollections.asList(iterator);
// then
assertEquals(asList(/*doc1:*/
1L << format.bitmapFormat().shift, /*doc2:*/
2L << format.bitmapFormat().shift, (2L << format.bitmapFormat().shift) + 1, /*doc3:*/
(3L << format.bitmapFormat().shift) + 4, (3L << format.bitmapFormat().shift) + 5), longs);
verify(searcher, times(1)).search(same(query), any(DocValuesCollector.class));
verify(rangeNDV, times(6)).get(anyInt());
verify(labelNDV, times(3)).get(anyInt());
verifyNoMoreInteractions(searcher);
verifyNoMoreInteractions(labelNDV);
verifyNoMoreInteractions(rangeNDV);
}
use of org.neo4j.kernel.api.impl.index.collector.DocValuesCollector in project neo4j by neo4j.
the class PageOfRangesIterator method getRanges.
private ValuesIterator getRanges() {
if (rangesIterator != null) {
return rangesIterator;
}
try {
DocValuesCollector docValuesCollector = new DocValuesCollector();
searcher.search(query, docValuesCollector);
rangesIterator = docValuesCollector.getSortedValuesIterator(BitmapDocumentFormat.RANGE, new Sort(new SortField(BitmapDocumentFormat.RANGE, SortField.Type.LONG)));
return rangesIterator;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.neo4j.kernel.api.impl.index.collector.DocValuesCollector in project neo4j by neo4j.
the class FullTxData method internalQuery.
private Collection<EntityId> internalQuery(Query query, QueryContext contextOrNull) {
if (this.directory == null) {
return Collections.emptySet();
}
try {
Sort sorting = contextOrNull != null ? contextOrNull.getSorting() : null;
boolean prioritizeCorrectness = contextOrNull == null || !contextOrNull.getTradeCorrectnessForSpeed();
IndexSearcher theSearcher = searcher(prioritizeCorrectness);
query = includeOrphans(query);
DocValuesCollector docValuesCollector = new DocValuesCollector(prioritizeCorrectness);
theSearcher.search(query, docValuesCollector);
Collection<EntityId> result = new ArrayList<>();
PrimitiveLongIterator valuesIterator = docValuesCollector.getSortedValuesIterator(KEY_DOC_ID, sorting);
while (valuesIterator.hasNext()) {
result.add(new EntityId.IdData(valuesIterator.next()));
}
return result;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.neo4j.kernel.api.impl.index.collector.DocValuesCollector 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