Search in sources :

Example 6 with LuceneIndexReader

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

the class MultiplexingLucenePropertyIndexTest method numDocsIsSumOfAllReaders.

@Test
public void numDocsIsSumOfAllReaders() throws Exception {
    NodeBuilder defnBuilder = newLucenePropertyIndexDefinition(builder, "test", ImmutableSet.of("foo"), "async");
    IndexDefinition defn = new IndexDefinition(initialContent, defnBuilder.getNodeState(), "/foo");
    //1. Have 2 reader created by writes in 2 diff mounts
    LuceneIndexWriterFactory factory = new DefaultIndexWriterFactory(mip, null, null);
    LuceneIndexWriter writer = factory.newInstance(defn, builder, true);
    writer.updateDocument("/content/en", newDoc("/content/en"));
    writer.updateDocument("/libs/config", newDoc("/libs/config"));
    writer.close(0);
    //2. Construct the readers
    LuceneIndexReaderFactory readerFactory = new DefaultIndexReaderFactory(mip, null);
    List<LuceneIndexReader> readers = readerFactory.createReaders(defn, builder.getNodeState(), "/foo");
    IndexNode node = new IndexNode("foo", defn, readers, null);
    //3 Obtain the plan
    FilterImpl filter = createFilter("nt:base");
    filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar"));
    IndexPlanner planner = new IndexPlanner(node, "/foo", filter, Collections.<QueryIndex.OrderEntry>emptyList());
    QueryIndex.IndexPlan plan = planner.getPlan();
    //Count should be sum of both readers
    assertEquals(2, plan.getEstimatedEntryCount());
}
Also used : FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) LuceneIndexWriter(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter) LuceneIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriterFactory) LuceneIndexReaderFactory(org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReaderFactory) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) LuceneIndexReader(org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReader) LuceneIndexHelper.newLucenePropertyIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition) QueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex) DefaultIndexReaderFactory(org.apache.jackrabbit.oak.plugins.index.lucene.reader.DefaultIndexReaderFactory) DefaultIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.writer.DefaultIndexWriterFactory) Test(org.junit.Test) AbstractQueryTest(org.apache.jackrabbit.oak.query.AbstractQueryTest)

Example 7 with LuceneIndexReader

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

the class NRTIndex method getReaders.

/**
     * Returns the list of LuceneIndexReader. If the writer has not received
     * any updates between 2 calls to this method then same list would be
     * returned.
     */
public synchronized List<LuceneIndexReader> getReaders() {
    checkState(!closed);
    DirectoryReader latestReader = createReader();
    //reuse old readers
    if (latestReader == dirReader && readers != null) {
        return readers;
    }
    List<LuceneIndexReader> newReaders = Lists.newArrayListWithCapacity(2);
    if (latestReader != null) {
        newReaders.add(new NRTReader(latestReader, directory));
    }
    //Old reader should be added later
    LuceneIndexReader previousReader = previous != null ? previous.getPrimaryReader() : null;
    if (previousReader != null) {
        newReaders.add(previousReader);
    }
    dirReader = latestReader;
    readers = ImmutableList.copyOf(newReaders);
    return readers;
}
Also used : LuceneIndexReader(org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReader) DirectoryReader(org.apache.lucene.index.DirectoryReader)

Example 8 with LuceneIndexReader

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

the class NRTIndexTest method writerCreation.

@Test
public void writerCreation() throws Exception {
    IndexDefinition idxDefn = getSyncIndexDefinition("/foo");
    NRTIndex idx = indexFactory.createIndex(idxDefn);
    LuceneIndexWriter writer = idx.getWriter();
    assertNotNull(writer);
    assertNotNull(idx.getIndexDir());
    List<LuceneIndexReader> readers = idx.getReaders();
    assertEquals(1, readers.size());
    LuceneIndexWriter writer2 = idx.getWriter();
    assertSame(writer, writer2);
}
Also used : LuceneIndexReader(org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReader) IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) LuceneIndexWriter(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter) Test(org.junit.Test)

Example 9 with LuceneIndexReader

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

the class NRTIndexTest method sameReaderIfNoChange.

@Test
public void sameReaderIfNoChange() throws Exception {
    IndexDefinition idxDefn = getSyncIndexDefinition("/foo");
    NRTIndex idx1 = indexFactory.createIndex(idxDefn);
    LuceneIndexWriter w1 = idx1.getWriter();
    Document d1 = new Document();
    d1.add(newPathField("/a/b"));
    w1.updateDocument("/a/b", d1);
    List<LuceneIndexReader> readers = idx1.getReaders();
    List<LuceneIndexReader> readers2 = idx1.getReaders();
    assertSame(readers, readers2);
    w1.updateDocument("/a/b", d1);
    List<LuceneIndexReader> readers3 = idx1.getReaders();
    assertNotSame(readers2, readers3);
}
Also used : LuceneIndexReader(org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReader) IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) LuceneIndexWriter(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter) Document(org.apache.lucene.document.Document) Test(org.junit.Test)

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