Search in sources :

Example 21 with IndexDefinition

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

the class NRTIndexTest method sameReaderIfNoChange.

@Test
public void sameReaderIfNoChange() throws Exception {
    IndexDefinition idxDefn = getSyncIndexDefinition("/foo");
    NRTIndex idx1 = indexFactory.createIndex(idxDefn);
    LuceneIndexWriter w1 = idx1.getWriter();
    Document d1 = new Document();
    d1.add(newPathField("/a/b"));
    w1.updateDocument("/a/b", d1);
    List<LuceneIndexReader> readers = idx1.getReaders();
    List<LuceneIndexReader> readers2 = idx1.getReaders();
    assertSame(readers, readers2);
    w1.updateDocument("/a/b", d1);
    List<LuceneIndexReader> readers3 = idx1.getReaders();
    assertNotSame(readers2, readers3);
}
Also used : LuceneIndexReader(org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReader) IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) LuceneIndexWriter(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter) Document(org.apache.lucene.document.Document) Test(org.junit.Test)

Example 22 with IndexDefinition

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

the class NRTIndexTest method dirDeletedUponClose.

@Test
public void dirDeletedUponClose() throws Exception {
    IndexDefinition idxDefn = getSyncIndexDefinition("/foo");
    NRTIndex idx = indexFactory.createIndex(idxDefn);
    LuceneIndexWriter writer = idx.getWriter();
    File indexDir = idx.getIndexDir();
    assertTrue(indexDir.exists());
    idx.close();
    assertFalse(indexDir.exists());
    try {
        idx.getReaders();
        fail();
    } catch (IllegalStateException ignore) {
    }
    try {
        idx.getWriter();
        fail();
    } catch (IllegalStateException ignore) {
    }
}
Also used : IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) LuceneIndexWriter(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter) File(java.io.File) Test(org.junit.Test)

Example 23 with IndexDefinition

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

the class NRTIndexTest method multipleUpdateForSamePath.

@Test
public void multipleUpdateForSamePath() throws Exception {
    IndexDefinition idxDefn = getSyncIndexDefinition("/foo");
    NRTIndex idx = indexFactory.createIndex(idxDefn);
    LuceneIndexWriter writer = idx.getWriter();
    Document document = new Document();
    document.add(newPathField("/a/b"));
    writer.updateDocument("/a/b", document);
    assertEquals(1, idx.getPrimaryReader().getReader().numDocs());
    writer.updateDocument("/a/b", document);
    //Update for same path should not lead to deletion
    assertEquals(2, idx.getPrimaryReader().getReader().numDocs());
    assertEquals(0, idx.getPrimaryReader().getReader().numDeletedDocs());
}
Also used : IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) LuceneIndexWriter(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter) Document(org.apache.lucene.document.Document) Test(org.junit.Test)

Example 24 with IndexDefinition

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

the class ExternalIndexObserverTest method createNRTIndex.

private static IndexDefinition createNRTIndex(String ruleName) {
    IndexDefinitionBuilder idx = new IndexDefinitionBuilder();
    idx.indexRule(ruleName).property("foo").propertyIndex();
    idx.async("async", "sync");
    return new IndexDefinition(INITIAL_CONTENT, idx.build(), "/oak:index/foo");
}
Also used : IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) IndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder)

Example 25 with IndexDefinition

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

the class NRTIndexFactoryTest method indexCreationAndCloser.

@Test
public void indexCreationAndCloser() throws Exception {
    IndexDefinition idxDefn = getNRTIndexDefinition("/foo");
    NRTIndex idx1 = indexFactory.createIndex(idxDefn);
    assertNotNull(idx1);
    assertEquals(1, indexFactory.getIndexes("/foo").size());
    NRTIndex idx2 = indexFactory.createIndex(idxDefn);
    assertEquals(2, indexFactory.getIndexes("/foo").size());
    assertFalse(idx1.isClosed());
    NRTIndex idx3 = indexFactory.createIndex(idxDefn);
    assertFalse(idx1.isClosed());
    assertEquals(3, indexFactory.getIndexes("/foo").size());
    //Nothing index so size is zero
    assertEquals(0, idx2.getReaders().size());
    assertEquals(0, idx3.getReaders().size());
    NRTIndex idx4 = indexFactory.createIndex(idxDefn);
    assertEquals(3, indexFactory.getIndexes("/foo").size());
    assertEquals(0, idx3.getReaders().size());
    assertEquals(0, idx4.getReaders().size());
    //With 3 generation open the first one should be closed
    assertTrue(idx1.isClosed());
    assertNull(idx1.getPrevious());
    NRTIndex idx5 = indexFactory.createIndex(idxDefn);
    assertEquals(3, indexFactory.getIndexes("/foo").size());
    assertTrue(idx2.isClosed());
    assertNull(idx2.getPrevious());
}
Also used : IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) Test(org.junit.Test)

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