Search in sources :

Example 1 with DefaultSolrConfiguration

use of org.apache.jackrabbit.oak.plugins.index.solr.configuration.DefaultSolrConfiguration 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')";
    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());
    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) 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 2 with DefaultSolrConfiguration

use of org.apache.jackrabbit.oak.plugins.index.solr.configuration.DefaultSolrConfiguration 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 DefaultSolrConfiguration

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

the class FilterQueryParserTest method testAllChildrenQueryParsing.

@Test
public void testAllChildrenQueryParsing() throws Exception {
    String query = "select [jcr:path], [jcr:score], * from [nt:hierarchy] as a where isdescendantnode(a, '/')";
    Filter filter = mock(Filter.class);
    OakSolrConfiguration configuration = new DefaultSolrConfiguration() {

        @Override
        public boolean useForPathRestrictions() {
            return true;
        }
    };
    when(filter.getQueryStatement()).thenReturn(query);
    Filter.PathRestriction pathRestriction = Filter.PathRestriction.ALL_CHILDREN;
    when(filter.getPathRestriction()).thenReturn(pathRestriction);
    when(filter.getPath()).thenReturn("/");
    QueryIndex.IndexPlan plan = mock(QueryIndex.IndexPlan.class);
    SolrQuery solrQuery = FilterQueryParser.getQuery(filter, plan, configuration);
    assertNotNull(solrQuery);
    String[] filterQueries = solrQuery.getFilterQueries();
    assertTrue(Arrays.asList(filterQueries).contains(configuration.getFieldForPathRestriction(pathRestriction) + ":\\/"));
    assertEquals("*:*", solrQuery.get("q"));
}
Also used : Filter(org.apache.jackrabbit.oak.spi.query.Filter) DefaultSolrConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.DefaultSolrConfiguration) OakSolrConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration) QueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Example 4 with DefaultSolrConfiguration

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

the class FilterQueryParserTest method testCollapseJcrContentNodes.

@Test
public void testCollapseJcrContentNodes() throws Exception {
    String query = "select [jcr:path], [jcr:score], * from [nt:hierarchy] as a where isdescendantnode(a, '/')";
    Filter filter = mock(Filter.class);
    OakSolrConfiguration configuration = new DefaultSolrConfiguration() {

        @Override
        public boolean collapseJcrContentNodes() {
            return true;
        }
    };
    when(filter.getQueryStatement()).thenReturn(query);
    QueryIndex.IndexPlan plan = mock(QueryIndex.IndexPlan.class);
    SolrQuery solrQuery = FilterQueryParser.getQuery(filter, plan, configuration);
    assertNotNull(solrQuery);
    String[] filterQueries = solrQuery.getFilterQueries();
    assertTrue(Arrays.asList(filterQueries).contains("{!collapse field=" + configuration.getCollapsedPathField() + " min=" + configuration.getPathDepthField() + " hint=top_fc nullPolicy=expand}"));
    assertEquals("*:*", solrQuery.get("q"));
}
Also used : Filter(org.apache.jackrabbit.oak.spi.query.Filter) DefaultSolrConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.DefaultSolrConfiguration) OakSolrConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration) QueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Example 5 with DefaultSolrConfiguration

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

the class SolrIndexEditorTest method testIgnoredPropertiesNotIndexed.

@Test
public void testIgnoredPropertiesNotIndexed() throws Exception {
    NodeBuilder builder = mock(NodeBuilder.class);
    SolrClient solrServer = TestUtils.createSolrServer();
    OakSolrConfiguration configuration = new DefaultSolrConfiguration() {

        @Nonnull
        @Override
        public Collection<String> getIgnoredProperties() {
            return Collections.singletonList("foo2");
        }

        @Nonnull
        @Override
        public CommitPolicy getCommitPolicy() {
            return CommitPolicy.HARD;
        }
    };
    IndexUpdateCallback callback = mock(IndexUpdateCallback.class);
    SolrIndexEditor solrIndexEditor = new SolrIndexEditor(solrServer, configuration, callback);
    NodeState before = mock(NodeState.class);
    NodeState after = mock(NodeState.class);
    Iterable properties = new Iterable<PropertyState>() {

        @Override
        public Iterator<PropertyState> iterator() {
            return Collections.singletonList(PropertyStates.createProperty("foo2", "bar")).iterator();
        }
    };
    when(after.getProperties()).thenReturn(properties);
    solrIndexEditor.leave(before, after);
    QueryResponse queryResponse = solrServer.query(new SolrQuery("foo2:*"));
    assertEquals(0, queryResponse.getResults().getNumFound());
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) SolrClient(org.apache.solr.client.solrj.SolrClient) IndexUpdateCallback(org.apache.jackrabbit.oak.plugins.index.IndexUpdateCallback) DefaultSolrConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.DefaultSolrConfiguration) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) OakSolrConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) SolrQuery(org.apache.solr.client.solrj.SolrQuery) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test)

Aggregations

DefaultSolrConfiguration (org.apache.jackrabbit.oak.plugins.index.solr.configuration.DefaultSolrConfiguration)7 OakSolrConfiguration (org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration)7 Test (org.junit.Test)6 QueryIndex (org.apache.jackrabbit.oak.spi.query.QueryIndex)5 OakSolrConfigurationProvider (org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfigurationProvider)4 SolrServerProvider (org.apache.jackrabbit.oak.plugins.index.solr.server.SolrServerProvider)4 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)4 SolrClient (org.apache.solr.client.solrj.SolrClient)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 SolrQuery (org.apache.solr.client.solrj.SolrQuery)3 Cursor (org.apache.jackrabbit.oak.spi.query.Cursor)2 Filter (org.apache.jackrabbit.oak.spi.query.Filter)2 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)2 SolrParams (org.apache.solr.common.params.SolrParams)2 File (java.io.File)1 IOException (java.io.IOException)1 RepositoryException (javax.jcr.RepositoryException)1 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)1