use of org.apache.jackrabbit.oak.query.ast.SelectorImpl in project jackrabbit-oak by apache.
the class SolrQueryIndexTest method newSelector.
private static SelectorImpl newSelector(NodeState root, String name) {
NodeTypeInfoProvider types = new NodeStateNodeTypeInfoProvider(root);
NodeTypeInfo type = types.getNodeTypeInfo("nt:base");
return new SelectorImpl(type, name);
}
use of org.apache.jackrabbit.oak.query.ast.SelectorImpl in project jackrabbit-oak by apache.
the class SolrQueryIndexTest method testPlanWithPropertyAndPathRestrictionsEnabled.
@Test
public void testPlanWithPropertyAndPathRestrictionsEnabled() throws Exception {
NodeBuilder builder = nodeState.builder();
builder.child("oak:index").child("solr").setProperty("pathRestrictions", true).setProperty("propertyRestrictions", true);
nodeState = builder.getNodeState();
SelectorImpl selector = newSelector(nodeState, "a");
SolrQueryIndex solrQueryIndex = new SolrQueryIndex(null, null, null);
FilterImpl filter = new FilterImpl(selector, "select * from [nt:base] as a where isdescendantnode(a, '/test')", new QueryEngineSettings());
filter.restrictPath("/test", Filter.PathRestriction.ALL_CHILDREN);
filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar"));
List<QueryIndex.OrderEntry> sortOrder = new LinkedList<QueryIndex.OrderEntry>();
List<QueryIndex.IndexPlan> plans = solrQueryIndex.getPlans(filter, sortOrder, nodeState);
assertEquals(1, plans.size());
}
use of org.apache.jackrabbit.oak.query.ast.SelectorImpl in project jackrabbit-oak by apache.
the class SolrQueryIndexTest method testSize.
@Test
public void testSize() throws Exception {
NodeState root = InitialContent.INITIAL_CONTENT;
SelectorImpl selector = newSelector(root, "a");
String sqlQuery = "select [jcr:path], [jcr:score] from [nt:base] as a where" + " contains([jcr:content/*], 'founded')";
SolrServerProvider solrServerProvider = mock(SolrServerProvider.class);
OakSolrConfigurationProvider configurationProvider = mock(OakSolrConfigurationProvider.class);
OakSolrConfiguration configuration = new DefaultSolrConfiguration() {
@Override
public boolean useForPropertyRestrictions() {
return true;
}
};
when(configurationProvider.getConfiguration()).thenReturn(configuration);
SolrQueryIndex solrQueryIndex = new SolrQueryIndex(null, configurationProvider, solrServerProvider);
FilterImpl filter = new FilterImpl(selector, sqlQuery, new QueryEngineSettings());
List<QueryIndex.IndexPlan> plans = solrQueryIndex.getPlans(filter, null, root);
for (QueryIndex.IndexPlan p : plans) {
Cursor cursor = solrQueryIndex.query(p, root);
assertNotNull(cursor);
long sizeExact = cursor.getSize(Result.SizePrecision.EXACT, 100000);
long sizeApprox = cursor.getSize(Result.SizePrecision.APPROXIMATION, 100000);
long sizeFastApprox = cursor.getSize(Result.SizePrecision.FAST_APPROXIMATION, 100000);
assertTrue(Math.abs(sizeExact - sizeApprox) < 10);
assertTrue(Math.abs(sizeExact - sizeFastApprox) > 10000);
}
}
use of org.apache.jackrabbit.oak.query.ast.SelectorImpl in project jackrabbit-oak by apache.
the class SolrQueryIndexTest method testNoPlanWithPropertyRestrictionsEnabledButNotUsedProperty.
@Test
public void testNoPlanWithPropertyRestrictionsEnabledButNotUsedProperty() throws Exception {
NodeBuilder builder = nodeState.builder();
builder.child("oak:index").child("solr").setProperty("usedProperties", Collections.singleton("foo"), Type.STRINGS).setProperty("propertyRestrictions", true);
nodeState = builder.getNodeState();
SelectorImpl selector = newSelector(nodeState, "a");
SolrQueryIndex solrQueryIndex = new SolrQueryIndex(null, null, null);
FilterImpl filter = new FilterImpl(selector, "select * from [nt:base] as a where name = 'hello')", new QueryEngineSettings());
filter.restrictProperty("name", Operator.EQUAL, PropertyValues.newString("hello"));
List<QueryIndex.OrderEntry> sortOrder = new LinkedList<QueryIndex.OrderEntry>();
List<QueryIndex.IndexPlan> plans = solrQueryIndex.getPlans(filter, sortOrder, nodeState);
assertEquals(0, plans.size());
}
use of org.apache.jackrabbit.oak.query.ast.SelectorImpl in project jackrabbit-oak by apache.
the class SolrQueryIndexTest method testPlanWithPropertyRestrictionsEnabled.
@Test
public void testPlanWithPropertyRestrictionsEnabled() throws Exception {
NodeBuilder builder = nodeState.builder();
builder.child("oak:index").child("solr").setProperty("propertyRestrictions", true);
nodeState = builder.getNodeState();
SelectorImpl selector = newSelector(nodeState, "a");
SolrQueryIndex solrQueryIndex = new SolrQueryIndex(null, null, null);
FilterImpl filter = new FilterImpl(selector, "select * from [nt:base] as a where name = 'hello')", new QueryEngineSettings());
filter.restrictProperty("name", Operator.EQUAL, PropertyValues.newString("hello"));
List<QueryIndex.OrderEntry> sortOrder = new LinkedList<QueryIndex.OrderEntry>();
List<QueryIndex.IndexPlan> plans = solrQueryIndex.getPlans(filter, sortOrder, nodeState);
assertEquals(1, plans.size());
}
Aggregations