use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.
the class IndexPathServiceImpl method createFilter.
private FilterImpl createFilter(String nodeTypeName) {
NodeTypeInfoProvider nodeTypes = new NodeStateNodeTypeInfoProvider(nodeStore.getRoot());
NodeTypeInfo type = nodeTypes.getNodeTypeInfo(nodeTypeName);
SelectorImpl selector = new SelectorImpl(type, nodeTypeName);
return new FilterImpl(selector, "SELECT * FROM [" + nodeTypeName + "]", settings);
}
use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.
the class AsyncPropertyIndexTest 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());
}
use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.
the class AsyncPropertyIndexTest method testAsyncPropertyLookup.
@Test
public void testAsyncPropertyLookup() throws Exception {
NodeStore store = new MemoryNodeStore();
assertTrue(Iterables.isEmpty(store.checkpoints()));
NodeBuilder builder = store.getRoot().builder();
//add a property index on 'foo'
NodeBuilder def = createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "foo", true, false, of("foo"), null);
def.setProperty(REINDEX_ASYNC_PROPERTY_NAME, true);
// add some content
builder.child("a").setProperty("foo", "abc");
builder.child("b").setProperty("foo", Arrays.asList("abc", "def"), STRINGS);
NodeState head = store.merge(builder, hook, EMPTY);
// query the index, check it doesn't get indexed by the normal PI
FilterImpl f = createFilter(head, NT_BASE);
PropertyIndexLookup lookup = new PropertyIndexLookup(head);
try {
assertEquals(of(), find(lookup, "foo", "abc", f));
fail();
} catch (IllegalArgumentException e) {
// expected: no index for "foo"
}
// run async first time, there are some changes
AsyncIndexUpdate async = new AsyncIndexUpdate(ASYNC_REINDEX_VALUE, store, provider, true);
async.run();
assertEquals(ASYNC_REINDEX_VALUE, store.getRoot().getChildNode(INDEX_DEFINITIONS_NAME).getChildNode("foo").getString(ASYNC_PROPERTY_NAME));
// run async second time, there are no changes, should switch to sync
async.run();
async.close();
assertEquals(null, store.getRoot().getChildNode(INDEX_DEFINITIONS_NAME).getChildNode("foo").getString(ASYNC_PROPERTY_NAME));
assertTrue(Iterables.isEmpty(store.checkpoints()));
// add content, it should be indexed synchronously
builder = store.getRoot().builder();
builder.child("c").setProperty("foo", "def");
head = store.merge(builder, hook, EMPTY);
f = createFilter(head, NT_BASE);
lookup = new PropertyIndexLookup(head);
assertEquals(ImmutableSet.of("b", "c"), find(lookup, "foo", "def", f));
}
use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.
the class PropertyIndexLookupTest 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());
}
use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.
the class NodeTypeIndexTest method nodeType.
@Test
public void nodeType() throws Exception {
NodeBuilder root = store.getRoot().builder();
// remove "rep:security" as it interferes with tests
root.getChildNode("rep:security").remove();
// set "entryCount", so the node type index counts the nodes
// and the approximation is not used
root.getChildNode("oak:index").getChildNode("nodetype").setProperty("entryCount", -1);
addFolder(root, "folder-1");
addFolder(root, "folder-2");
addFile(root, "file-1");
store.merge(root, new EditorHook(new IndexUpdateProvider(new PropertyIndexEditorProvider())), CommitInfo.EMPTY);
NodeState rootState = store.getRoot();
NodeTypeIndex index = new NodeTypeIndex(Mounts.defaultMountInfoProvider());
FilterImpl filter;
filter = createFilter(rootState, JcrConstants.NT_FOLDER);
assertEquals(6.0, index.getCost(filter, rootState), 0.0);
checkCursor(index.query(filter, rootState), "/folder-1", "/folder-2");
filter = createFilter(rootState, JcrConstants.NT_FILE);
assertEquals(5.0, index.getCost(filter, rootState), 0.0);
checkCursor(index.query(filter, rootState), "/file-1");
filter = createFilter(rootState, JcrConstants.NT_HIERARCHYNODE);
assertEquals(7.0, index.getCost(filter, rootState), 0.0);
checkCursor(index.query(filter, rootState), "/folder-1", "/folder-2", "/file-1");
}
Aggregations