Search in sources :

Example 1 with LuceneDocumentMaker

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

the class ExternalIndexObserver method contentChanged.

@Override
public void contentChanged(@Nonnull NodeState after, @Nonnull 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.lucene.IndexDefinition) CommitContext(org.apache.jackrabbit.oak.spi.commit.CommitContext)

Example 2 with LuceneDocumentMaker

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

the class LuceneIndexer method index.

@Override
public boolean index(NodeStateEntry entry) throws IOException, CommitFailedException {
    if (getFilterResult(entry.getPath()) != PathFilter.Result.INCLUDE) {
        return false;
    }
    IndexingRule indexingRule = definition.getApplicableIndexingRule(entry.getNodeState());
    if (indexingRule == null) {
        return false;
    }
    LuceneDocumentMaker maker = newDocumentMaker(indexingRule, entry.getPath());
    Document doc = maker.makeDocument(entry.getNodeState());
    if (doc != null) {
        writeToIndex(doc, entry.getPath());
        progressReporter.indexUpdate(definition.getIndexPath());
        return true;
    }
    return false;
}
Also used : IndexingRule(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition.IndexingRule) LuceneDocumentMaker(org.apache.jackrabbit.oak.plugins.index.lucene.LuceneDocumentMaker) Document(org.apache.lucene.document.Document) NodeDocument(org.apache.jackrabbit.oak.plugins.document.NodeDocument)

Aggregations

LuceneDocumentMaker (org.apache.jackrabbit.oak.plugins.index.lucene.LuceneDocumentMaker)2 Document (org.apache.lucene.document.Document)2 NodeDocument (org.apache.jackrabbit.oak.plugins.document.NodeDocument)1 IndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition)1 IndexingRule (org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition.IndexingRule)1 CommitContext (org.apache.jackrabbit.oak.spi.commit.CommitContext)1 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)1 TimerStats (org.apache.jackrabbit.oak.stats.TimerStats)1