Search in sources :

Example 1 with FilterImpl

use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.

the class NodeTypeIndexTest method createFilter.

private static FilterImpl createFilter(NodeState root, String nodeTypeName) {
    NodeTypeInfoProvider nodeTypes = new NodeStateNodeTypeInfoProvider(root);
    NodeTypeInfo type = nodeTypes.getNodeTypeInfo(nodeTypeName);
    SelectorImpl selector = new SelectorImpl(type, nodeTypeName);
    return new FilterImpl(selector, "SELECT * FROM [" + nodeTypeName + "]", new QueryEngineSettings());
}
Also used : FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) NodeTypeInfo(org.apache.jackrabbit.oak.query.ast.NodeTypeInfo) SelectorImpl(org.apache.jackrabbit.oak.query.ast.SelectorImpl) QueryEngineSettings(org.apache.jackrabbit.oak.query.QueryEngineSettings) NodeStateNodeTypeInfoProvider(org.apache.jackrabbit.oak.query.NodeStateNodeTypeInfoProvider) NodeTypeInfoProvider(org.apache.jackrabbit.oak.query.ast.NodeTypeInfoProvider) NodeStateNodeTypeInfoProvider(org.apache.jackrabbit.oak.query.NodeStateNodeTypeInfoProvider)

Example 2 with FilterImpl

use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.

the class IndexUpdateTest method find.

private Set<String> find(PropertyIndexLookup lookup, String name, String value) {
    NodeTypeInfoProvider nodeTypes = new NodeStateNodeTypeInfoProvider(root);
    NodeTypeInfo type = nodeTypes.getNodeTypeInfo(NT_BASE);
    SelectorImpl selector = new SelectorImpl(type, NT_BASE);
    Filter filter = new FilterImpl(selector, "SELECT * FROM [nt:base]", new QueryEngineSettings());
    return Sets.newHashSet(lookup.query(filter, name, PropertyValues.newString(value)));
}
Also used : FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) NodeTypeInfo(org.apache.jackrabbit.oak.query.ast.NodeTypeInfo) Filter(org.apache.jackrabbit.oak.spi.query.Filter) SelectorImpl(org.apache.jackrabbit.oak.query.ast.SelectorImpl) QueryEngineSettings(org.apache.jackrabbit.oak.query.QueryEngineSettings) NodeStateNodeTypeInfoProvider(org.apache.jackrabbit.oak.query.NodeStateNodeTypeInfoProvider) NodeTypeInfoProvider(org.apache.jackrabbit.oak.query.ast.NodeTypeInfoProvider) NodeStateNodeTypeInfoProvider(org.apache.jackrabbit.oak.query.NodeStateNodeTypeInfoProvider)

Example 3 with FilterImpl

use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.

the class DiffCollectorTest method testUUIDInner.

@Test
public void testUUIDInner() throws Exception {
    NodeState root = EMPTY_NODE;
    NodeBuilder builder = root.builder();
    builder.child("a").setProperty("jcr:uuid", "abc");
    NodeState before = builder.getNodeState();
    builder = before.builder();
    builder.child("a").child("b").setProperty("jcr:uuid", "xyz");
    NodeState after = builder.getNodeState();
    UUIDDiffCollector collector = new UUIDDiffCollector(before, after);
    FilterImpl f = FilterImpl.newTestInstance();
    f.restrictProperty("jcr:uuid", Operator.EQUAL, PropertyValues.newString("xyz"));
    Set<String> result = collector.getResults(f);
    Iterator<String> iterator = result.iterator();
    assertTrue(iterator.hasNext());
    assertEquals("a/b", iterator.next());
    assertFalse(iterator.hasNext());
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 4 with FilterImpl

use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.

the class DiffCollectorTest method testUUID.

@Test
public void testUUID() throws Exception {
    NodeState root = EMPTY_NODE;
    NodeBuilder builder = root.builder();
    builder.child("a").setProperty("jcr:uuid", "abc");
    builder.child("b").setProperty("jcr:uuid", "xyz");
    NodeState after = builder.getNodeState();
    UUIDDiffCollector collector = new UUIDDiffCollector(root, after);
    FilterImpl f = FilterImpl.newTestInstance();
    f.restrictProperty("jcr:uuid", Operator.EQUAL, PropertyValues.newString("abc"));
    Set<String> result = collector.getResults(f);
    Iterator<String> iterator = result.iterator();
    assertTrue(iterator.hasNext());
    assertEquals("a", iterator.next());
    assertFalse(iterator.hasNext());
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 5 with FilterImpl

use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.

the class PropertyIndexTest method valuePattern.

@Test
public void valuePattern() throws Exception {
    NodeState root = EMPTY_NODE;
    // Add index definitions
    NodeBuilder builder = root.builder();
    NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
    NodeBuilder indexDef = createIndexDefinition(index, "fooIndex", true, false, ImmutableSet.of("foo"), null);
    indexDef.setProperty(IndexConstants.VALUE_PATTERN, "(a.*|b)");
    NodeState before = builder.getNodeState();
    // Add some content and process it through the property index hook
    builder.child("a").setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, Type.NAME).setProperty("foo", "a");
    builder.child("a1").setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, Type.NAME).setProperty("foo", "a1");
    builder.child("b").setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, Type.NAME).setProperty("foo", "b");
    builder.child("c").setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, Type.NAME).setProperty("foo", "c");
    NodeState after = builder.getNodeState();
    // Add an index
    NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
    FilterImpl f = createFilter(after, NT_UNSTRUCTURED);
    // Query the index
    PropertyIndexLookup lookup = new PropertyIndexLookup(indexed);
    PropertyIndex pIndex = new PropertyIndex(Mounts.defaultMountInfoProvider());
    assertEquals(ImmutableSet.of("a"), find(lookup, "foo", "a", f));
    assertEquals(ImmutableSet.of("a1"), find(lookup, "foo", "a1", f));
    assertEquals(ImmutableSet.of("b"), find(lookup, "foo", "b", f));
    // expected: no index for "is not null"
    assertTrue(pIndex.getCost(f, indexed) == Double.POSITIVE_INFINITY);
    ArrayList<PropertyValue> list = new ArrayList<PropertyValue>();
    list.add(PropertyValues.newString("c"));
    f.restrictPropertyAsList("foo", list);
    // expected: no index for value c
    assertTrue(pIndex.getCost(f, indexed) == Double.POSITIVE_INFINITY);
    f = createFilter(after, NT_UNSTRUCTURED);
    list = new ArrayList<PropertyValue>();
    list.add(PropertyValues.newString("a"));
    f.restrictPropertyAsList("foo", list);
    // expected: no index for value a
    assertTrue(pIndex.getCost(f, indexed) < Double.POSITIVE_INFINITY);
}
Also used : EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) ArrayList(java.util.ArrayList) PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Aggregations

FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)98 Test (org.junit.Test)81 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)74 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)39 QueryIndex (org.apache.jackrabbit.oak.spi.query.QueryIndex)28 SelectorImpl (org.apache.jackrabbit.oak.query.ast.SelectorImpl)27 LuceneIndexHelper.newLucenePropertyIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition)26 QueryEngineSettings (org.apache.jackrabbit.oak.query.QueryEngineSettings)26 LuceneIndexHelper.newLuceneIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition)25 AdvancedQueryIndex (org.apache.jackrabbit.oak.spi.query.QueryIndex.AdvancedQueryIndex)15 LinkedList (java.util.LinkedList)14 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)14 NodeStateNodeTypeInfoProvider (org.apache.jackrabbit.oak.query.NodeStateNodeTypeInfoProvider)10 NodeTypeInfo (org.apache.jackrabbit.oak.query.ast.NodeTypeInfo)10 NodeTypeInfoProvider (org.apache.jackrabbit.oak.query.ast.NodeTypeInfoProvider)10 Cursor (org.apache.jackrabbit.oak.spi.query.Cursor)9 IndexPlan (org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan)8 IndexUpdateProvider (org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider)4 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)4 DefaultSolrConfiguration (org.apache.jackrabbit.oak.plugins.index.solr.configuration.DefaultSolrConfiguration)3