use of org.neo4j.collection.primitive.PrimitiveLongIterator 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.collection.primitive.PrimitiveLongIterator 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.collection.primitive.PrimitiveLongIterator in project neo4j by neo4j.
the class DatabaseCompositeIndexAccessorTest method indexReaderShouldSupportScan.
@Test
public void indexReaderShouldSupportScan() throws Exception {
// GIVEN
updateAndCommit(asList(add(nodeId, values), add(nodeId2, values2)));
IndexReader reader = accessor.newReader();
// WHEN
PrimitiveLongIterator results = reader.query(IndexQuery.exists(PROP_ID1), IndexQuery.exists(PROP_ID2));
// THEN
assertEquals(asSet(nodeId, nodeId2), PrimitiveLongCollections.toSet(results));
assertEquals(asSet(nodeId), PrimitiveLongCollections.toSet(reader.query(IndexQuery.exact(PROP_ID1, values[0]), IndexQuery.exact(PROP_ID2, values[1]))));
reader.close();
}
use of org.neo4j.collection.primitive.PrimitiveLongIterator in project neo4j by neo4j.
the class DatabaseIndexAccessorTest method indexNumberRangeQuery.
@Test
public void indexNumberRangeQuery() throws Exception {
updateAndCommit(asList(add(1, 1), add(2, 2), add(3, 3), add(4, 4), add(5, Double.NaN)));
IndexReader reader = accessor.newReader();
PrimitiveLongIterator rangeTwoThree = reader.query(range(PROP_ID, 2, true, 3, true));
assertThat(PrimitiveLongCollections.asArray(rangeTwoThree), LongArrayMatcher.of(2, 3));
PrimitiveLongIterator infiniteMaxRange = reader.query(range(PROP_ID, 2, true, Long.MAX_VALUE, true));
assertThat(PrimitiveLongCollections.asArray(infiniteMaxRange), LongArrayMatcher.of(2, 3, 4));
PrimitiveLongIterator infiniteMinRange = reader.query(range(PROP_ID, Long.MIN_VALUE, true, 3, true));
assertThat(PrimitiveLongCollections.asArray(infiniteMinRange), LongArrayMatcher.of(PROP_ID, 2, 3));
PrimitiveLongIterator maxNanInterval = reader.query(range(PROP_ID, 3, true, Double.NaN, true));
assertThat(PrimitiveLongCollections.asArray(maxNanInterval), LongArrayMatcher.of(3, 4, 5));
PrimitiveLongIterator minNanInterval = reader.query(range(PROP_ID, Double.NaN, true, 5, true));
assertThat(PrimitiveLongCollections.asArray(minNanInterval), LongArrayMatcher.emptyArrayMatcher());
PrimitiveLongIterator nanInterval = reader.query(range(PROP_ID, Double.NaN, true, Double.NaN, true));
assertThat(PrimitiveLongCollections.asArray(nanInterval), LongArrayMatcher.of(5));
}
use of org.neo4j.collection.primitive.PrimitiveLongIterator in project neo4j by neo4j.
the class DocValuesCollectorTest method shouldReturnDocValuesInIndexOrderWhenNoSortIsGiven.
@Test
public void shouldReturnDocValuesInIndexOrderWhenNoSortIsGiven() throws Exception {
// given
DocValuesCollector collector = new DocValuesCollector(false);
IndexReaderStub readerStub = indexReaderWithMaxDocs(42);
// when
collector.doSetNextReader(readerStub.getContext());
collector.collect(1);
collector.collect(2);
// then
PrimitiveLongIterator valuesIterator = collector.getSortedValuesIterator("id", null);
assertEquals(1, valuesIterator.next());
assertEquals(2, valuesIterator.next());
assertFalse(valuesIterator.hasNext());
}
Aggregations