Search in sources :

Example 6 with IndexDefinition

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

the class DefaultIndexWriterTest method writeInitializedUponReindex.

@Test
public void writeInitializedUponReindex() throws Exception {
    IndexDefinition defn = new IndexDefinition(root, builder.getNodeState(), "/foo");
    DefaultIndexWriter writer = new DefaultIndexWriter(defn, builder, new DefaultDirectoryFactory(null, null), INDEX_DATA_CHILD_NAME, SUGGEST_DATA_CHILD_NAME, true);
    assertTrue(writer.close(0));
}
Also used : IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) DefaultDirectoryFactory(org.apache.jackrabbit.oak.plugins.index.lucene.directory.DefaultDirectoryFactory) Test(org.junit.Test)

Example 7 with IndexDefinition

use of org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition 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 8 with IndexDefinition

use of org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition 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)

Example 9 with IndexDefinition

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

the class NRTIndexTest method getReaderWithoutWriter.

@Test
public void getReaderWithoutWriter() throws Exception {
    IndexDefinition idxDefn = getSyncIndexDefinition("/foo");
    NRTIndex idx1 = indexFactory.createIndex(idxDefn);
    List<LuceneIndexReader> readers = idx1.getReaders();
    assertNotNull(readers);
    assertTrue(readers.isEmpty());
    idx1.close();
    assertTrue(idx1.isClosed());
    //Closing multiple times should not raise exception
    idx1.close();
}
Also used : LuceneIndexReader(org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReader) IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) Test(org.junit.Test)

Example 10 with IndexDefinition

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

the class LuceneIndexDumper method dump.

public void dump() throws IOException {
    try (Closer closer = Closer.create()) {
        NodeState idx = NodeStateUtils.getNode(rootState, indexPath);
        IndexDefinition defn = IndexDefinition.newBuilder(rootState, idx, indexPath).build();
        indexDir = DirectoryUtils.createIndexDir(baseDir, indexPath);
        DirectoryUtils.writeMeta(indexDir, indexPath);
        for (String dirName : idx.getChildNodeNames()) {
            if (NodeStateUtils.isHidden(dirName) && (isIndexDirName(dirName) || isSuggestIndexDirName(dirName))) {
                copyContent(idx, defn, indexDir, dirName, closer);
            }
        }
    }
}
Also used : Closer(com.google.common.io.Closer) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition)

Aggregations

IndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition)28 Test (org.junit.Test)24 LuceneIndexWriter (org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter)7 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)7 Document (org.apache.lucene.document.Document)7 Directory (org.apache.lucene.store.Directory)7 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)5 File (java.io.File)4 OakDirectory (org.apache.jackrabbit.oak.plugins.index.lucene.OakDirectory)4 Result (org.apache.jackrabbit.oak.plugins.index.lucene.directory.IndexConsistencyChecker.Result)3 LuceneIndexReader (org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReader)3 DefaultDirectoryFactory (org.apache.jackrabbit.oak.plugins.index.lucene.directory.DefaultDirectoryFactory)2 DefaultIndexWriterFactory (org.apache.jackrabbit.oak.plugins.index.lucene.writer.DefaultIndexWriterFactory)2 LuceneIndexWriterFactory (org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriterFactory)2 StringField (org.apache.lucene.document.StringField)2 FSDirectory (org.apache.lucene.store.FSDirectory)2 Closer (com.google.common.io.Closer)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 Blob (org.apache.jackrabbit.oak.api.Blob)1