Search in sources :

Example 1 with LuceneIndexDefinitionBuilder

use of org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexDefinitionBuilder in project jackrabbit-oak by apache.

the class LuceneIndexEditor2Test method relativeProperties.

@Test
public void relativeProperties() throws Exception {
    LuceneIndexDefinitionBuilder defnb = new LuceneIndexDefinitionBuilder();
    defnb.indexRule("nt:base").property("jcr:content/metadata/foo").propertyIndex();
    defnb.aggregateRule("nt:base").include("*");
    NodeState defnState = defnb.build();
    IndexDefinition defn = new IndexDefinition(root, defnState, indexPath);
    LuceneIndexEditorContext ctx = newContext(defnState.builder(), defn, true);
    ctx.setPropertyUpdateCallback(propCallback);
    EditorHook hook = createHook(ctx);
    updateBefore(defnb);
    // Property added
    NodeBuilder builder = before.builder();
    builder.child("a").child("jcr:content").child("metadata").setProperty("foo", "bar");
    builder.child("a").setProperty("foo2", "bar");
    before = hook.processCommit(root, builder.getNodeState(), CommitInfo.EMPTY);
    propCallback.state.assertState("/a", "jcr:content/metadata/foo", UpdateState.ADDED);
    assertEquals(1, propCallback.invocationCount);
    propCallback.reset();
    // Property updated
    builder = before.builder();
    builder.child("a").child("jcr:content").child("metadata").setProperty("foo", "bar2");
    builder.child("a").setProperty("foo2", "bar2");
    before = hook.processCommit(before, builder.getNodeState(), CommitInfo.EMPTY);
    propCallback.state.assertState("/a", "jcr:content/metadata/foo", UpdateState.UPDATED);
    assertEquals(1, propCallback.invocationCount);
    propCallback.reset();
    // Property deleted
    builder = before.builder();
    builder.child("a").child("jcr:content").child("metadata").removeProperty("foo");
    builder.child("a").removeProperty("foo2");
    before = hook.processCommit(before, builder.getNodeState(), CommitInfo.EMPTY);
    propCallback.state.assertState("/a", "jcr:content/metadata/foo", UpdateState.DELETED);
    assertEquals(1, propCallback.invocationCount);
    propCallback.reset();
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) IndexDefinition(org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) LuceneIndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexDefinitionBuilder) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 2 with LuceneIndexDefinitionBuilder

use of org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexDefinitionBuilder in project jackrabbit-oak by apache.

the class LuceneIndexDefinitionTest method uniqueIsSync.

@Test
public void uniqueIsSync() throws Exception {
    LuceneIndexDefinitionBuilder defnb = new LuceneIndexDefinitionBuilder();
    defnb.indexRule("nt:base").property("foo").unique();
    IndexDefinition defn = IndexDefinition.newBuilder(root, defnb.build(), "/foo").build();
    assertTrue(defn.getApplicableIndexingRule("nt:base").getConfig("foo").sync);
    assertTrue(defn.getApplicableIndexingRule("nt:base").getConfig("foo").unique);
    assertTrue(defn.getApplicableIndexingRule("nt:base").getConfig("foo").propertyIndex);
}
Also used : IndexDefinition(org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition) LuceneIndexHelper.newLucenePropertyIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition) LuceneIndexHelper.newLuceneIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition) LuceneIndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexDefinitionBuilder) Test(org.junit.Test)

Example 3 with LuceneIndexDefinitionBuilder

use of org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexDefinitionBuilder in project jackrabbit-oak by apache.

the class LuceneIndexDefinitionTest method syncIsProperty.

@Test
public void syncIsProperty() throws Exception {
    LuceneIndexDefinitionBuilder defnb = new LuceneIndexDefinitionBuilder();
    defnb.indexRule("nt:base").property("foo").sync();
    IndexDefinition defn = IndexDefinition.newBuilder(root, defnb.build(), "/foo").build();
    assertTrue(defn.getApplicableIndexingRule("nt:base").getConfig("foo").sync);
    assertTrue(defn.getApplicableIndexingRule("nt:base").getConfig("foo").propertyIndex);
}
Also used : IndexDefinition(org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition) LuceneIndexHelper.newLucenePropertyIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition) LuceneIndexHelper.newLuceneIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition) LuceneIndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexDefinitionBuilder) Test(org.junit.Test)

Example 4 with LuceneIndexDefinitionBuilder

use of org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexDefinitionBuilder in project jackrabbit-oak by apache.

the class LuceneIndexDefinitionTest method nodeTypeIndex_mixin.

@Test
public void nodeTypeIndex_mixin() throws Exception {
    TestUtil.registerNodeType(builder, testNodeTypeDefn);
    root = builder.getNodeState();
    LuceneIndexDefinitionBuilder defnb = new LuceneIndexDefinitionBuilder();
    defnb.nodeTypeIndex();
    defnb.indexRule("oak:TestMixA");
    IndexDefinition defn = IndexDefinition.newBuilder(root, defnb.build(), "/foo").build();
    assertFalse(defn.hasSyncPropertyDefinitions());
    assertNotNull(getRule(defn, "oak:TestTypeB"));
    assertTrue(getRule(defn, "oak:TestTypeB").indexesAllNodesOfMatchingType());
    assertNotNull(getRule(defn, "oak:TestMixA"));
    assertTrue(getRule(defn, "oak:TestMixA").indexesAllNodesOfMatchingType());
    assertNull(getRule(defn, "oak:TestTypeA"));
    assertNull(getRule(defn, "oak:TestSuperType"));
}
Also used : IndexDefinition(org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition) LuceneIndexHelper.newLucenePropertyIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition) LuceneIndexHelper.newLuceneIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition) LuceneIndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexDefinitionBuilder) Test(org.junit.Test)

Example 5 with LuceneIndexDefinitionBuilder

use of org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexDefinitionBuilder in project jackrabbit-oak by apache.

the class LuceneIndexDefinitionTest method regexAllProps.

@Test
public void regexAllProps() {
    LuceneIndexDefinitionBuilder builder = new LuceneIndexDefinitionBuilder();
    builder.indexRule("nt:base").property("p");
    builder.indexRule("nt:base").property("all", FulltextIndexConstants.REGEX_ALL_PROPS, true);
    IndexDefinition def = IndexDefinition.newBuilder(root, builder.build(), "/foo").build();
    IndexingRule rule = def.getApplicableIndexingRule(root);
    assertNotNull(rule);
    PropertyDefinition pd = rule.getConfig("p");
    assertNotNull(pd);
    assertFalse(pd.isRegexp);
    assertFalse(pd.relative);
    assertEquals(0, pd.ancestors.length);
    pd = rule.getConfig("all");
    assertNotNull(pd);
    assertTrue(pd.isRegexp);
    assertFalse(pd.relative);
    assertEquals(0, pd.ancestors.length);
    assertThat(rule.getAggregate().getIncludes(), is(empty()));
    assertFalse(rule.getAggregate().hasNodeAggregates());
    List<Aggregate.Matcher> matchers = rule.getAggregate().createMatchers(new TestRoot("/"));
    assertThat(matchers, is(empty()));
    assertThat(def.getRelativeNodeNames(), is(empty()));
}
Also used : IndexingRule(org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition.IndexingRule) IndexDefinition(org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition) LuceneIndexHelper.newLucenePropertyIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition) LuceneIndexHelper.newLuceneIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition) LuceneIndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexDefinitionBuilder) PropertyDefinition(org.apache.jackrabbit.oak.plugins.index.search.PropertyDefinition) Test(org.junit.Test)

Aggregations

LuceneIndexDefinitionBuilder (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexDefinitionBuilder)110 Test (org.junit.Test)94 LuceneIndexHelper.newLuceneIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition)44 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)37 Tree (org.apache.jackrabbit.oak.api.Tree)35 IndexDefinitionBuilder (org.apache.jackrabbit.oak.plugins.index.search.util.IndexDefinitionBuilder)33 FulltextIndexPlanner (org.apache.jackrabbit.oak.plugins.index.search.spi.query.FulltextIndexPlanner)31 QueryIndex (org.apache.jackrabbit.oak.spi.query.QueryIndex)29 AbstractQueryTest (org.apache.jackrabbit.oak.query.AbstractQueryTest)27 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)20 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)20 IndexDefinition (org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition)18 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)18 LuceneIndexHelper.newLucenePropertyIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition)13 OrderEntry (org.apache.jackrabbit.oak.spi.query.QueryIndex.OrderEntry)6 Document (org.apache.lucene.document.Document)6 StringField (org.apache.lucene.document.StringField)6 Directory (org.apache.lucene.store.Directory)6 RAMDirectory (org.apache.lucene.store.RAMDirectory)6 IndexingRule (org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition.IndexingRule)5