Search in sources :

Example 1 with IndexDefinition

use of org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition in project jackrabbit-oak by apache.

the class LuceneIndexEditor2Test method relativeProperties.

@Test
public void relativeProperties() throws Exception {
    LuceneIndexDefinitionBuilder defnb = new LuceneIndexDefinitionBuilder();
    defnb.indexRule("nt:base").property("jcr:content/metadata/foo").propertyIndex();
    defnb.aggregateRule("nt:base").include("*");
    NodeState defnState = defnb.build();
    IndexDefinition defn = new IndexDefinition(root, defnState, indexPath);
    LuceneIndexEditorContext ctx = newContext(defnState.builder(), defn, true);
    ctx.setPropertyUpdateCallback(propCallback);
    EditorHook hook = createHook(ctx);
    updateBefore(defnb);
    // Property added
    NodeBuilder builder = before.builder();
    builder.child("a").child("jcr:content").child("metadata").setProperty("foo", "bar");
    builder.child("a").setProperty("foo2", "bar");
    before = hook.processCommit(root, builder.getNodeState(), CommitInfo.EMPTY);
    propCallback.state.assertState("/a", "jcr:content/metadata/foo", UpdateState.ADDED);
    assertEquals(1, propCallback.invocationCount);
    propCallback.reset();
    // Property updated
    builder = before.builder();
    builder.child("a").child("jcr:content").child("metadata").setProperty("foo", "bar2");
    builder.child("a").setProperty("foo2", "bar2");
    before = hook.processCommit(before, builder.getNodeState(), CommitInfo.EMPTY);
    propCallback.state.assertState("/a", "jcr:content/metadata/foo", UpdateState.UPDATED);
    assertEquals(1, propCallback.invocationCount);
    propCallback.reset();
    // Property deleted
    builder = before.builder();
    builder.child("a").child("jcr:content").child("metadata").removeProperty("foo");
    builder.child("a").removeProperty("foo2");
    before = hook.processCommit(before, builder.getNodeState(), CommitInfo.EMPTY);
    propCallback.state.assertState("/a", "jcr:content/metadata/foo", UpdateState.DELETED);
    assertEquals(1, propCallback.invocationCount);
    propCallback.reset();
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) IndexDefinition(org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) LuceneIndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexDefinitionBuilder) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 2 with IndexDefinition

use of org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition in project jackrabbit-oak by apache.

the class LuceneIndexEditorTest method autoFormatUpdate.

@Test
public void autoFormatUpdate() throws Exception {
    NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
    NodeBuilder nb = newLuceneIndexDefinitionV2(index, "lucene", of(TYPENAME_STRING));
    // 1. Trigger a index so that next index step does not see it as a fresh index
    NodeState indexed = HOOK.processCommit(EMPTY_NODE, builder.getNodeState(), CommitInfo.EMPTY);
    IndexDefinition defn = new IndexDefinition(root, indexed.getChildNode(INDEX_DEFINITIONS_NAME).getChildNode("lucene"), "/foo");
    assertFalse(defn.isOfOldFormat());
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) IndexDefinition(org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition) LuceneIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexDefinition) LuceneIndexHelper.newLuceneIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 3 with IndexDefinition

use of org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition in project jackrabbit-oak by apache.

the class DocumentStoreIndexerBase method buildFlatFileStore.

/**
 * @return an Instance of FlatFileStore, whose getFlatFileStorePath() method can be used to get the absolute path to this store.
 * @throws IOException
 * @throws CommitFailedException
 */
public FlatFileStore buildFlatFileStore() throws IOException, CommitFailedException {
    NodeState checkpointedState = indexerSupport.retrieveNodeStateForCheckpoint();
    NodeStore copyOnWriteStore = new MemoryNodeStore(checkpointedState);
    NodeBuilder builder = copyOnWriteStore.getRoot().builder();
    NodeState root = builder.getNodeState();
    indexerSupport.updateIndexDefinitions(builder);
    IndexDefinition.Builder indexDefBuilder = new IndexDefinition.Builder();
    Set<String> preferredPathElements = new HashSet<>();
    Set<IndexDefinition> indexDefinitions = new HashSet<>();
    for (String indexPath : indexHelper.getIndexPaths()) {
        NodeBuilder idxBuilder = IndexerSupport.childBuilder(builder, indexPath, false);
        IndexDefinition indexDf = indexDefBuilder.defn(idxBuilder.getNodeState()).indexPath(indexPath).root(root).build();
        preferredPathElements.addAll(indexDf.getRelativeNodeNames());
        indexDefinitions.add(indexDf);
    }
    Predicate<String> predicate = s -> indexDefinitions.stream().anyMatch(indexDef -> indexDef.getPathFilter().filter(s) != PathFilter.Result.EXCLUDE);
    FlatFileStore flatFileStore = buildFlatFileStore(checkpointedState, null, predicate, preferredPathElements);
    log.info("FlatFileStore built at {}. To use this flatFileStore in a reindex step, set System Property-{} with value {}", flatFileStore.getFlatFileStorePath(), OAK_INDEXER_SORTED_FILE_PATH, flatFileStore.getFlatFileStorePath());
    return flatFileStore;
}
Also used : FlatFileStore(org.apache.jackrabbit.oak.index.indexer.document.flatfile.FlatFileStore) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) Stopwatch(com.google.common.base.Stopwatch) IndexDefinition(org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition) MongoDocumentTraverser(org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentTraverser) IndexUpdateCallback(org.apache.jackrabbit.oak.plugins.index.IndexUpdateCallback) LoggerFactory(org.slf4j.LoggerFactory) IndexHelper(org.apache.jackrabbit.oak.index.IndexHelper) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MetricStatisticsProvider(org.apache.jackrabbit.oak.plugins.metric.MetricStatisticsProvider) IndexerSupport(org.apache.jackrabbit.oak.index.IndexerSupport) EmptyHook(org.apache.jackrabbit.oak.spi.commit.EmptyHook) DefaultMemoryManager(org.apache.jackrabbit.oak.index.indexer.document.flatfile.DefaultMemoryManager) Closer(com.google.common.io.Closer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DocumentStoreSplitter(org.apache.jackrabbit.oak.plugins.document.mongo.DocumentStoreSplitter) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) RevisionVector(org.apache.jackrabbit.oak.plugins.document.RevisionVector) PathFilter(org.apache.jackrabbit.oak.spi.filter.PathFilter) OAK_INDEXER_SORTED_FILE_PATH(org.apache.jackrabbit.oak.index.indexer.document.flatfile.FlatFileNodeStoreBuilder.OAK_INDEXER_SORTED_FILE_PATH) MetricRegistry(com.codahale.metrics.MetricRegistry) Logger(org.slf4j.Logger) FlatFileNodeStoreBuilder(org.apache.jackrabbit.oak.index.indexer.document.flatfile.FlatFileNodeStoreBuilder) NodeTraversalCallback(org.apache.jackrabbit.oak.plugins.index.NodeTraversalCallback) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) Predicate(java.util.function.Predicate) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) MongoConnection(org.apache.jackrabbit.oak.plugins.document.util.MongoConnection) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) Set(java.util.Set) IOException(java.io.IOException) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) File(java.io.File) MongoDocumentStore(org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore) List(java.util.List) Collection(org.apache.jackrabbit.oak.plugins.document.Collection) DocumentNodeState(org.apache.jackrabbit.oak.plugins.document.DocumentNodeState) IndexingProgressReporter(org.apache.jackrabbit.oak.plugins.index.progress.IndexingProgressReporter) Closeable(java.io.Closeable) MemoryManager(org.apache.jackrabbit.oak.index.indexer.document.flatfile.MemoryManager) IndexConstants(org.apache.jackrabbit.oak.plugins.index.IndexConstants) MetricRateEstimator(org.apache.jackrabbit.oak.plugins.index.progress.MetricRateEstimator) TYPE_PROPERTY_NAME(org.apache.jackrabbit.oak.plugins.index.IndexConstants.TYPE_PROPERTY_NAME) NodeStateUtils(org.apache.jackrabbit.oak.spi.state.NodeStateUtils) StatisticsProvider(org.apache.jackrabbit.oak.stats.StatisticsProvider) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) DocumentNodeState(org.apache.jackrabbit.oak.plugins.document.DocumentNodeState) FlatFileStore(org.apache.jackrabbit.oak.index.indexer.document.flatfile.FlatFileStore) FlatFileNodeStoreBuilder(org.apache.jackrabbit.oak.index.indexer.document.flatfile.FlatFileNodeStoreBuilder) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) IndexDefinition(org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition) HashSet(java.util.HashSet)

Example 4 with IndexDefinition

use of org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition in project jackrabbit-oak by apache.

the class ExternalIndexObserver method contentChanged.

@Override
public void contentChanged(@NotNull NodeState after, @NotNull CommitInfo info) {
    // Only interested in external changes
    if (excludes(after, info)) {
        return;
    }
    CommitContext commitContext = (CommitContext) info.getInfo().get(CommitContext.NAME);
    IndexedPaths indexedPaths = (IndexedPaths) commitContext.get(LuceneDocumentHolder.NAME);
    commitContext.remove(LuceneDocumentHolder.NAME);
    log.trace("Received indexed paths {}", indexedPaths);
    int droppedCount = 0;
    int indexedCount = 0;
    TimerStats.Context ctx = timer.time();
    Set<String> indexPaths = Sets.newHashSet();
    for (IndexedPathInfo indexData : indexedPaths) {
        String path = indexData.getPath();
        NodeState indexedNode = null;
        for (String indexPath : indexData.getIndexPaths()) {
            IndexDefinition defn = indexTracker.getIndexDefinition(indexPath);
            // but not used locally
            if (defn == null) {
                continue;
            }
            // Lazily initialize indexedNode
            if (indexedNode == null) {
                indexedNode = NodeStateUtils.getNode(after, path);
            }
            if (!indexedNode.exists()) {
                continue;
            }
            IndexDefinition.IndexingRule indexingRule = defn.getApplicableIndexingRule(indexedNode);
            if (indexingRule == null) {
                log.debug("No indexingRule found for path {} for index {}", path, indexPath);
                continue;
            }
            indexPaths.add(indexPath);
            try {
                Document doc = new LuceneDocumentMaker(defn, indexingRule, path).makeDocument(indexedNode);
                if (doc != null) {
                    if (indexingQueue.add(LuceneDoc.forUpdate(indexPath, path, doc))) {
                        indexedCount++;
                    } else {
                        droppedCount++;
                    }
                }
            } catch (Exception e) {
                log.warn("Ignoring making LuceneDocument for path {} for index {} due to exception", path, indexPath, e);
            }
        }
    }
    if (droppedCount > 0) {
        log.warn("Dropped [{}] docs from indexing as queue is full", droppedCount);
    }
    added.mark(indexedCount);
    ctx.stop();
    log.debug("Added {} documents for {} indexes from external changes", indexedCount, indexPaths.size());
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) LuceneDocumentMaker(org.apache.jackrabbit.oak.plugins.index.lucene.LuceneDocumentMaker) TimerStats(org.apache.jackrabbit.oak.stats.TimerStats) Document(org.apache.lucene.document.Document) IndexDefinition(org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition) CommitContext(org.apache.jackrabbit.oak.spi.commit.CommitContext)

Example 5 with IndexDefinition

use of org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition in project jackrabbit-oak by apache.

the class ElasticIndexerTest method nodeIndexed_WithIncludedPaths.

@Test
public void nodeIndexed_WithIncludedPaths() throws Exception {
    ElasticIndexDefinitionBuilder idxb = new ElasticIndexDefinitionBuilder();
    idxb.indexRule("nt:base").property("foo").propertyIndex();
    idxb.includedPaths("/content");
    NodeState defn = idxb.build();
    IndexDefinition idxDefn = new ElasticIndexDefinition(root, defn, "/oak:index/testIndex", "testPrefix");
    NodeBuilder builder = root.builder();
    FulltextIndexWriter indexWriter = new ElasticIndexWriterFactory(mock(ElasticConnection.class), mock(ElasticIndexTracker.class)).newInstance(idxDefn, defn.builder(), CommitInfo.EMPTY, false);
    ElasticIndexer indexer = new ElasticIndexer(idxDefn, mock(FulltextBinaryTextExtractor.class), builder, mock(IndexingProgressReporter.class), indexWriter, mock(ElasticIndexEditorProvider.class), mock(IndexHelper.class));
    NodeState testNode = EMPTY_NODE.builder().setProperty("foo", "bar").getNodeState();
    assertTrue(indexer.index(new NodeStateEntry.NodeStateEntryBuilder(testNode, "/content/x").build()));
    assertFalse(indexer.index(new NodeStateEntry.NodeStateEntryBuilder(testNode, "/x").build()));
    assertFalse(indexer.index(new NodeStateEntry.NodeStateEntryBuilder(testNode, "/").build()));
}
Also used : ElasticIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.elastic.index.ElasticIndexWriterFactory) IndexHelper(org.apache.jackrabbit.oak.index.IndexHelper) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) FulltextBinaryTextExtractor(org.apache.jackrabbit.oak.plugins.index.search.spi.binary.FulltextBinaryTextExtractor) IndexDefinition(org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition) ElasticIndexDefinition(org.apache.jackrabbit.oak.plugins.index.elastic.ElasticIndexDefinition) FulltextIndexWriter(org.apache.jackrabbit.oak.plugins.index.search.spi.editor.FulltextIndexWriter) IndexingProgressReporter(org.apache.jackrabbit.oak.plugins.index.progress.IndexingProgressReporter) ElasticIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.elastic.index.ElasticIndexEditorProvider) ElasticIndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.elastic.util.ElasticIndexDefinitionBuilder) ElasticIndexDefinition(org.apache.jackrabbit.oak.plugins.index.elastic.ElasticIndexDefinition) Test(org.junit.Test)

Aggregations

IndexDefinition (org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition)36 Test (org.junit.Test)28 LuceneIndexHelper.newLuceneIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition)19 LuceneIndexDefinitionBuilder (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexDefinitionBuilder)18 LuceneIndexHelper.newLucenePropertyIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition)17 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)17 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)12 IndexingRule (org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition.IndexingRule)5 IndexingProgressReporter (org.apache.jackrabbit.oak.plugins.index.progress.IndexingProgressReporter)4 File (java.io.File)3 FulltextBinaryTextExtractor (org.apache.jackrabbit.oak.plugins.index.search.spi.binary.FulltextBinaryTextExtractor)3 IOException (java.io.IOException)2 Tree (org.apache.jackrabbit.oak.api.Tree)2 IndexHelper (org.apache.jackrabbit.oak.index.IndexHelper)2 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Stopwatch (com.google.common.base.Stopwatch)1 Closer (com.google.common.io.Closer)1 Closeable (java.io.Closeable)1