Search in sources :

Example 1 with OakSolrConfiguration

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

the class FilterQueryParserTest method testMatchAllConversionWithNoConstraints.

@Test
public void testMatchAllConversionWithNoConstraints() throws Exception {
    Filter filter = mock(Filter.class);
    OakSolrConfiguration configuration = mock(OakSolrConfiguration.class);
    QueryIndex.IndexPlan plan = mock(QueryIndex.IndexPlan.class);
    SolrQuery solrQuery = FilterQueryParser.getQuery(filter, plan, configuration);
    assertNotNull(solrQuery);
    assertEquals("*:*", solrQuery.getQuery());
}
Also used : Filter(org.apache.jackrabbit.oak.spi.query.Filter) 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 2 with OakSolrConfiguration

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

the class SolrIndexEditorTest method testIndexedProperties.

@Test
public void testIndexedProperties() throws Exception {
    SolrClient solrServer = TestUtils.createSolrServer();
    OakSolrConfiguration configuration = TestUtils.getTestConfiguration();
    IndexUpdateCallback callback = mock(IndexUpdateCallback.class);
    SolrIndexEditor solrIndexEditor = new SolrIndexEditor(solrServer, configuration, callback);
    NodeState before = mock(NodeState.class);
    NodeState after = mock(NodeState.class);
    Iterable properties = (Iterable<PropertyState>) () -> Collections.singletonList(PropertyStates.createProperty("foo1", "bar")).iterator();
    when(after.getProperties()).thenReturn(properties);
    solrIndexEditor.leave(before, after);
    QueryResponse queryResponse = solrServer.query(new SolrQuery("foo1:*"));
    assertEquals(1, 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) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) OakSolrConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Example 3 with OakSolrConfiguration

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

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

the class SolrQueryIndex method query.

@Override
public Cursor query(final IndexPlan plan, final NodeState root) {
    Cursor cursor;
    try {
        Filter filter = plan.getFilter();
        final Set<String> relPaths = filter.getFullTextConstraint() != null ? getRelativePaths(filter.getFullTextConstraint()) : Collections.<String>emptySet();
        final String parent = relPaths.size() == 0 ? "" : relPaths.iterator().next();
        final int parentDepth = getDepth(parent);
        String path = plan.getPlanName();
        OakSolrConfiguration configuration = getConfiguration(path, root);
        SolrClient solrServer = getServer(path, root);
        LMSEstimator estimator = getEstimator(path);
        AbstractIterator<SolrResultRow> iterator = getIterator(filter, plan, parent, parentDepth, configuration, solrServer, estimator);
        cursor = new SolrRowCursor(iterator, plan, filter.getQueryLimits(), estimator, solrServer, configuration);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return cursor;
}
Also used : OakSolrConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration) Cursor(org.apache.jackrabbit.oak.spi.query.Cursor) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException) Filter(org.apache.jackrabbit.oak.spi.query.Filter) SolrClient(org.apache.solr.client.solrj.SolrClient)

Example 5 with OakSolrConfiguration

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

the class SolrIndexEditorProvider method getIndexEditor.

@Override
public Editor getIndexEditor(@Nonnull String type, @Nonnull NodeBuilder definition, @Nonnull NodeState root, @Nonnull IndexUpdateCallback callback) throws CommitFailedException {
    SolrIndexEditor editor = null;
    if (SolrQueryIndex.TYPE.equals(type)) {
        try {
            // if index definition contains a persisted configuration, use that
            if (isPersistedConfiguration(definition)) {
                NodeState nodeState = definition.getNodeState();
                OakSolrConfiguration configuration = new OakSolrNodeStateConfiguration(nodeState);
                SolrServerConfigurationProvider configurationProvider = new NodeStateSolrServerConfigurationProvider(definition.getChildNode("server").getNodeState());
                SolrClient solrServer = new OakSolrServer(configurationProvider);
                editor = getEditor(configuration, solrServer, callback);
            } else {
                // otherwise use the default configuration providers (e.g. defined via code or OSGi)
                OakSolrConfiguration configuration = oakSolrConfigurationProvider.getConfiguration();
                editor = getEditor(configuration, solrServerProvider.getIndexingSolrServer(), callback);
            }
        } catch (Exception e) {
            log.warn("could not get Solr index editor from {}", definition.getNodeState(), e);
        }
    }
    return editor;
}
Also used : NodeStateSolrServerConfigurationProvider(org.apache.jackrabbit.oak.plugins.index.solr.configuration.nodestate.NodeStateSolrServerConfigurationProvider) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) NodeStateSolrServerConfigurationProvider(org.apache.jackrabbit.oak.plugins.index.solr.configuration.nodestate.NodeStateSolrServerConfigurationProvider) SolrServerConfigurationProvider(org.apache.jackrabbit.oak.plugins.index.solr.configuration.SolrServerConfigurationProvider) OakSolrServer(org.apache.jackrabbit.oak.plugins.index.solr.server.OakSolrServer) SolrClient(org.apache.solr.client.solrj.SolrClient) OakSolrConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration) OakSolrNodeStateConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.nodestate.OakSolrNodeStateConfiguration) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException)

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