use of org.apache.jackrabbit.oak.plugins.index.lucene.directory.DirectoryFactory in project jackrabbit-oak by apache.
the class LuceneIndexHelper method createEditorProvider.
public LuceneIndexEditorProvider createEditorProvider() throws IOException {
LuceneIndexEditorProvider editor;
if (directoryFactory != null) {
editor = new LuceneIndexEditorProvider(getIndexCopier(), indexHelper.getExtractedTextCache(), null, indexHelper.getMountInfoProvider()) {
@Override
protected DirectoryFactory newDirectoryFactory(BlobDeletionCallback blobDeletionCallback) {
return directoryFactory;
}
};
} else {
editor = new LuceneIndexEditorProvider(getIndexCopier(), indexHelper.getExtractedTextCache(), null, indexHelper.getMountInfoProvider());
}
editor.setBlobStore(indexHelper.getGCBlobStore());
return editor;
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.directory.DirectoryFactory in project jackrabbit-oak by apache.
the class MultiplexingIndexWriterTest method writesInDefaultMountBlobStore.
@Test
public void writesInDefaultMountBlobStore() throws Exception {
CachingFileDataStore ds = DataStoreUtils.createCachingFDS(folder.newFolder().getAbsolutePath(), folder.newFolder().getAbsolutePath());
DirectoryFactory directoryFactory = new DefaultDirectoryFactory(null, new DataStoreBlobStore(ds));
LuceneIndexWriterFactory factory = new DefaultIndexWriterFactory(mip, directoryFactory, writerConfig);
LuceneIndexWriter writer = factory.newInstance(defn, builder, true);
// 1. Add entry in foo mount
writer.updateDocument("/libs/config", newDoc("/libs/config"));
writer.close(0);
List<String> names = getIndexDirNodes();
// Only dirNode for mount foo should be present
assertThat(names, contains(indexDirName(fooMount)));
// 2. Add entry in default mount
writer = factory.newInstance(defn, builder, true);
writer.updateDocument("/content", newDoc("/content"));
writer.close(0);
names = getIndexDirNodes();
// Dir names for both mounts should be present
assertThat(names, containsInAnyOrder(indexDirName(fooMount), indexDirName(defaultMount)));
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.directory.DirectoryFactory in project jackrabbit-oak by apache.
the class MultiplexingLucenePropertyIndexTest method numDocsIsSumOfAllReaders.
@Test
public void numDocsIsSumOfAllReaders() throws Exception {
NodeBuilder defnBuilder = newLucenePropertyIndexDefinition(builder, "test", ImmutableSet.of("foo"), "async");
IndexDefinition defn = new IndexDefinition(initialContent, defnBuilder.getNodeState(), "/foo");
// 1. Have 2 reader created by writes in 2 diff mounts
DirectoryFactory directoryFactory = new DefaultDirectoryFactory(null, null);
LuceneIndexWriterFactory factory = new DefaultIndexWriterFactory(mip, directoryFactory, new LuceneIndexWriterConfig());
LuceneIndexWriter writer = factory.newInstance(defn, builder, true);
Document doc = newDoc("/content/en");
doc.add(new StringField("foo", "bar", Field.Store.NO));
writer.updateDocument("/content/en", doc);
doc = newDoc("/libs/config");
doc.add(new StringField("foo", "baz", Field.Store.NO));
writer.updateDocument("/libs/config", doc);
writer.close(0);
// 2. Construct the readers
LuceneIndexReaderFactory readerFactory = new DefaultIndexReaderFactory(mip, null);
List<LuceneIndexReader> readers = readerFactory.createReaders(defn, builder.getNodeState(), "/foo");
IndexNodeManager node = new IndexNodeManager("foo", defn, readers, null);
// 3 Obtain the plan
FilterImpl filter = createFilter("nt:base");
filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar"));
IndexPlanner planner = new IndexPlanner(node.acquire(), "/foo", filter, Collections.<QueryIndex.OrderEntry>emptyList());
QueryIndex.IndexPlan plan = planner.getPlan();
// Count should be sum of both readers
assertEquals(IndexPlannerTest.documentsPerValue(2), plan.getEstimatedEntryCount());
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.directory.DirectoryFactory 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());
DirectoryFactory directoryFactory = new DefaultDirectoryFactory(null, new DataStoreBlobStore(ds));
LuceneIndexWriterFactory factory = new DefaultIndexWriterFactory(mip, directoryFactory, writerConfig);
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.directory.DirectoryFactory in project jackrabbit-oak by apache.
the class AggregateTest method propOneLevelNamedDirect.
@Test
public void propOneLevelNamedDirect() throws Exception {
IndexDefinitionBuilder builder = new IndexDefinitionBuilder();
builder.indexRule("nt:folder").property("jcr:content/a").ordered(PropertyType.TYPENAME_LONG).propertyIndex().property("jcr:content/b").ordered(PropertyType.TYPENAME_LONG).propertyIndex();
IndexDefinition defn = new IndexDefinition(root, builder.build(), "/foo");
Aggregate ag = defn.getApplicableIndexingRule("nt:folder").getAggregate();
NodeBuilder nb = newNode("nt:folder");
nb.child("jcr:content").setProperty("a", 1);
nb.child("jcr:content").setProperty("b", 1);
LuceneDocumentMaker maker = new LuceneDocumentMaker(defn, defn.getApplicableIndexingRule("nt:folder"), "/bar");
Document doc = maker.makeDocument(nb.getNodeState());
DirectoryFactory directoryFactory = new DefaultDirectoryFactory(null, null);
DefaultIndexWriterFactory writerFactory = new DefaultIndexWriterFactory(Mounts.defaultMountInfoProvider(), directoryFactory, new LuceneIndexWriterConfig());
LuceneIndexWriter writer = writerFactory.newInstance(defn, EMPTY_NODE.builder(), false);
writer.updateDocument("/bar", doc);
writer.close(100);
}
Aggregations