use of org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter in project jackrabbit-oak by apache.
the class DocumentQueue method processDocs.
private void processDocs(String indexPath, Iterable<LuceneDoc> docs, boolean docsFromQueue) {
//Drop the write call if stopped
if (stopped) {
return;
}
IndexNode indexNode = tracker.acquireIndexNode(indexPath);
if (indexNode == null) {
log.debug("No IndexNode found for index [{}].", indexPath);
return;
}
try {
LuceneIndexWriter writer = indexNode.getLocalWriter();
boolean docAdded = false;
for (LuceneDoc doc : docs) {
if (writer == null) {
//IndexDefinition per IndexNode might have changed and local
//indexing is disabled. Ignore
log.debug("No local IndexWriter found for index [{}]. Skipping index " + "entry for [{}]", indexPath, doc.docPath);
return;
}
if (doc.isProcessed()) {
//Skip already processed doc entry
continue;
} else {
doc.markProcessed();
}
if (doc.delete) {
writer.deleteDocuments(doc.docPath);
} else {
writer.updateDocument(doc.docPath, doc.doc);
}
docAdded = true;
String prefix = docsFromQueue ? "Queued" : "Direct";
log.trace("[{}] Updated index with doc {}", prefix, doc);
}
if (docAdded) {
indexNode.refreshReadersOnWriteIfRequired();
}
} catch (Exception e) {
//For now we just log it. Later we need to see if frequent error then to
//temporarily disable indexing for this index
log.warn("Error occurred while indexing index [{}]", indexPath, e);
} finally {
indexNode.release();
}
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter in project jackrabbit-oak by apache.
the class LuceneIndexEditor method childNodeDeleted.
@Override
public Editor childNodeDeleted(String name, NodeState before) throws CommitFailedException {
PathFilter.Result filterResult = getPathFilterResult(name);
if (filterResult == PathFilter.Result.EXCLUDE) {
return null;
}
if (!isDeleted) {
// tree deletion is handled on the parent node
String path = concat(getPath(), name);
try {
LuceneIndexWriter writer = context.getWriter();
// Remove all index entries in the removed subtree
writer.deleteDocuments(path);
this.context.indexUpdate();
} catch (IOException e) {
CommitFailedException ce = new CommitFailedException("Lucene", 5, "Failed to remove the index entries of" + " the removed subtree " + path + "for index " + context.getIndexingContext().getIndexPath(), e);
context.getIndexingContext().indexUpdateFailed(ce);
throw ce;
}
}
MatcherState ms = getMatcherState(name, before);
if (!ms.isEmpty()) {
return new LuceneIndexEditor(this, name, ms, filterResult, true);
}
// no need to recurse down the removed subtree
return null;
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter in project jackrabbit-oak by apache.
the class DefaultIndexReaderFactoryTest method multipleReaders_SingleSuggester.
@Test
public void multipleReaders_SingleSuggester() throws Exception {
LuceneIndexWriterFactory factory = new DefaultIndexWriterFactory(mip, null, null);
enabledSuggestorForSomeProp();
defn = new IndexDefinition(root, builder.getNodeState(), "/foo");
LuceneIndexWriter writer = factory.newInstance(defn, builder, true);
//Suggester field is only present for document in default mount
Document doc = newDoc("/content/en");
doc.add(new StringField(FieldNames.SUGGEST, "test", null));
writer.updateDocument("/content/en", doc);
writer.updateDocument("/libs/config", newDoc("/libs/config"));
writer.close(0);
LuceneIndexReaderFactory readerFactory = new DefaultIndexReaderFactory(mip, null);
List<LuceneIndexReader> readers = readerFactory.createReaders(defn, builder.getNodeState(), "/foo");
//Suggester should be present for all though it may be empty
for (LuceneIndexReader reader : readers) {
assertNotNull(reader.getReader());
assertNotNull(reader.getSuggestDirectory());
assertNotNull(reader.getLookup());
}
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter in project jackrabbit-oak by apache.
the class DefaultIndexReaderFactoryTest method multipleReaders.
@Test
public void multipleReaders() throws Exception {
LuceneIndexWriterFactory factory = new DefaultIndexWriterFactory(mip, null, null);
LuceneIndexWriter writer = factory.newInstance(defn, builder, true);
writer.updateDocument("/content/en", newDoc("/content/en"));
writer.updateDocument("/libs/config", newDoc("/libs/config"));
writer.close(0);
LuceneIndexReaderFactory readerFactory = new DefaultIndexReaderFactory(mip, null);
List<LuceneIndexReader> readers = readerFactory.createReaders(defn, builder.getNodeState(), "/foo");
assertEquals(2, readers.size());
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter in project jackrabbit-oak by apache.
the class DefaultIndexReaderFactoryTest method suggesterDir.
@Test
public void suggesterDir() throws Exception {
LuceneIndexWriterFactory factory = new DefaultIndexWriterFactory(mip, null, null);
enabledSuggestorForSomeProp();
defn = new IndexDefinition(root, builder.getNodeState(), "/foo");
LuceneIndexWriter writer = factory.newInstance(defn, builder, true);
Document doc = newDoc("/content/en");
doc.add(new StringField(FieldNames.SUGGEST, "test", null));
writer.updateDocument("/content/en", doc);
writer.close(0);
LuceneIndexReaderFactory readerFactory = new DefaultIndexReaderFactory(mip, null);
List<LuceneIndexReader> readers = readerFactory.createReaders(defn, builder.getNodeState(), "/foo");
LuceneIndexReader reader = readers.get(0);
assertNotNull(reader.getReader());
assertNotNull(reader.getSuggestDirectory());
assertNotNull(reader.getLookup());
}
Aggregations