Search in sources :

Example 1 with LuceneIndexReader

use of org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReader in project jackrabbit-oak by apache.

the class IndexNode method createReader.

private IndexReader createReader(List<LuceneIndexReader> nrtReaders) {
    if (readers.size() == 1 && nrtReaders.isEmpty()) {
        return readers.get(0).getReader();
    }
    if (nrtReaders.size() == 1 && readers.isEmpty()) {
        return nrtReaders.get(0).getReader();
    }
    IndexReader[] readerArr = new IndexReader[readers.size() + nrtReaders.size()];
    int i = 0;
    for (LuceneIndexReader r : Iterables.concat(readers, nrtReaders)) {
        readerArr[i++] = r.getReader();
    }
    return new MultiReader(readerArr, true);
}
Also used : LuceneIndexReader(org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReader) MultiReader(org.apache.lucene.index.MultiReader) LuceneIndexReader(org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReader) IndexReader(org.apache.lucene.index.IndexReader)

Example 2 with LuceneIndexReader

use of org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReader in project jackrabbit-oak by apache.

the class NRTIndexTest method getReaderWithoutWriter.

@Test
public void getReaderWithoutWriter() throws Exception {
    IndexDefinition idxDefn = getSyncIndexDefinition("/foo");
    NRTIndex idx1 = indexFactory.createIndex(idxDefn);
    List<LuceneIndexReader> readers = idx1.getReaders();
    assertNotNull(readers);
    assertTrue(readers.isEmpty());
    idx1.close();
    assertTrue(idx1.isClosed());
    //Closing multiple times should not raise exception
    idx1.close();
}
Also used : LuceneIndexReader(org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReader) IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) Test(org.junit.Test)

Example 3 with LuceneIndexReader

use of org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReader in project jackrabbit-oak by apache.

the class IndexNode method open.

static IndexNode open(String indexPath, NodeState root, NodeState defnNodeState, LuceneIndexReaderFactory readerFactory, @Nullable NRTIndexFactory nrtFactory) throws IOException {
    IndexDefinition definition = new IndexDefinition(root, defnNodeState, indexPath);
    List<LuceneIndexReader> readers = readerFactory.createReaders(definition, defnNodeState, indexPath);
    NRTIndex nrtIndex = nrtFactory != null ? nrtFactory.createIndex(definition) : null;
    if (!readers.isEmpty() || (nrtIndex != null && !hasAsyncIndexerRun(root))) {
        return new IndexNode(PathUtils.getName(indexPath), definition, readers, nrtIndex);
    }
    return null;
}
Also used : LuceneIndexReader(org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReader) NRTIndex(org.apache.jackrabbit.oak.plugins.index.lucene.hybrid.NRTIndex)

Example 4 with LuceneIndexReader

use of org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReader in project jackrabbit-oak by apache.

the class IndexNode method refreshReaders.

private void refreshReaders() {
    long start = PERF_LOGGER.start();
    List<LuceneIndexReader> newNRTReaders = getNRTReaders();
    //so if they are same no need to reinitialize the searcher
    if (newNRTReaders != nrtReaders) {
        nrtReaders = newNRTReaders;
        indexSearcher = new IndexSearcher(createReader(nrtReaders));
        PERF_LOGGER.end(start, 0, "Refreshed reader for index [{}]", definition);
    }
}
Also used : LuceneIndexReader(org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReader) IndexSearcher(org.apache.lucene.search.IndexSearcher)

Example 5 with LuceneIndexReader

use of org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReader in project jackrabbit-oak by apache.

the class IndexNode method close.

void close() throws IOException {
    lock.writeLock().lock();
    try {
        checkState(!closed);
        closed = true;
    } finally {
        lock.writeLock().unlock();
    }
    //them
    for (LuceneIndexReader reader : Iterables.concat(readers, nrtReaders)) {
        reader.close();
    }
}
Also used : LuceneIndexReader(org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReader)

Aggregations

LuceneIndexReader (org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReader)9 Test (org.junit.Test)4 IndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition)3 LuceneIndexWriter (org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter)3 NRTIndex (org.apache.jackrabbit.oak.plugins.index.lucene.hybrid.NRTIndex)1 DefaultIndexReaderFactory (org.apache.jackrabbit.oak.plugins.index.lucene.reader.DefaultIndexReaderFactory)1 LuceneIndexReaderFactory (org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReaderFactory)1 LuceneIndexHelper.newLucenePropertyIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition)1 DefaultIndexWriterFactory (org.apache.jackrabbit.oak.plugins.index.lucene.writer.DefaultIndexWriterFactory)1 LuceneIndexWriterFactory (org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriterFactory)1 AbstractQueryTest (org.apache.jackrabbit.oak.query.AbstractQueryTest)1 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)1 QueryIndex (org.apache.jackrabbit.oak.spi.query.QueryIndex)1 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)1 Document (org.apache.lucene.document.Document)1 DirectoryReader (org.apache.lucene.index.DirectoryReader)1 IndexReader (org.apache.lucene.index.IndexReader)1 MultiReader (org.apache.lucene.index.MultiReader)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1