Search in sources :

Example 1 with OakSolrConfigurationProvider

use of org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfigurationProvider in project jackrabbit-oak by apache.

the class SolrQueryIndexTest method testNoMoreThanThreeSolrRequests.

@Test
public void testNoMoreThanThreeSolrRequests() 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')";
    SolrServer solrServer = mock(SolrServer.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());
    CountingResponse response = new CountingResponse(0);
    when(solrServer.query(any(SolrParams.class))).thenReturn(response);
    List<QueryIndex.IndexPlan> plans = solrQueryIndex.getPlans(filter, null, root);
    for (QueryIndex.IndexPlan p : plans) {
        Cursor cursor = solrQueryIndex.query(p, root);
        assertNotNull(cursor);
        while (cursor.hasNext()) {
            IndexRow row = cursor.next();
            assertNotNull(row);
        }
        assertEquals(3, response.getCounter());
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) IndexRow(org.apache.jackrabbit.oak.spi.query.IndexRow) QueryEngineSettings(org.apache.jackrabbit.oak.query.QueryEngineSettings) OakSolrConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration) Cursor(org.apache.jackrabbit.oak.spi.query.Cursor) SolrServer(org.apache.solr.client.solrj.SolrServer) OakSolrConfigurationProvider(org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfigurationProvider) 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 2 with OakSolrConfigurationProvider

use of org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfigurationProvider 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);
    }
}
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) Cursor(org.apache.jackrabbit.oak.spi.query.Cursor) OakSolrConfigurationProvider(org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfigurationProvider) 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) QueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex) Test(org.junit.Test)

Example 3 with OakSolrConfigurationProvider

use of org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfigurationProvider 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 + "'";
    SolrServer solrServer = mock(SolrServer.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) SolrServer(org.apache.solr.client.solrj.SolrServer) OakSolrConfigurationProvider(org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfigurationProvider) 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 4 with OakSolrConfigurationProvider

use of org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfigurationProvider in project jackrabbit-oak by apache.

the class SolrOakRepositoryStub method preCreateRepository.

@Override
protected void preCreateRepository(Jcr jcr) {
    String path = getClass().getResource("/").getFile() + "/queryjcrtest";
    File f = new File(path);
    final SolrServer solrServer;
    try {
        solrServer = new EmbeddedSolrServerProvider(new EmbeddedSolrServerConfiguration(f.getPath(), "oak")).getSolrServer();
    } catch (Exception e) {
        throw new RuntimeException();
    }
    SolrServerProvider solrServerProvider = new SolrServerProvider() {

        @Override
        public void close() throws IOException {
        }

        @CheckForNull
        @Override
        public SolrServer getSolrServer() throws Exception {
            return solrServer;
        }

        @Override
        public SolrServer getIndexingSolrServer() throws Exception {
            return solrServer;
        }

        @Override
        public SolrServer getSearchingSolrServer() throws Exception {
            return solrServer;
        }
    };
    try {
        // safely remove any previous document on the index
        solrServer.deleteByQuery("*:*");
        solrServer.commit();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    OakSolrConfiguration configuration = new DefaultSolrConfiguration() {

        @Nonnull
        @Override
        public CommitPolicy getCommitPolicy() {
            return CommitPolicy.HARD;
        }
    };
    OakSolrConfigurationProvider oakSolrConfigurationProvider = new DefaultSolrConfigurationProvider(configuration);
    jcr.with(new SolrIndexInitializer(false)).with(AggregateIndexProvider.wrap(new SolrQueryIndexProvider(solrServerProvider, oakSolrConfigurationProvider))).with(new NodeStateSolrServersObserver()).with(new SolrIndexEditorProvider(solrServerProvider, oakSolrConfigurationProvider));
}
Also used : EmbeddedSolrServerConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.EmbeddedSolrServerConfiguration) DefaultSolrConfigurationProvider(org.apache.jackrabbit.oak.plugins.index.solr.configuration.DefaultSolrConfigurationProvider) OakSolrConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration) SolrIndexInitializer(org.apache.jackrabbit.oak.plugins.index.solr.util.SolrIndexInitializer) SolrServer(org.apache.solr.client.solrj.SolrServer) IOException(java.io.IOException) RepositoryException(javax.jcr.RepositoryException) OakSolrConfigurationProvider(org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfigurationProvider) EmbeddedSolrServerProvider(org.apache.jackrabbit.oak.plugins.index.solr.server.EmbeddedSolrServerProvider) SolrServerProvider(org.apache.jackrabbit.oak.plugins.index.solr.server.SolrServerProvider) SolrQueryIndexProvider(org.apache.jackrabbit.oak.plugins.index.solr.query.SolrQueryIndexProvider) EmbeddedSolrServerProvider(org.apache.jackrabbit.oak.plugins.index.solr.server.EmbeddedSolrServerProvider) NodeStateSolrServersObserver(org.apache.jackrabbit.oak.plugins.index.solr.configuration.nodestate.NodeStateSolrServersObserver) DefaultSolrConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.DefaultSolrConfiguration) File(java.io.File) SolrIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.solr.index.SolrIndexEditorProvider)

Aggregations

DefaultSolrConfiguration (org.apache.jackrabbit.oak.plugins.index.solr.configuration.DefaultSolrConfiguration)4 OakSolrConfiguration (org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration)4 OakSolrConfigurationProvider (org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfigurationProvider)4 SolrServerProvider (org.apache.jackrabbit.oak.plugins.index.solr.server.SolrServerProvider)4 QueryEngineSettings (org.apache.jackrabbit.oak.query.QueryEngineSettings)3 SelectorImpl (org.apache.jackrabbit.oak.query.ast.SelectorImpl)3 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)3 QueryIndex (org.apache.jackrabbit.oak.spi.query.QueryIndex)3 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)3 SolrServer (org.apache.solr.client.solrj.SolrServer)3 Test (org.junit.Test)3 Cursor (org.apache.jackrabbit.oak.spi.query.Cursor)2 SolrParams (org.apache.solr.common.params.SolrParams)2 File (java.io.File)1 IOException (java.io.IOException)1 RepositoryException (javax.jcr.RepositoryException)1 DefaultSolrConfigurationProvider (org.apache.jackrabbit.oak.plugins.index.solr.configuration.DefaultSolrConfigurationProvider)1 EmbeddedSolrServerConfiguration (org.apache.jackrabbit.oak.plugins.index.solr.configuration.EmbeddedSolrServerConfiguration)1 NodeStateSolrServersObserver (org.apache.jackrabbit.oak.plugins.index.solr.configuration.nodestate.NodeStateSolrServersObserver)1 SolrIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.solr.index.SolrIndexEditorProvider)1