Search in sources :

Example 11 with LuceneIndexWriter

use of org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter in project jackrabbit-oak by apache.

the class NRTIndexTest method dirDeletedUponClose.

@Test
public void dirDeletedUponClose() throws Exception {
    IndexDefinition idxDefn = getSyncIndexDefinition("/foo");
    NRTIndex idx = indexFactory.createIndex(idxDefn);
    LuceneIndexWriter writer = idx.getWriter();
    File indexDir = idx.getIndexDir();
    assertTrue(indexDir.exists());
    idx.close();
    assertFalse(indexDir.exists());
    try {
        idx.getReaders();
        fail();
    } catch (IllegalStateException ignore) {
    }
    try {
        idx.getWriter();
        fail();
    } catch (IllegalStateException ignore) {
    }
}
Also used : IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) LuceneIndexWriter(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter) File(java.io.File) Test(org.junit.Test)

Example 12 with LuceneIndexWriter

use of org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter in project jackrabbit-oak by apache.

the class NRTIndexTest method multipleUpdateForSamePath.

@Test
public void multipleUpdateForSamePath() throws Exception {
    IndexDefinition idxDefn = getSyncIndexDefinition("/foo");
    NRTIndex idx = indexFactory.createIndex(idxDefn);
    LuceneIndexWriter writer = idx.getWriter();
    Document document = new Document();
    document.add(newPathField("/a/b"));
    writer.updateDocument("/a/b", document);
    assertEquals(1, idx.getPrimaryReader().getReader().numDocs());
    writer.updateDocument("/a/b", document);
    //Update for same path should not lead to deletion
    assertEquals(2, idx.getPrimaryReader().getReader().numDocs());
    assertEquals(0, idx.getPrimaryReader().getReader().numDeletedDocs());
}
Also used : 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)

Example 13 with LuceneIndexWriter

use of org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter in project jackrabbit-oak by apache.

the class DefaultIndexReaderFactoryTest method indexDir.

@Test
public void indexDir() throws Exception {
    LuceneIndexWriterFactory factory = new DefaultIndexWriterFactory(mip, null, null);
    LuceneIndexWriter writer = factory.newInstance(defn, builder, true);
    writer.updateDocument("/content/en", newDoc("/content/en"));
    writer.close(0);
    LuceneIndexReaderFactory readerFactory = new DefaultIndexReaderFactory(mip, null);
    List<LuceneIndexReader> readers = readerFactory.createReaders(defn, builder.getNodeState(), "/foo");
    assertEquals(1, readers.size());
    LuceneIndexReader reader = readers.get(0);
    assertNotNull(reader.getReader());
    assertNull(reader.getSuggestDirectory());
    assertNull(reader.getLookup());
    assertEquals(1, reader.getReader().numDocs());
    final AtomicBoolean closed = new AtomicBoolean();
    reader.getReader().addReaderClosedListener(new IndexReader.ReaderClosedListener() {

        @Override
        public void onClose(IndexReader reader) {
            closed.set(true);
        }
    });
    reader.close();
    assertTrue(closed.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LuceneIndexWriter(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter) IndexReader(org.apache.lucene.index.IndexReader) LuceneIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriterFactory) DefaultIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.writer.DefaultIndexWriterFactory) Test(org.junit.Test)

Example 14 with LuceneIndexWriter

use of org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter in project jackrabbit-oak by apache.

the class DefaultIndexReaderFactoryTest method indexDirWithBlobStore.

@Test
public void indexDirWithBlobStore() throws Exception {
    /* Register a blob store */
    CachingFileDataStore ds = DataStoreUtils.createCachingFDS(folder.newFolder().getAbsolutePath(), folder.newFolder().getAbsolutePath());
    LuceneIndexWriterFactory factory = new DefaultIndexWriterFactory(mip, null, new DataStoreBlobStore(ds));
    LuceneIndexWriter writer = factory.newInstance(defn, builder, true);
    writer.updateDocument("/content/en", newDoc("/content/en"));
    writer.close(0);
    LuceneIndexReaderFactory readerFactory = new DefaultIndexReaderFactory(mip, null);
    List<LuceneIndexReader> readers = readerFactory.createReaders(defn, builder.getNodeState(), "/foo");
    assertEquals(1, readers.size());
    LuceneIndexReader reader = readers.get(0);
    assertNotNull(reader.getReader());
    assertNull(reader.getSuggestDirectory());
    assertNull(reader.getLookup());
    assertEquals(1, reader.getReader().numDocs());
    final AtomicBoolean closed = new AtomicBoolean();
    reader.getReader().addReaderClosedListener(new IndexReader.ReaderClosedListener() {

        @Override
        public void onClose(IndexReader reader) {
            closed.set(true);
        }
    });
    reader.close();
    assertTrue(closed.get());
}
Also used : LuceneIndexWriter(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter) CachingFileDataStore(org.apache.jackrabbit.oak.plugins.blob.datastore.CachingFileDataStore) LuceneIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriterFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IndexReader(org.apache.lucene.index.IndexReader) DefaultIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.writer.DefaultIndexWriterFactory) DataStoreBlobStore(org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore) Test(org.junit.Test)

Aggregations

LuceneIndexWriter (org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter)14 Test (org.junit.Test)12 IndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition)7 DefaultIndexWriterFactory (org.apache.jackrabbit.oak.plugins.index.lucene.writer.DefaultIndexWriterFactory)7 LuceneIndexWriterFactory (org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriterFactory)6 Document (org.apache.lucene.document.Document)6 LuceneIndexReader (org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReader)3 IOException (java.io.IOException)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)2 StringField (org.apache.lucene.document.StringField)2 IndexReader (org.apache.lucene.index.IndexReader)2 File (java.io.File)1 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)1 CachingFileDataStore (org.apache.jackrabbit.oak.plugins.blob.datastore.CachingFileDataStore)1 DataStoreBlobStore (org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore)1 PathFilter (org.apache.jackrabbit.oak.plugins.index.PathFilter)1 IndexNode (org.apache.jackrabbit.oak.plugins.index.lucene.IndexNode)1 DefaultIndexReaderFactory (org.apache.jackrabbit.oak.plugins.index.lucene.reader.DefaultIndexReaderFactory)1 LuceneIndexReaderFactory (org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReaderFactory)1