Search in sources :

Example 21 with SolrRequestInfo

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

the class AbstractReRankQuery method getTopDocsCollector.

public TopDocsCollector getTopDocsCollector(int len, QueryCommand cmd, IndexSearcher searcher) throws IOException {
    if (this.boostedPriority == null) {
        SolrRequestInfo info = SolrRequestInfo.getRequestInfo();
        if (info != null) {
            Map context = info.getReq().getContext();
            this.boostedPriority = (Map<BytesRef, Integer>) context.get(QueryElevationComponent.BOOSTED_PRIORITY);
        }
    }
    return new ReRankCollector(reRankDocs, len, reRankQueryRescorer, cmd, searcher, boostedPriority);
}
Also used : SolrRequestInfo(org.apache.solr.request.SolrRequestInfo) Map(java.util.Map) BytesRef(org.apache.lucene.util.BytesRef)

Example 22 with SolrRequestInfo

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

the class AnalyticsQuery method getFilterCollector.

public DelegatingCollector getFilterCollector(IndexSearcher searcher) {
    SolrRequestInfo info = SolrRequestInfo.getRequestInfo();
    ResponseBuilder rb = null;
    if (info != null) {
        rb = info.getResponseBuilder();
    }
    if (rb == null) {
        //This is the autowarming case.
        return new DelegatingCollector();
    } else {
        return getAnalyticsCollector(rb, searcher);
    }
}
Also used : SolrRequestInfo(org.apache.solr.request.SolrRequestInfo) ResponseBuilder(org.apache.solr.handler.component.ResponseBuilder)

Example 23 with SolrRequestInfo

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

the class SolrLogLayout method _format.

public String _format(LoggingEvent event) {
    String message = (String) event.getMessage();
    if (message == null) {
        message = "";
    }
    StringBuilder sb = new StringBuilder(message.length() + 80);
    long now = event.timeStamp;
    long timeFromStart = now - startTime;
    long timeSinceLast = now - lastTime;
    lastTime = now;
    String shortClassName = getShortClassName(event.getLocationInformation().getClassName(), event.getLocationInformation().getMethodName());
    /***
     * sb.append(timeFromStart).append(' ').append(timeSinceLast);
     * sb.append(' ');
     * sb.append(record.getSourceClassName()).append('.').append(
     * record.getSourceMethodName()); sb.append(' ');
     * sb.append(record.getLevel());
     ***/
    SolrRequestInfo requestInfo = SolrRequestInfo.getRequestInfo();
    SolrQueryRequest req = requestInfo == null ? null : requestInfo.getReq();
    SolrCore core = req == null ? null : req.getCore();
    ZkController zkController = null;
    CoreInfo info = null;
    if (core != null) {
        info = coreInfoMap.get(core.hashCode());
        if (info == null) {
            info = new CoreInfo();
            info.shortId = "C" + Integer.toString(CoreInfo.maxCoreNum++);
            coreInfoMap.put(core.hashCode(), info);
            if (sb.length() == 0)
                sb.append("ASYNC ");
            sb.append(" NEW_CORE " + info.shortId);
            sb.append(" name=" + core.getName());
            sb.append(" " + core);
        }
        zkController = core.getCoreContainer().getZkController();
        if (zkController != null) {
            if (info.url == null) {
                info.url = zkController.getBaseUrl() + "/" + core.getName();
                sb.append(" url=" + info.url + " node=" + zkController.getNodeName());
            }
            Map<String, Object> coreProps = getReplicaProps(zkController, core);
            if (info.coreProps == null || !coreProps.equals(info.coreProps)) {
                info.coreProps = coreProps;
                final String corePropsString = "coll:" + core.getCoreDescriptor().getCloudDescriptor().getCollectionName() + " core:" + core.getName() + " props:" + coreProps;
                sb.append(" " + info.shortId + "_STATE=" + corePropsString);
            }
        }
    }
    if (sb.length() > 0)
        sb.append('\n');
    sb.append(timeFromStart);
    // sb.append("\nL").append(record.getSequenceNumber()); // log number is
    // useful for sequencing when looking at multiple parts of a log file, but
    // ms since start should be fine.
    appendThread(sb, event);
    appendMDC(sb);
    if (info != null) {
        // core
        sb.append(' ').append(info.shortId);
    }
    if (shortClassName.length() > 0) {
        sb.append(' ').append(shortClassName);
    }
    if (event.getLevel() != Level.INFO) {
        sb.append(' ').append(event.getLevel());
    }
    sb.append(' ');
    appendMultiLineString(sb, message);
    ThrowableInformation thInfo = event.getThrowableInformation();
    if (thInfo != null) {
        Throwable th = event.getThrowableInformation().getThrowable();
        if (th != null) {
            sb.append(' ');
            String err = SolrException.toStr(th);
            String ignoredMsg = SolrException.doIgnore(th, err);
            if (ignoredMsg != null) {
                sb.append(ignoredMsg);
            } else {
                sb.append(err);
            }
        }
    }
    sb.append('\n');
    return sb.toString();
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrCore(org.apache.solr.core.SolrCore) ZkController(org.apache.solr.cloud.ZkController) ThrowableInformation(org.apache.log4j.spi.ThrowableInformation) SolrRequestInfo(org.apache.solr.request.SolrRequestInfo)

Example 24 with SolrRequestInfo

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

the class SolrIndexSearcher method warm.

/**
   * Warm this searcher based on an old one (primarily for auto-cache warming).
   */
public void warm(SolrIndexSearcher old) {
    // Make sure this is first! filters can help queryResults execute!
    long warmingStartTime = System.nanoTime();
    // warm the caches in order...
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.add("warming", "true");
    for (int i = 0; i < cacheList.length; i++) {
        if (log.isDebugEnabled()) {
            log.debug("autowarming [{}] from [{}]\n\t{}", this, old, old.cacheList[i]);
        }
        final SolrQueryRequest req = new LocalSolrQueryRequest(core, params) {

            @Override
            public SolrIndexSearcher getSearcher() {
                return SolrIndexSearcher.this;
            }

            @Override
            public void close() {
            }
        };
        final SolrQueryResponse rsp = new SolrQueryResponse();
        SolrRequestInfo.clearRequestInfo();
        SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
        try {
            cacheList[i].warm(this, old.cacheList[i]);
        } finally {
            try {
                req.close();
            } finally {
                SolrRequestInfo.clearRequestInfo();
            }
        }
        if (log.isDebugEnabled()) {
            log.debug("autowarming result for [{}]\n\t{}", this, cacheList[i]);
        }
    }
    warmupTime = TimeUnit.MILLISECONDS.convert(System.nanoTime() - warmingStartTime, TimeUnit.NANOSECONDS);
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrRequestInfo(org.apache.solr.request.SolrRequestInfo) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) IndexFingerprint(org.apache.solr.update.IndexFingerprint)

Example 25 with SolrRequestInfo

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

the class EmbeddedSolrServer method request.

// TODO-- this implementation sends the response to XML and then parses it.
// It *should* be able to convert the response directly into a named list.
@Override
public NamedList<Object> request(SolrRequest request, String coreName) throws SolrServerException, IOException {
    String path = request.getPath();
    if (path == null || !path.startsWith("/")) {
        path = "/select";
    }
    SolrRequestHandler handler = coreContainer.getRequestHandler(path);
    if (handler != null) {
        try {
            SolrQueryRequest req = _parser.buildRequestFrom(null, request.getParams(), request.getContentStreams());
            SolrQueryResponse resp = new SolrQueryResponse();
            handler.handleRequest(req, resp);
            checkForExceptions(resp);
            return BinaryResponseWriter.getParsedResponse(req, resp);
        } catch (IOException | SolrException iox) {
            throw iox;
        } catch (Exception ex) {
            throw new SolrServerException(ex);
        }
    }
    if (coreName == null)
        coreName = this.coreName;
    // Check for cores action
    SolrQueryRequest req = null;
    try (SolrCore core = coreContainer.getCore(coreName)) {
        if (core == null) {
            throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "No such core: " + coreName);
        }
        SolrParams params = request.getParams();
        if (params == null) {
            params = new ModifiableSolrParams();
        }
        // Extract the handler from the path or params
        handler = core.getRequestHandler(path);
        if (handler == null) {
            if ("/select".equals(path) || "/select/".equalsIgnoreCase(path)) {
                String qt = params.get(CommonParams.QT);
                handler = core.getRequestHandler(qt);
                if (handler == null) {
                    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "unknown handler: " + qt);
                }
            }
        }
        if (handler == null) {
            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "unknown handler: " + path);
        }
        req = _parser.buildRequestFrom(core, params, request.getContentStreams());
        req.getContext().put(PATH, path);
        req.getContext().put("httpMethod", request.getMethod().name());
        SolrQueryResponse rsp = new SolrQueryResponse();
        SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
        core.execute(handler, req, rsp);
        checkForExceptions(rsp);
        // Check if this should stream results
        if (request.getStreamingResponseCallback() != null) {
            try {
                final StreamingResponseCallback callback = request.getStreamingResponseCallback();
                BinaryResponseWriter.Resolver resolver = new BinaryResponseWriter.Resolver(req, rsp.getReturnFields()) {

                    @Override
                    public void writeResults(ResultContext ctx, JavaBinCodec codec) throws IOException {
                        // write an empty list...
                        SolrDocumentList docs = new SolrDocumentList();
                        docs.setNumFound(ctx.getDocList().matches());
                        docs.setStart(ctx.getDocList().offset());
                        docs.setMaxScore(ctx.getDocList().maxScore());
                        codec.writeSolrDocumentList(docs);
                        // This will transform
                        writeResultsBody(ctx, codec);
                    }
                };
                try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
                    createJavaBinCodec(callback, resolver).setWritableDocFields(resolver).marshal(rsp.getValues(), out);
                    try (InputStream in = out.toInputStream()) {
                        return (NamedList<Object>) new JavaBinCodec(resolver).unmarshal(in);
                    }
                }
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        }
        // Now write it out
        NamedList<Object> normalized = BinaryResponseWriter.getParsedResponse(req, rsp);
        return normalized;
    } catch (IOException | SolrException iox) {
        throw iox;
    } catch (Exception ex) {
        throw new SolrServerException(ex);
    } finally {
        if (req != null)
            req.close();
        SolrRequestInfo.clearRequestInfo();
    }
}
Also used : ResultContext(org.apache.solr.response.ResultContext) SolrCore(org.apache.solr.core.SolrCore) BinaryResponseWriter(org.apache.solr.response.BinaryResponseWriter) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) StreamingResponseCallback(org.apache.solr.client.solrj.StreamingResponseCallback) SolrRequestInfo(org.apache.solr.request.SolrRequestInfo) SolrException(org.apache.solr.common.SolrException) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) InputStream(java.io.InputStream) NamedList(org.apache.solr.common.util.NamedList) IOException(java.io.IOException) SolrDocumentList(org.apache.solr.common.SolrDocumentList) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrException(org.apache.solr.common.SolrException) IOException(java.io.IOException) JavaBinCodec(org.apache.solr.common.util.JavaBinCodec) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrRequestHandler(org.apache.solr.request.SolrRequestHandler)

Aggregations

SolrRequestInfo (org.apache.solr.request.SolrRequestInfo)29 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)22 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)16 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)9 SolrCore (org.apache.solr.core.SolrCore)9 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)8 Map (java.util.Map)5 QueryResponseWriter (org.apache.solr.response.QueryResponseWriter)5 Query (org.apache.lucene.search.Query)4 SolrException (org.apache.solr.common.SolrException)4 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)4 IOException (java.io.IOException)3 StringWriter (java.io.StringWriter)3 HashMap (java.util.HashMap)3 JavaBinCodec (org.apache.solr.common.util.JavaBinCodec)3 NamedList (org.apache.solr.common.util.NamedList)3 BinaryResponseWriter (org.apache.solr.response.BinaryResponseWriter)3 ResultContext (org.apache.solr.response.ResultContext)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2