Search in sources :

Example 1 with DefaultDirectoryFactory

use of org.apache.jackrabbit.oak.plugins.index.lucene.directory.DefaultDirectoryFactory in project jackrabbit-oak by apache.

the class MultiplexingIndexWriterTest method writesInDefaultMountBlobStore.

@Test
public void writesInDefaultMountBlobStore() throws Exception {
    CachingFileDataStore ds = DataStoreUtils.createCachingFDS(folder.newFolder().getAbsolutePath(), folder.newFolder().getAbsolutePath());
    DirectoryFactory directoryFactory = new DefaultDirectoryFactory(null, new DataStoreBlobStore(ds));
    LuceneIndexWriterFactory factory = new DefaultIndexWriterFactory(mip, directoryFactory, writerConfig);
    LuceneIndexWriter writer = factory.newInstance(defn, builder, true);
    // 1. Add entry in foo mount
    writer.updateDocument("/libs/config", newDoc("/libs/config"));
    writer.close(0);
    List<String> names = getIndexDirNodes();
    // Only dirNode for mount foo should be present
    assertThat(names, contains(indexDirName(fooMount)));
    // 2. Add entry in default mount
    writer = factory.newInstance(defn, builder, true);
    writer.updateDocument("/content", newDoc("/content"));
    writer.close(0);
    names = getIndexDirNodes();
    // Dir names for both mounts should be present
    assertThat(names, containsInAnyOrder(indexDirName(fooMount), indexDirName(defaultMount)));
}
Also used : DirectoryFactory(org.apache.jackrabbit.oak.plugins.index.lucene.directory.DirectoryFactory) DefaultDirectoryFactory(org.apache.jackrabbit.oak.plugins.index.lucene.directory.DefaultDirectoryFactory) CachingFileDataStore(org.apache.jackrabbit.oak.plugins.blob.datastore.CachingFileDataStore) DefaultDirectoryFactory(org.apache.jackrabbit.oak.plugins.index.lucene.directory.DefaultDirectoryFactory) DataStoreBlobStore(org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore) Test(org.junit.Test)

Example 2 with DefaultDirectoryFactory

use of org.apache.jackrabbit.oak.plugins.index.lucene.directory.DefaultDirectoryFactory in project jackrabbit-oak by apache.

the class LuceneIndexTest method getDeletedDocCount.

public int getDeletedDocCount(NodeBuilder idx, IndexDefinition definition) throws IOException {
    Directory dir = new DefaultDirectoryFactory(null, null).newInstance(definition, idx, LuceneIndexConstants.INDEX_DATA_CHILD_NAME, false);
    IndexReader reader = DirectoryReader.open(dir);
    int numDeletes = reader.numDeletedDocs();
    reader.close();
    return numDeletes;
}
Also used : IndexReader(org.apache.lucene.index.IndexReader) DefaultDirectoryFactory(org.apache.jackrabbit.oak.plugins.index.lucene.directory.DefaultDirectoryFactory) Directory(org.apache.lucene.store.Directory)

Example 3 with DefaultDirectoryFactory

use of org.apache.jackrabbit.oak.plugins.index.lucene.directory.DefaultDirectoryFactory in project jackrabbit-oak by apache.

the class LuceneIndexTest method purgeDeletedDocs.

private void purgeDeletedDocs(NodeBuilder idx, IndexDefinition definition) throws IOException {
    Directory dir = new DefaultDirectoryFactory(null, null).newInstance(definition, idx, LuceneIndexConstants.INDEX_DATA_CHILD_NAME, false);
    IndexWriter writer = new IndexWriter(dir, getIndexWriterConfig(definition, true));
    writer.forceMergeDeletes();
    writer.close();
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) DefaultDirectoryFactory(org.apache.jackrabbit.oak.plugins.index.lucene.directory.DefaultDirectoryFactory) Directory(org.apache.lucene.store.Directory)

Example 4 with DefaultDirectoryFactory

use of org.apache.jackrabbit.oak.plugins.index.lucene.directory.DefaultDirectoryFactory 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
    DirectoryFactory directoryFactory = new DefaultDirectoryFactory(null, null);
    LuceneIndexWriterFactory factory = new DefaultIndexWriterFactory(mip, directoryFactory, new LuceneIndexWriterConfig());
    LuceneIndexWriter writer = factory.newInstance(defn, builder, true);
    Document doc = newDoc("/content/en");
    doc.add(new StringField("foo", "bar", Field.Store.NO));
    writer.updateDocument("/content/en", doc);
    doc = newDoc("/libs/config");
    doc.add(new StringField("foo", "baz", Field.Store.NO));
    writer.updateDocument("/libs/config", doc);
    writer.close(0);
    // 2. Construct the readers
    LuceneIndexReaderFactory readerFactory = new DefaultIndexReaderFactory(mip, null);
    List<LuceneIndexReader> readers = readerFactory.createReaders(defn, builder.getNodeState(), "/foo");
    IndexNodeManager node = new IndexNodeManager("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.acquire(), "/foo", filter, Collections.<QueryIndex.OrderEntry>emptyList());
    QueryIndex.IndexPlan plan = planner.getPlan();
    // Count should be sum of both readers
    assertEquals(IndexPlannerTest.documentsPerValue(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) Document(org.apache.lucene.document.Document) LuceneIndexWriterConfig(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriterConfig) LuceneIndexReader(org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReader) LuceneIndexHelper.newLucenePropertyIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition) DirectoryFactory(org.apache.jackrabbit.oak.plugins.index.lucene.directory.DirectoryFactory) DefaultDirectoryFactory(org.apache.jackrabbit.oak.plugins.index.lucene.directory.DefaultDirectoryFactory) StringField(org.apache.lucene.document.StringField) 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) DefaultDirectoryFactory(org.apache.jackrabbit.oak.plugins.index.lucene.directory.DefaultDirectoryFactory) Test(org.junit.Test) AbstractQueryTest(org.apache.jackrabbit.oak.query.AbstractQueryTest)

Example 5 with DefaultDirectoryFactory

use of org.apache.jackrabbit.oak.plugins.index.lucene.directory.DefaultDirectoryFactory 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());
    DirectoryFactory directoryFactory = new DefaultDirectoryFactory(null, new DataStoreBlobStore(ds));
    LuceneIndexWriterFactory factory = new DefaultIndexWriterFactory(mip, directoryFactory, writerConfig);
    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) DirectoryFactory(org.apache.jackrabbit.oak.plugins.index.lucene.directory.DirectoryFactory) DefaultDirectoryFactory(org.apache.jackrabbit.oak.plugins.index.lucene.directory.DefaultDirectoryFactory) IndexReader(org.apache.lucene.index.IndexReader) DefaultIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.writer.DefaultIndexWriterFactory) DefaultDirectoryFactory(org.apache.jackrabbit.oak.plugins.index.lucene.directory.DefaultDirectoryFactory) DataStoreBlobStore(org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore) Test(org.junit.Test)

Aggregations

DefaultDirectoryFactory (org.apache.jackrabbit.oak.plugins.index.lucene.directory.DefaultDirectoryFactory)6 DirectoryFactory (org.apache.jackrabbit.oak.plugins.index.lucene.directory.DirectoryFactory)4 Test (org.junit.Test)4 DefaultIndexWriterFactory (org.apache.jackrabbit.oak.plugins.index.lucene.writer.DefaultIndexWriterFactory)3 LuceneIndexWriter (org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter)3 CachingFileDataStore (org.apache.jackrabbit.oak.plugins.blob.datastore.CachingFileDataStore)2 DataStoreBlobStore (org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore)2 LuceneIndexWriterConfig (org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriterConfig)2 LuceneIndexWriterFactory (org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriterFactory)2 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)2 Document (org.apache.lucene.document.Document)2 IndexReader (org.apache.lucene.index.IndexReader)2 Directory (org.apache.lucene.store.Directory)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)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 IndexDefinitionBuilder (org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder)1 LuceneIndexHelper.newLucenePropertyIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition)1 AbstractQueryTest (org.apache.jackrabbit.oak.query.AbstractQueryTest)1