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());
}
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;
}
Aggregations