use of org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter 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) {
}
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter 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());
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter in project jackrabbit-oak by apache.
the class DefaultIndexReaderFactoryTest method indexDir.
@Test
public void indexDir() throws Exception {
LuceneIndexWriterFactory factory = new DefaultIndexWriterFactory(mip, null, null);
LuceneIndexWriter writer = factory.newInstance(defn, builder, true);
writer.updateDocument("/content/en", newDoc("/content/en"));
writer.close(0);
LuceneIndexReaderFactory readerFactory = new DefaultIndexReaderFactory(mip, null);
List<LuceneIndexReader> readers = readerFactory.createReaders(defn, builder.getNodeState(), "/foo");
assertEquals(1, readers.size());
LuceneIndexReader reader = readers.get(0);
assertNotNull(reader.getReader());
assertNull(reader.getSuggestDirectory());
assertNull(reader.getLookup());
assertEquals(1, reader.getReader().numDocs());
final AtomicBoolean closed = new AtomicBoolean();
reader.getReader().addReaderClosedListener(new IndexReader.ReaderClosedListener() {
@Override
public void onClose(IndexReader reader) {
closed.set(true);
}
});
reader.close();
assertTrue(closed.get());
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter in project jackrabbit-oak by apache.
the class DefaultIndexReaderFactoryTest method indexDirWithBlobStore.
@Test
public void indexDirWithBlobStore() throws Exception {
/* Register a blob store */
CachingFileDataStore ds = DataStoreUtils.createCachingFDS(folder.newFolder().getAbsolutePath(), folder.newFolder().getAbsolutePath());
LuceneIndexWriterFactory factory = new DefaultIndexWriterFactory(mip, null, new DataStoreBlobStore(ds));
LuceneIndexWriter writer = factory.newInstance(defn, builder, true);
writer.updateDocument("/content/en", newDoc("/content/en"));
writer.close(0);
LuceneIndexReaderFactory readerFactory = new DefaultIndexReaderFactory(mip, null);
List<LuceneIndexReader> readers = readerFactory.createReaders(defn, builder.getNodeState(), "/foo");
assertEquals(1, readers.size());
LuceneIndexReader reader = readers.get(0);
assertNotNull(reader.getReader());
assertNull(reader.getSuggestDirectory());
assertNull(reader.getLookup());
assertEquals(1, reader.getReader().numDocs());
final AtomicBoolean closed = new AtomicBoolean();
reader.getReader().addReaderClosedListener(new IndexReader.ReaderClosedListener() {
@Override
public void onClose(IndexReader reader) {
closed.set(true);
}
});
reader.close();
assertTrue(closed.get());
}
Aggregations