Search in sources :

Example 41 with QueryEngineSettings

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);
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) QueryEngineSettings(org.apache.jackrabbit.oak.query.QueryEngineSettings) OakSolrConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) OakSolrConfigurationProvider(org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfigurationProvider) SolrClient(org.apache.solr.client.solrj.SolrClient) SolrServerProvider(org.apache.jackrabbit.oak.plugins.index.solr.server.SolrServerProvider) SelectorImpl(org.apache.jackrabbit.oak.query.ast.SelectorImpl) DefaultSolrConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.DefaultSolrConfiguration) SolrParams(org.apache.solr.common.params.SolrParams) QueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex) Test(org.junit.Test)

Example 42 with QueryEngineSettings

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
    }
}
Also used : QueryEngineSettings(org.apache.jackrabbit.oak.query.QueryEngineSettings) Cursor(org.apache.jackrabbit.oak.spi.query.Cursor) Test(org.junit.Test)

Example 43 with QueryEngineSettings

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());
}
Also used : QueryEngineSettings(org.apache.jackrabbit.oak.query.QueryEngineSettings) Cursor(org.apache.jackrabbit.oak.spi.query.Cursor) Test(org.junit.Test)

Example 44 with QueryEngineSettings

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());
}
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 45 with 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();
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) QueryEngineSettings(org.apache.jackrabbit.oak.query.QueryEngineSettings) Jcr(org.apache.jackrabbit.oak.jcr.Jcr) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) ConfigurationParameters(org.apache.jackrabbit.oak.spi.security.ConfigurationParameters) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) Before(org.junit.Before)

Aggregations

QueryEngineSettings (org.apache.jackrabbit.oak.query.QueryEngineSettings)49 SelectorImpl (org.apache.jackrabbit.oak.query.ast.SelectorImpl)29 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)29 Test (org.junit.Test)24 QueryIndex (org.apache.jackrabbit.oak.spi.query.QueryIndex)17 LinkedList (java.util.LinkedList)14 NodeStateNodeTypeInfoProvider (org.apache.jackrabbit.oak.query.NodeStateNodeTypeInfoProvider)12 NodeTypeInfo (org.apache.jackrabbit.oak.query.ast.NodeTypeInfo)12 NodeTypeInfoProvider (org.apache.jackrabbit.oak.query.ast.NodeTypeInfoProvider)12 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)10 Jcr (org.apache.jackrabbit.oak.jcr.Jcr)5 Cursor (org.apache.jackrabbit.oak.spi.query.Cursor)4 Before (org.junit.Before)4 SimpleCredentials (javax.jcr.SimpleCredentials)3 DefaultSolrConfiguration (org.apache.jackrabbit.oak.plugins.index.solr.configuration.DefaultSolrConfiguration)3 OakSolrConfiguration (org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration)3 OakSolrConfigurationProvider (org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfigurationProvider)3 SolrServerProvider (org.apache.jackrabbit.oak.plugins.index.solr.server.SolrServerProvider)3 ConfigurationParameters (org.apache.jackrabbit.oak.spi.security.ConfigurationParameters)3 SecurityProvider (org.apache.jackrabbit.oak.spi.security.SecurityProvider)3