use of org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReader 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.reader.LuceneIndexReader in project jackrabbit-oak by apache.
the class NRTIndex method getReaders.
/**
* Returns the list of LuceneIndexReader. If the writer has not received
* any updates between 2 calls to this method then same list would be
* returned.
*/
public synchronized List<LuceneIndexReader> getReaders() {
checkState(!closed);
DirectoryReader latestReader = createReader();
//reuse old readers
if (latestReader == dirReader && readers != null) {
return readers;
}
List<LuceneIndexReader> newReaders = Lists.newArrayListWithCapacity(2);
if (latestReader != null) {
newReaders.add(new NRTReader(latestReader, directory));
}
//Old reader should be added later
LuceneIndexReader previousReader = previous != null ? previous.getPrimaryReader() : null;
if (previousReader != null) {
newReaders.add(previousReader);
}
dirReader = latestReader;
readers = ImmutableList.copyOf(newReaders);
return readers;
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReader 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.reader.LuceneIndexReader 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