use of org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter 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
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);
//2. Construct the readers
LuceneIndexReaderFactory readerFactory = new DefaultIndexReaderFactory(mip, null);
List<LuceneIndexReader> readers = readerFactory.createReaders(defn, builder.getNodeState(), "/foo");
IndexNode node = new IndexNode("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, "/foo", filter, Collections.<QueryIndex.OrderEntry>emptyList());
QueryIndex.IndexPlan plan = planner.getPlan();
//Count should be sum of both readers
assertEquals(2, plan.getEstimatedEntryCount());
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter 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());
DefaultIndexWriterFactory writerFactory = new DefaultIndexWriterFactory(Mounts.defaultMountInfoProvider(), null, null);
LuceneIndexWriter writer = writerFactory.newInstance(defn, EMPTY_NODE.builder(), false);
writer.updateDocument("/bar", doc);
writer.close(100);
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter in project jackrabbit-oak by apache.
the class NRTIndexTest method writerCreation.
@Test
public void writerCreation() throws Exception {
IndexDefinition idxDefn = getSyncIndexDefinition("/foo");
NRTIndex idx = indexFactory.createIndex(idxDefn);
LuceneIndexWriter writer = idx.getWriter();
assertNotNull(writer);
assertNotNull(idx.getIndexDir());
List<LuceneIndexReader> readers = idx.getReaders();
assertEquals(1, readers.size());
LuceneIndexWriter writer2 = idx.getWriter();
assertSame(writer, writer2);
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter in project jackrabbit-oak by apache.
the class NRTIndexTest method previousIndexInitialized.
@Test
public void previousIndexInitialized() 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);
NRTIndex idx2 = indexFactory.createIndex(idxDefn);
assertEquals(1, idx2.getReaders().size());
LuceneIndexWriter w2 = idx2.getWriter();
assertEquals(2, idx2.getReaders().size());
assertNotEquals(idx1.getIndexDir(), idx2.getIndexDir());
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter 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);
}
Aggregations