Search in sources :

Example 6 with OakSolrConfiguration

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

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

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

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

Example 10 with OakSolrConfiguration

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

the class SolrQueryIndex method getPlans.

@Override
public List<IndexPlan> getPlans(Filter filter, List<OrderEntry> sortOrder, NodeState rootState) {
    Collection<String> indexPaths = new SolrIndexLookup(rootState).collectIndexNodePaths(filter);
    List<IndexPlan> plans = Lists.newArrayListWithCapacity(indexPaths.size());
    for (String path : indexPaths) {
        OakSolrConfiguration configuration = getConfiguration(path, rootState);
        SolrClient solrServer = getServer(path, rootState);
        // only provide the plan if both valid configuration and server exist
        if (configuration != null && solrServer != null) {
            LMSEstimator estimator = getEstimator(path);
            IndexPlan plan = getIndexPlan(filter, configuration, estimator, sortOrder, path);
            if (plan != null) {
                plans.add(plan);
            }
        }
    }
    return plans;
}
Also used : SolrClient(org.apache.solr.client.solrj.SolrClient) OakSolrConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration)

Aggregations

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