Search in sources :

Example 1 with DefaultIndexWriterFactory

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

the class DefaultIndexReaderFactoryTest method multipleReaders_SingleSuggester.

@Test
public void multipleReaders_SingleSuggester() throws Exception {
    LuceneIndexWriterFactory factory = new DefaultIndexWriterFactory(mip, null, null);
    enabledSuggestorForSomeProp();
    defn = new IndexDefinition(root, builder.getNodeState(), "/foo");
    LuceneIndexWriter writer = factory.newInstance(defn, builder, true);
    //Suggester field is only present for document in default mount
    Document doc = newDoc("/content/en");
    doc.add(new StringField(FieldNames.SUGGEST, "test", null));
    writer.updateDocument("/content/en", doc);
    writer.updateDocument("/libs/config", newDoc("/libs/config"));
    writer.close(0);
    LuceneIndexReaderFactory readerFactory = new DefaultIndexReaderFactory(mip, null);
    List<LuceneIndexReader> readers = readerFactory.createReaders(defn, builder.getNodeState(), "/foo");
    //Suggester should be present for all though it may be empty
    for (LuceneIndexReader reader : readers) {
        assertNotNull(reader.getReader());
        assertNotNull(reader.getSuggestDirectory());
        assertNotNull(reader.getLookup());
    }
}
Also used : IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) LuceneIndexWriter(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter) StringField(org.apache.lucene.document.StringField) LuceneIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriterFactory) DefaultIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.writer.DefaultIndexWriterFactory) Document(org.apache.lucene.document.Document) Test(org.junit.Test)

Example 2 with DefaultIndexWriterFactory

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

the class DefaultIndexReaderFactoryTest method multipleReaders.

@Test
public void multipleReaders() throws Exception {
    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);
    LuceneIndexReaderFactory readerFactory = new DefaultIndexReaderFactory(mip, null);
    List<LuceneIndexReader> readers = readerFactory.createReaders(defn, builder.getNodeState(), "/foo");
    assertEquals(2, readers.size());
}
Also used : LuceneIndexWriter(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter) 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 3 with DefaultIndexWriterFactory

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

the class DefaultIndexReaderFactoryTest method suggesterDir.

@Test
public void suggesterDir() throws Exception {
    LuceneIndexWriterFactory factory = new DefaultIndexWriterFactory(mip, null, null);
    enabledSuggestorForSomeProp();
    defn = new IndexDefinition(root, builder.getNodeState(), "/foo");
    LuceneIndexWriter writer = factory.newInstance(defn, builder, true);
    Document doc = newDoc("/content/en");
    doc.add(new StringField(FieldNames.SUGGEST, "test", null));
    writer.updateDocument("/content/en", doc);
    writer.close(0);
    LuceneIndexReaderFactory readerFactory = new DefaultIndexReaderFactory(mip, null);
    List<LuceneIndexReader> readers = readerFactory.createReaders(defn, builder.getNodeState(), "/foo");
    LuceneIndexReader reader = readers.get(0);
    assertNotNull(reader.getReader());
    assertNotNull(reader.getSuggestDirectory());
    assertNotNull(reader.getLookup());
}
Also used : IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) LuceneIndexWriter(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter) StringField(org.apache.lucene.document.StringField) LuceneIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriterFactory) DefaultIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.writer.DefaultIndexWriterFactory) Document(org.apache.lucene.document.Document) Test(org.junit.Test)

Example 4 with DefaultIndexWriterFactory

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

the class LuceneIndexEditorProvider method getIndexEditor.

@Override
public Editor getIndexEditor(@Nonnull String type, @Nonnull NodeBuilder definition, @Nonnull NodeState root, @Nonnull IndexUpdateCallback callback) throws CommitFailedException {
    if (TYPE_LUCENE.equals(type)) {
        checkArgument(callback instanceof ContextAwareCallback, "callback instance not of type " + "ContextAwareCallback [%s]", callback);
        IndexingContext indexingContext = ((ContextAwareCallback) callback).getIndexingContext();
        BlobDeletionCallback blobDeletionCallback = activeDeletedBlobCollector.getBlobDeletionCallback();
        indexingContext.registerIndexCommitCallback(blobDeletionCallback);
        indexWriterFactory = new DefaultIndexWriterFactory(mountInfoProvider, getDirectoryFactory(blobDeletionCallback));
        LuceneIndexWriterFactory writerFactory = indexWriterFactory;
        IndexDefinition indexDefinition = null;
        boolean asyncIndexing = true;
        if (!indexingContext.isAsync() && IndexDefinition.supportsSyncOrNRTIndexing(definition)) {
            //incremental indexing
            if (indexingContext.isReindexing()) {
                return null;
            }
            CommitContext commitContext = getCommitContext(indexingContext);
            if (commitContext == null) {
                //Logically there should not be any commit without commit context. But
                //some initializer code does the commit with out it. So ignore such calls with
                //warning now
                //TODO Revisit use of warn level once all such cases are analyzed
                log.warn("No CommitContext found for commit", new Exception());
                return null;
            }
            //TODO Also check if index has been done once
            writerFactory = new LocalIndexWriterFactory(getDocumentHolder(commitContext), indexingContext.getIndexPath());
            //creating definition instance for each commit as this gets executed for each commit
            if (indexTracker != null) {
                indexDefinition = indexTracker.getIndexDefinition(indexingContext.getIndexPath());
                if (indexDefinition != null && !indexDefinition.hasMatchingNodeTypeReg(root)) {
                    log.debug("Detected change in NodeType registry for index {}. Would not use " + "existing index definition", indexDefinition.getIndexPath());
                    indexDefinition = null;
                }
            }
            //Pass on a read only builder to ensure that nothing gets written
            //at all to NodeStore for local indexing.
            //TODO [hybrid] This would cause issue with Facets as for faceted fields
            //some stuff gets written to NodeBuilder. That logic should be refactored
            //to be moved to LuceneIndexWriter
            definition = new ReadOnlyBuilder(definition.getNodeState());
            asyncIndexing = false;
        }
        LuceneIndexEditorContext context = new LuceneIndexEditorContext(root, definition, indexDefinition, callback, writerFactory, extractedTextCache, augmentorFactory, indexingContext, asyncIndexing);
        return new LuceneIndexEditor(context);
    }
    return null;
}
Also used : ReadOnlyBuilder(org.apache.jackrabbit.oak.spi.state.ReadOnlyBuilder) ContextAwareCallback(org.apache.jackrabbit.oak.plugins.index.ContextAwareCallback) BlobDeletionCallback(org.apache.jackrabbit.oak.plugins.index.lucene.directory.ActiveDeletedBlobCollectorFactory.BlobDeletionCallback) LuceneIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriterFactory) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) CommitContext(org.apache.jackrabbit.oak.spi.commit.CommitContext) IndexingContext(org.apache.jackrabbit.oak.plugins.index.IndexingContext) LocalIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.hybrid.LocalIndexWriterFactory) DefaultIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.writer.DefaultIndexWriterFactory)

Example 5 with DefaultIndexWriterFactory

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

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