Search in sources :

Example 6 with LuceneIndexWriter

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());
}
Also used : FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) LuceneIndexWriter(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter) LuceneIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriterFactory) LuceneIndexReaderFactory(org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReaderFactory) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) LuceneIndexReader(org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReader) LuceneIndexHelper.newLucenePropertyIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition) QueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex) DefaultIndexReaderFactory(org.apache.jackrabbit.oak.plugins.index.lucene.reader.DefaultIndexReaderFactory) DefaultIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.writer.DefaultIndexWriterFactory) Test(org.junit.Test) AbstractQueryTest(org.apache.jackrabbit.oak.query.AbstractQueryTest)

Example 7 with LuceneIndexWriter

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);
}
Also used : LuceneIndexWriter(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter) IndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder) DefaultIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.writer.DefaultIndexWriterFactory) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Document(org.apache.lucene.document.Document) Test(org.junit.Test)

Example 8 with LuceneIndexWriter

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);
}
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) Test(org.junit.Test)

Example 9 with LuceneIndexWriter

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());
}
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 10 with LuceneIndexWriter

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);
}
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)

Aggregations

LuceneIndexWriter (org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter)14 Test (org.junit.Test)12 IndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition)7 DefaultIndexWriterFactory (org.apache.jackrabbit.oak.plugins.index.lucene.writer.DefaultIndexWriterFactory)7 LuceneIndexWriterFactory (org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriterFactory)6 Document (org.apache.lucene.document.Document)6 LuceneIndexReader (org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReader)3 IOException (java.io.IOException)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)2 StringField (org.apache.lucene.document.StringField)2 IndexReader (org.apache.lucene.index.IndexReader)2 File (java.io.File)1 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)1 CachingFileDataStore (org.apache.jackrabbit.oak.plugins.blob.datastore.CachingFileDataStore)1 DataStoreBlobStore (org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore)1 PathFilter (org.apache.jackrabbit.oak.plugins.index.PathFilter)1 IndexNode (org.apache.jackrabbit.oak.plugins.index.lucene.IndexNode)1 DefaultIndexReaderFactory (org.apache.jackrabbit.oak.plugins.index.lucene.reader.DefaultIndexReaderFactory)1 LuceneIndexReaderFactory (org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReaderFactory)1