Search in sources :

Example 6 with LuceneIndexWriterFactory

use of org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriterFactory 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 7 with LuceneIndexWriterFactory

use of org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriterFactory 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

DefaultIndexWriterFactory (org.apache.jackrabbit.oak.plugins.index.lucene.writer.DefaultIndexWriterFactory)7 LuceneIndexWriterFactory (org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriterFactory)7 LuceneIndexWriter (org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter)6 Test (org.junit.Test)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 IndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition)2 Document (org.apache.lucene.document.Document)2 StringField (org.apache.lucene.document.StringField)2 IndexReader (org.apache.lucene.index.IndexReader)2 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 ContextAwareCallback (org.apache.jackrabbit.oak.plugins.index.ContextAwareCallback)1 IndexingContext (org.apache.jackrabbit.oak.plugins.index.IndexingContext)1 BlobDeletionCallback (org.apache.jackrabbit.oak.plugins.index.lucene.directory.ActiveDeletedBlobCollectorFactory.BlobDeletionCallback)1 LocalIndexWriterFactory (org.apache.jackrabbit.oak.plugins.index.lucene.hybrid.LocalIndexWriterFactory)1 DefaultIndexReaderFactory (org.apache.jackrabbit.oak.plugins.index.lucene.reader.DefaultIndexReaderFactory)1 LuceneIndexReader (org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReader)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