Search in sources :

Example 6 with DefaultIndexWriterFactory

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

the class AggregateTest method propOneLevelNamedDirect.

@Test
public void propOneLevelNamedDirect() throws Exception {
    IndexDefinitionBuilder builder = new IndexDefinitionBuilder();
    builder.indexRule("nt:folder").property("jcr:content/a").ordered(PropertyType.TYPENAME_LONG).propertyIndex().property("jcr:content/b").ordered(PropertyType.TYPENAME_LONG).propertyIndex();
    IndexDefinition defn = new IndexDefinition(root, builder.build(), "/foo");
    Aggregate ag = defn.getApplicableIndexingRule("nt:folder").getAggregate();
    NodeBuilder nb = newNode("nt:folder");
    nb.child("jcr:content").setProperty("a", 1);
    nb.child("jcr:content").setProperty("b", 1);
    LuceneDocumentMaker maker = new LuceneDocumentMaker(defn, defn.getApplicableIndexingRule("nt:folder"), "/bar");
    Document doc = maker.makeDocument(nb.getNodeState());
    DefaultIndexWriterFactory writerFactory = new DefaultIndexWriterFactory(Mounts.defaultMountInfoProvider(), null, null);
    LuceneIndexWriter writer = writerFactory.newInstance(defn, EMPTY_NODE.builder(), false);
    writer.updateDocument("/bar", doc);
    writer.close(100);
}
Also used : LuceneIndexWriter(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter) IndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder) DefaultIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.writer.DefaultIndexWriterFactory) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Document(org.apache.lucene.document.Document) Test(org.junit.Test)

Example 7 with DefaultIndexWriterFactory

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

use of org.apache.jackrabbit.oak.plugins.index.lucene.writer.DefaultIndexWriterFactory 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)8 LuceneIndexWriter (org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter)7 LuceneIndexWriterFactory (org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriterFactory)7 Test (org.junit.Test)7 Document (org.apache.lucene.document.Document)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 IndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition)2 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)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