Search in sources :

Example 1 with LuceneIndexWriter

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();
    }
}
Also used : LuceneIndexWriter(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter) IndexNode(org.apache.jackrabbit.oak.plugins.index.lucene.IndexNode) IOException(java.io.IOException)

Example 2 with LuceneIndexWriter

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;
}
Also used : PathFilter(org.apache.jackrabbit.oak.plugins.index.PathFilter) LuceneIndexWriter(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter) IOException(java.io.IOException) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException)

Example 3 with LuceneIndexWriter

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());
    }
}
Also used : IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) LuceneIndexWriter(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter) StringField(org.apache.lucene.document.StringField) LuceneIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriterFactory) DefaultIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.writer.DefaultIndexWriterFactory) Document(org.apache.lucene.document.Document) Test(org.junit.Test)

Example 4 with LuceneIndexWriter

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());
}
Also used : LuceneIndexWriter(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter) LuceneIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriterFactory) DefaultIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.writer.DefaultIndexWriterFactory) Test(org.junit.Test)

Example 5 with LuceneIndexWriter

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());
}
Also used : IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) LuceneIndexWriter(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter) StringField(org.apache.lucene.document.StringField) LuceneIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriterFactory) DefaultIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.writer.DefaultIndexWriterFactory) Document(org.apache.lucene.document.Document) Test(org.junit.Test)

Aggregations

LuceneIndexWriter (org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter)14 Test (org.junit.Test)12 IndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition)7 DefaultIndexWriterFactory (org.apache.jackrabbit.oak.plugins.index.lucene.writer.DefaultIndexWriterFactory)7 LuceneIndexWriterFactory (org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriterFactory)6 Document (org.apache.lucene.document.Document)6 LuceneIndexReader (org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReader)3 IOException (java.io.IOException)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)2 StringField (org.apache.lucene.document.StringField)2 IndexReader (org.apache.lucene.index.IndexReader)2 File (java.io.File)1 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)1 CachingFileDataStore (org.apache.jackrabbit.oak.plugins.blob.datastore.CachingFileDataStore)1 DataStoreBlobStore (org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore)1 PathFilter (org.apache.jackrabbit.oak.plugins.index.PathFilter)1 IndexNode (org.apache.jackrabbit.oak.plugins.index.lucene.IndexNode)1 DefaultIndexReaderFactory (org.apache.jackrabbit.oak.plugins.index.lucene.reader.DefaultIndexReaderFactory)1 LuceneIndexReaderFactory (org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReaderFactory)1