Search in sources :

Example 1 with PropertyIndexUpdateCallback

use of org.apache.jackrabbit.oak.plugins.index.lucene.property.PropertyIndexUpdateCallback 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);
        LuceneIndexWriterFactory writerFactory = null;
        IndexDefinition indexDefinition = null;
        boolean asyncIndexing = true;
        String indexPath = indexingContext.getIndexPath();
        PropertyIndexUpdateCallback propertyUpdateCallback = null;
        if (nrtIndexingEnabled() && !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), indexPath);
            // creating definition instance for each commit as this gets executed for each commit
            if (indexTracker != null) {
                indexDefinition = indexTracker.getIndexDefinition(indexPath);
                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;
                }
            }
            if (indexDefinition == null) {
                indexDefinition = IndexDefinition.newBuilder(root, definition.getNodeState(), indexPath).build();
            }
            if (indexDefinition.hasSyncPropertyDefinitions()) {
                propertyUpdateCallback = new PropertyIndexUpdateCallback(indexPath, definition, root);
                if (indexTracker != null) {
                    PropertyQuery query = new LuceneIndexPropertyQuery(indexTracker, indexPath);
                    propertyUpdateCallback.getUniquenessConstraintValidator().setSecondStore(query);
                }
            }
            // 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;
        }
        if (writerFactory == null) {
            writerFactory = new DefaultIndexWriterFactory(mountInfoProvider, newDirectoryFactory(blobDeletionCallback), writerConfig);
        }
        LuceneIndexEditorContext context = new LuceneIndexEditorContext(root, definition, indexDefinition, callback, writerFactory, extractedTextCache, augmentorFactory, indexingContext, asyncIndexing);
        context.setPropertyUpdateCallback(propertyUpdateCallback);
        return new LuceneIndexEditor(context);
    }
    return null;
}
Also used : PropertyIndexUpdateCallback(org.apache.jackrabbit.oak.plugins.index.lucene.property.PropertyIndexUpdateCallback) PropertyQuery(org.apache.jackrabbit.oak.plugins.index.lucene.property.PropertyQuery) LuceneIndexPropertyQuery(org.apache.jackrabbit.oak.plugins.index.lucene.property.LuceneIndexPropertyQuery) 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) LuceneIndexPropertyQuery(org.apache.jackrabbit.oak.plugins.index.lucene.property.LuceneIndexPropertyQuery) 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)

Aggregations

CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)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 LuceneIndexPropertyQuery (org.apache.jackrabbit.oak.plugins.index.lucene.property.LuceneIndexPropertyQuery)1 PropertyIndexUpdateCallback (org.apache.jackrabbit.oak.plugins.index.lucene.property.PropertyIndexUpdateCallback)1 PropertyQuery (org.apache.jackrabbit.oak.plugins.index.lucene.property.PropertyQuery)1 DefaultIndexWriterFactory (org.apache.jackrabbit.oak.plugins.index.lucene.writer.DefaultIndexWriterFactory)1 LuceneIndexWriterFactory (org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriterFactory)1 CommitContext (org.apache.jackrabbit.oak.spi.commit.CommitContext)1 ReadOnlyBuilder (org.apache.jackrabbit.oak.spi.state.ReadOnlyBuilder)1