Search in sources :

Example 1 with SolrServer

use of org.apache.solr.client.solrj.SolrServer in project qi4j-sdk by Qi4j.

the class SolrEntityQueryMixin method findEntities.

@Override
public Iterable<EntityReference> findEntities(Class<?> resultType, @Optional Specification<Composite> whereClause, @Optional OrderBy[] orderBySegments, @Optional Integer firstResult, @Optional Integer maxResults, Map<String, Object> variables) throws EntityFinderException {
    try {
        QuerySpecification expr = (QuerySpecification) whereClause;
        SolrServer server = solr.solrServer();
        NamedList<Object> list = new NamedList<Object>();
        list.add("q", expr.query());
        list.add("rows", maxResults != 0 ? maxResults : 10000);
        list.add("start", firstResult);
        if (orderBySegments != null && orderBySegments.length > 0) {
            for (OrderBy orderBySegment : orderBySegments) {
                String propName = ((Member) orderBySegment.property().accessor()).getName() + "_for_sort";
                String order = orderBySegment.order() == OrderBy.Order.ASCENDING ? "asc" : "desc";
                list.add("sort", propName + " " + order);
            }
        }
        SolrParams solrParams = SolrParams.toSolrParams(list);
        logger.debug("Search:" + list.toString());
        QueryResponse query = server.query(solrParams);
        SolrDocumentList results = query.getResults();
        List<EntityReference> references = new ArrayList<EntityReference>(results.size());
        for (SolrDocument result : results) {
            references.add(EntityReference.parseEntityReference(result.getFirstValue("id").toString()));
        }
        return references;
    } catch (SolrServerException e) {
        throw new EntityFinderException(e);
    }
}
Also used : OrderBy(org.qi4j.api.query.grammar.OrderBy) NamedList(org.apache.solr.common.util.NamedList) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ArrayList(java.util.ArrayList) SolrDocumentList(org.apache.solr.common.SolrDocumentList) SolrServer(org.apache.solr.client.solrj.SolrServer) QuerySpecification(org.qi4j.api.query.grammar.QuerySpecification) SolrDocument(org.apache.solr.common.SolrDocument) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) EntityFinderException(org.qi4j.spi.query.EntityFinderException) EntityReference(org.qi4j.api.entity.EntityReference) SolrParams(org.apache.solr.common.params.SolrParams)

Example 2 with SolrServer

use of org.apache.solr.client.solrj.SolrServer 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());
                SolrServer 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) OakSolrConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration) OakSolrNodeStateConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.nodestate.OakSolrNodeStateConfiguration) SolrServer(org.apache.solr.client.solrj.SolrServer) OakSolrServer(org.apache.jackrabbit.oak.plugins.index.solr.server.OakSolrServer) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException)

Example 3 with SolrServer

use of org.apache.solr.client.solrj.SolrServer in project jackrabbit-oak by apache.

the class SolrServerProviderService method getServer.

private SolrServer getServer() {
    SolrServer solrServer = null;
    if (serverType != null && !"none".equals(serverType)) {
        SolrServerConfigurationProvider solrServerConfigurationProvider = solrServerConfigurationProviders.get(serverType);
        if (solrServerConfigurationProvider != null) {
            try {
                solrServer = new OakSolrServer(solrServerConfigurationProvider);
                log.info("created new SolrServer {}", solrServer);
            } catch (Exception e) {
                log.error("could not get a SolrServerProvider of type {}", serverType, e);
            }
        }
    }
    return solrServer;
}
Also used : SolrServerConfigurationProvider(org.apache.jackrabbit.oak.plugins.index.solr.configuration.SolrServerConfigurationProvider) OakSolrServer(org.apache.jackrabbit.oak.plugins.index.solr.server.OakSolrServer) SolrServer(org.apache.solr.client.solrj.SolrServer) OakSolrServer(org.apache.jackrabbit.oak.plugins.index.solr.server.OakSolrServer) IOException(java.io.IOException)

Example 4 with SolrServer

use of org.apache.solr.client.solrj.SolrServer 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);
        SolrServer 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.getQueryEngineSettings(), 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) OakSolrServer(org.apache.jackrabbit.oak.plugins.index.solr.server.OakSolrServer) SolrServer(org.apache.solr.client.solrj.SolrServer) SolrServerException(org.apache.solr.client.solrj.SolrServerException) Filter(org.apache.jackrabbit.oak.spi.query.Filter)

Example 5 with SolrServer

use of org.apache.solr.client.solrj.SolrServer in project jackrabbit-oak by apache.

the class RemoteSolrServerProvider method getIndexingSolrServer.

@CheckForNull
@Override
public SolrServer getIndexingSolrServer() throws Exception {
    SolrServer server = getSolrServer();
    if (server instanceof HttpSolrServer) {
        String url = ((HttpSolrServer) server).getBaseURL();
        server = new ConcurrentUpdateSolrServer(url, 1000, Runtime.getRuntime().availableProcessors());
    }
    return server;
}
Also used : ConcurrentUpdateSolrServer(org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrServer) HttpSolrServer(org.apache.solr.client.solrj.impl.HttpSolrServer) SolrServer(org.apache.solr.client.solrj.SolrServer) ConcurrentUpdateSolrServer(org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrServer) CloudSolrServer(org.apache.solr.client.solrj.impl.CloudSolrServer) HttpSolrServer(org.apache.solr.client.solrj.impl.HttpSolrServer) CheckForNull(javax.annotation.CheckForNull)

Aggregations

SolrServer (org.apache.solr.client.solrj.SolrServer)40 ManagedSolrServer (org.apache.stanbol.commons.solr.managed.ManagedSolrServer)21 SolrServerException (org.apache.solr.client.solrj.SolrServerException)18 EmbeddedSolrServer (org.apache.solr.client.solrj.embedded.EmbeddedSolrServer)17 ClassifierException (org.apache.stanbol.enhancer.topic.api.ClassifierException)13 IOException (java.io.IOException)12 SolrQuery (org.apache.solr.client.solrj.SolrQuery)12 ConfigurationException (org.osgi.service.cm.ConfigurationException)11 SolrDocument (org.apache.solr.common.SolrDocument)10 TrainingSetException (org.apache.stanbol.enhancer.topic.api.training.TrainingSetException)10 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)10 OakSolrConfiguration (org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration)8 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)8 ArrayList (java.util.ArrayList)7 ChainException (org.apache.stanbol.enhancer.servicesapi.ChainException)7 EngineException (org.apache.stanbol.enhancer.servicesapi.EngineException)7 InvalidContentException (org.apache.stanbol.enhancer.servicesapi.InvalidContentException)7 EntityhubException (org.apache.stanbol.entityhub.servicesapi.EntityhubException)7 SolrInputDocument (org.apache.solr.common.SolrInputDocument)6 Test (org.junit.Test)6