use of org.apache.jackrabbit.oak.query.QueryEngineSettings in project jackrabbit-oak by apache.
the class SolrQueryIndexTest method testNoNegativeCost.
@Test
public void testNoNegativeCost() throws Exception {
NodeState root = InitialContent.INITIAL_CONTENT;
NodeBuilder builder = root.builder();
builder.child("oak:index").child("solr").setProperty("usedProperties", Collections.singleton("name"), Type.STRINGS).setProperty("propertyRestrictions", true).setProperty("type", "solr");
nodeState = builder.getNodeState();
SelectorImpl selector = newSelector(root, "a");
String query = "select * from [nt:base] as a where native('solr','select?q=searchKeywords:\"foo\"^20 text:\"foo\"^1 " + "description:\"foo\"^8 something:\"foo\"^3 headline:\"foo\"^5 title:\"foo\"^10 &q.op=OR'";
String sqlQuery = "select * from [nt:base] a where native('solr','" + query + "'";
SolrClient solrServer = mock(SolrClient.class);
SolrServerProvider solrServerProvider = mock(SolrServerProvider.class);
when(solrServerProvider.getSearchingSolrServer()).thenReturn(solrServer);
OakSolrConfigurationProvider configurationProvider = mock(OakSolrConfigurationProvider.class);
OakSolrConfiguration configuration = new DefaultSolrConfiguration() {
@Override
public boolean useForPropertyRestrictions() {
return true;
}
@Override
public int getRows() {
return 10;
}
};
when(configurationProvider.getConfiguration()).thenReturn(configuration);
SolrQueryIndex solrQueryIndex = new SolrQueryIndex(null, configurationProvider, solrServerProvider);
FilterImpl filter = new FilterImpl(selector, sqlQuery, new QueryEngineSettings());
filter.restrictProperty("native*solr", Operator.EQUAL, PropertyValues.newString(query));
CountingResponse response = new CountingResponse(0);
when(solrServer.query(any(SolrParams.class))).thenReturn(response);
List<QueryIndex.IndexPlan> plans = solrQueryIndex.getPlans(filter, null, nodeState);
for (QueryIndex.IndexPlan p : plans) {
double costPerEntry = p.getCostPerEntry();
assertTrue(costPerEntry >= 0);
double costPerExecution = p.getCostPerExecution();
assertTrue(costPerExecution >= 0);
long estimatedEntryCount = p.getEstimatedEntryCount();
assertTrue(estimatedEntryCount >= 0);
double c = p.getCostPerExecution() + estimatedEntryCount * p.getCostPerEntry();
assertTrue(c >= 0);
}
}
use of org.apache.jackrabbit.oak.query.QueryEngineSettings in project jackrabbit-oak by apache.
the class CursorsTest method intersectionCursorExceptions.
@Test
public void intersectionCursorExceptions() {
QueryEngineSettings s = new QueryEngineSettings();
Cursor a = new SimpleCursor("1:", "/x", "/b", "/c", "/e", "/e", "/c");
Cursor b = new SimpleCursor("2:", "/a", "/c", "/d", "/b", "/c");
Cursor c = Cursors.newIntersectionCursor(a, b, s);
c.next();
c.next();
try {
c.remove();
fail();
} catch (UnsupportedOperationException e) {
// expected
}
try {
c.next();
fail();
} catch (IllegalStateException e) {
// expected
}
}
use of org.apache.jackrabbit.oak.query.QueryEngineSettings in project jackrabbit-oak by apache.
the class CursorsTest method intersectionCursor.
@Test
public void intersectionCursor() {
QueryEngineSettings s = new QueryEngineSettings();
Cursor a = new SimpleCursor("1:", "/b", "/c", "/e", "/e", "/c");
Cursor b = new SimpleCursor("2:", "/a", "/c", "/d", "/b", "/c");
Cursor c = Cursors.newIntersectionCursor(a, b, s);
assertEquals("1:/b, 1:/c", list(c));
assertFalse(c.hasNext());
}
use of org.apache.jackrabbit.oak.query.QueryEngineSettings in project jackrabbit-oak by apache.
the class IndexImporterTest 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.QueryEngineSettings in project jackrabbit-oak by apache.
the class AbstractImportTest method before.
@Before
public void before() throws Exception {
ConfigurationParameters config = getConfigurationParameters();
if (config != null) {
securityProvider = SecurityProviderBuilder.newBuilder().with(config).build();
} else {
securityProvider = SecurityProviderBuilder.newBuilder().build();
}
QueryEngineSettings queryEngineSettings = new QueryEngineSettings();
queryEngineSettings.setFailTraversal(true);
Jcr jcr = new Jcr();
jcr.with(securityProvider);
jcr.with(queryEngineSettings);
repo = jcr.createRepository();
adminSession = repo.login(new SimpleCredentials(UserConstants.DEFAULT_ADMIN_ID, UserConstants.DEFAULT_ADMIN_ID.toCharArray()));
if (!(adminSession instanceof JackrabbitSession)) {
throw new NotExecutableException();
}
userMgr = ((JackrabbitSession) adminSession).getUserManager();
preTestAuthorizables.clear();
Iterator<Authorizable> iter = userMgr.findAuthorizables("rep:principalName", null);
while (iter.hasNext()) {
String id = iter.next().getID();
preTestAuthorizables.add(id);
}
// make sure the target node for group-import exists
Authorizable administrators = userMgr.getAuthorizable(ADMINISTRATORS);
if (userMgr.getAuthorizable(ADMINISTRATORS) == null) {
userMgr.createGroup(new PrincipalImpl(ADMINISTRATORS));
} else if (!administrators.isGroup()) {
throw new NotExecutableException("Expected " + administrators.getID() + " to be a group.");
}
adminSession.save();
}
Aggregations