Search in sources :

Example 11 with SolrQueryRequest

use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.

the class LTRScoringQuery method createWeights.

private void createWeights(IndexSearcher searcher, boolean needsScores, List<Feature.FeatureWeight> featureWeights, Collection<Feature> features) throws IOException {
    final SolrQueryRequest req = getRequest();
    // since the feature store is a linkedhashmap order is preserved
    for (final Feature f : features) {
        try {
            Feature.FeatureWeight fw = f.createWeight(searcher, needsScores, req, originalQuery, efi);
            featureWeights.add(fw);
        } catch (final Exception e) {
            throw new RuntimeException("Exception from createWeight for " + f.toString() + " " + e.getMessage(), e);
        }
    }
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) Feature(org.apache.solr.ltr.feature.Feature) IOException(java.io.IOException)

Example 12 with SolrQueryRequest

use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.

the class UpdateRequestHandlerApi method getApiImpl.

private Api getApiImpl() {
    return new Api(ApiBag.getSpec("core.Update")) {

        @Override
        public void call(SolrQueryRequest req, SolrQueryResponse rsp) {
            String path = req.getPath();
            String target = mapping.get(path);
            if (target != null)
                req.getContext().put("path", target);
            try {
                handleRequest(req, rsp);
            } catch (RuntimeException e) {
                throw e;
            } catch (Exception e) {
                throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
            }
        }
    };
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) Api(org.apache.solr.api.Api) SolrException(org.apache.solr.common.SolrException) SolrException(org.apache.solr.common.SolrException)

Example 13 with SolrQueryRequest

use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.

the class BaseHandlerApiSupport method getApi.

private Api getApi(final V2EndPoint op) {
    final BaseHandlerApiSupport apiHandler = this;
    return new Api(ApiBag.getSpec(op.getSpecName())) {

        @Override
        public void call(SolrQueryRequest req, SolrQueryResponse rsp) {
            SolrParams params = req.getParams();
            SolrRequest.METHOD method = SolrRequest.METHOD.valueOf(req.getHttpMethod());
            List<ApiCommand> commands = commandsMapping.get(method).get(op);
            try {
                if (method == POST) {
                    List<CommandOperation> cmds = req.getCommands(true);
                    if (cmds.size() > 1)
                        throw new SolrException(BAD_REQUEST, "Only one command is allowed");
                    CommandOperation c = cmds.size() == 0 ? null : cmds.get(0);
                    ApiCommand command = null;
                    String commandName = c == null ? null : c.name;
                    for (ApiCommand cmd : commands) {
                        if (Objects.equals(cmd.meta().getName(), commandName)) {
                            command = cmd;
                            break;
                        }
                    }
                    if (command == null) {
                        throw new SolrException(BAD_REQUEST, " no such command " + c);
                    }
                    wrapParams(req, c, command, false);
                    command.invoke(req, rsp, apiHandler);
                } else {
                    if (commands == null || commands.isEmpty()) {
                        rsp.add("error", "No support for : " + method + " at :" + req.getPath());
                        return;
                    }
                    if (commands.size() > 1) {
                        for (ApiCommand command : commands) {
                            if (command.meta().getName().equals(req.getPath())) {
                                commands = Collections.singletonList(command);
                                break;
                            }
                        }
                    }
                    wrapParams(req, new CommandOperation("", Collections.EMPTY_MAP), commands.get(0), true);
                    commands.get(0).invoke(req, rsp, apiHandler);
                }
            } catch (SolrException e) {
                throw e;
            } catch (Exception e) {
                throw new SolrException(BAD_REQUEST, e);
            } finally {
                req.setParams(params);
            }
        }
    };
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) CommandOperation(org.apache.solr.common.util.CommandOperation) SolrRequest(org.apache.solr.client.solrj.SolrRequest) SolrException(org.apache.solr.common.SolrException) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrParams(org.apache.solr.common.params.SolrParams) Api(org.apache.solr.api.Api) SolrException(org.apache.solr.common.SolrException)

Example 14 with SolrQueryRequest

use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.

the class CommitTracker method run.

/** This is the worker part for the ScheduledFuture **/
@Override
public void run() {
    synchronized (this) {
        // log.info("###start commit. pending=null");
        // allow a new commit to be scheduled
        pending = null;
    }
    SolrQueryRequest req = new LocalSolrQueryRequest(core, new ModifiableSolrParams());
    try {
        CommitUpdateCommand command = new CommitUpdateCommand(req, false);
        command.openSearcher = openSearcher;
        command.waitSearcher = WAIT_SEARCHER;
        command.softCommit = softCommit;
        if (core.getCoreDescriptor().getCloudDescriptor() != null && core.getCoreDescriptor().getCloudDescriptor().isLeader() && !softCommit) {
            command.version = core.getUpdateHandler().getUpdateLog().getVersionInfo().getNewClock();
        }
        // no need for command.maxOptimizeSegments = 1; since it is not optimizing
        // we increment this *before* calling commit because it was causing a race
        // in the tests (the new searcher was registered and the test proceeded
        // to check the commit count before we had incremented it.)
        autoCommitCount.incrementAndGet();
        core.getUpdateHandler().commit(command);
    } catch (Exception e) {
        SolrException.log(log, "auto commit error...", e);
    } finally {
        // log.info("###done committing");
        req.close();
    }
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrException(org.apache.solr.common.SolrException)

Example 15 with SolrQueryRequest

use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.

the class CdcrUpdateLog method copyBufferedUpdates.

/**
   * <p>
   *   Read the entries from the given tlog file and replay them as buffered updates.
   *   The buffered tlog that we are trying to copy might contain duplicate operations with the
   *   current update log. During the tlog replication process, the replica might buffer update operations
   *   that will be present also in the tlog files downloaded from the leader. In order to remove these
   *   duplicates, it will skip any operations with a version inferior to the latest know version.
   */
private void copyBufferedUpdates(File tlogSrc, long offsetSrc, long latestVersion) {
    recoveryInfo = new RecoveryInfo();
    recoveryInfo.positionOfStart = tlog == null ? 0 : tlog.snapshot();
    state = State.BUFFERING;
    operationFlags |= FLAG_GAP;
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set(DistributingUpdateProcessorFactory.DISTRIB_UPDATE_PARAM, DistributedUpdateProcessor.DistribPhase.FROMLEADER.toString());
    SolrQueryRequest req = new LocalSolrQueryRequest(uhandler.core, params);
    CdcrTransactionLog src = new CdcrTransactionLog(tlogSrc, null, true);
    TransactionLog.LogReader tlogReader = src.getReader(offsetSrc);
    try {
        int operationAndFlags = 0;
        for (; ; ) {
            Object o = tlogReader.next();
            // we reached the end of the tlog
            if (o == null)
                break;
            // should currently be a List<Oper,Ver,Doc/Id>
            List entry = (List) o;
            operationAndFlags = (Integer) entry.get(0);
            int oper = operationAndFlags & OPERATION_MASK;
            long version = (Long) entry.get(1);
            if (version <= latestVersion) {
                // probably a buffered update that is also present in a tlog file coming from the leader,
                // skip it.
                log.debug("Dropping buffered operation - version {} < {}", version, latestVersion);
                continue;
            }
            switch(oper) {
                case UpdateLog.ADD:
                    {
                        SolrInputDocument sdoc = (SolrInputDocument) entry.get(entry.size() - 1);
                        AddUpdateCommand cmd = new AddUpdateCommand(req);
                        cmd.solrDoc = sdoc;
                        cmd.setVersion(version);
                        cmd.setFlags(UpdateCommand.BUFFERING);
                        this.add(cmd);
                        break;
                    }
                case UpdateLog.DELETE:
                    {
                        byte[] idBytes = (byte[]) entry.get(2);
                        DeleteUpdateCommand cmd = new DeleteUpdateCommand(req);
                        cmd.setIndexedId(new BytesRef(idBytes));
                        cmd.setVersion(version);
                        cmd.setFlags(UpdateCommand.BUFFERING);
                        this.delete(cmd);
                        break;
                    }
                case UpdateLog.DELETE_BY_QUERY:
                    {
                        String query = (String) entry.get(2);
                        DeleteUpdateCommand cmd = new DeleteUpdateCommand(req);
                        cmd.query = query;
                        cmd.setVersion(version);
                        cmd.setFlags(UpdateCommand.BUFFERING);
                        this.deleteByQuery(cmd);
                        break;
                    }
                default:
                    throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Invalid Operation! " + oper);
            }
        }
    } catch (Exception e) {
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unable to copy buffered updates", e);
    } finally {
        try {
            tlogReader.close();
        } finally {
            this.doClose(src);
        }
    }
}
Also used : ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) IOException(java.io.IOException) SolrException(org.apache.solr.common.SolrException) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrInputDocument(org.apache.solr.common.SolrInputDocument) ArrayList(java.util.ArrayList) List(java.util.List) BytesRef(org.apache.lucene.util.BytesRef) SolrException(org.apache.solr.common.SolrException)

Aggregations

SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)362 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)148 Test (org.junit.Test)143 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)129 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)106 SolrCore (org.apache.solr.core.SolrCore)58 ArrayList (java.util.ArrayList)49 NamedList (org.apache.solr.common.util.NamedList)48 SolrInputDocument (org.apache.solr.common.SolrInputDocument)45 HashMap (java.util.HashMap)43 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)37 SolrParams (org.apache.solr.common.params.SolrParams)36 SolrException (org.apache.solr.common.SolrException)34 IOException (java.io.IOException)24 Query (org.apache.lucene.search.Query)24 BufferingRequestProcessor (org.apache.solr.update.processor.BufferingRequestProcessor)24 List (java.util.List)23 MapSolrParams (org.apache.solr.common.params.MapSolrParams)23 ContentStreamBase (org.apache.solr.common.util.ContentStreamBase)23 Map (java.util.Map)22