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