Search in sources :

Example 1 with DocValuesCollector

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;
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) DocValuesCollector(org.neo4j.kernel.api.impl.index.collector.DocValuesCollector)

Example 2 with DocValuesCollector

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);
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) NumericDocValues(org.apache.lucene.index.NumericDocValues) Query(org.apache.lucene.search.Query) IndexReaderStub(org.neo4j.kernel.api.impl.index.IndexReaderStub) DocValuesCollector(org.neo4j.kernel.api.impl.index.collector.DocValuesCollector) PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) Test(org.junit.Test)

Example 3 with DocValuesCollector

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);
    }
}
Also used : DocValuesCollector(org.neo4j.kernel.api.impl.index.collector.DocValuesCollector) Sort(org.apache.lucene.search.Sort) SortField(org.apache.lucene.search.SortField) IOException(java.io.IOException)

Example 4 with DocValuesCollector

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);
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) DocValuesCollector(org.neo4j.kernel.api.impl.index.collector.DocValuesCollector) ArrayList(java.util.ArrayList) Sort(org.apache.lucene.search.Sort) IOException(java.io.IOException)

Example 5 with DocValuesCollector

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) {
        }
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) DocValuesCollector(org.neo4j.kernel.api.impl.index.collector.DocValuesCollector) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.apache.lucene.document.Document) LegacyIndexHits(org.neo4j.kernel.api.LegacyIndexHits)

Aggregations

DocValuesCollector (org.neo4j.kernel.api.impl.index.collector.DocValuesCollector)9 IOException (java.io.IOException)5 IndexSearcher (org.apache.lucene.search.IndexSearcher)4 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)4 Sort (org.apache.lucene.search.Sort)3 ArrayList (java.util.ArrayList)2 Document (org.apache.lucene.document.Document)2 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)1 MultiReader (org.apache.lucene.index.MultiReader)1 NumericDocValues (org.apache.lucene.index.NumericDocValues)1 Query (org.apache.lucene.search.Query)1 SortField (org.apache.lucene.search.SortField)1 Test (org.junit.Test)1 PrimitiveLongSet (org.neo4j.collection.primitive.PrimitiveLongSet)1 LongCostume (org.neo4j.index.impl.lucene.legacy.EntityId.LongCostume)1 LegacyIndexHits (org.neo4j.kernel.api.LegacyIndexHits)1 IndexReaderStub (org.neo4j.kernel.api.impl.index.IndexReaderStub)1