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);
}
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);
}
}
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();
}
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);
}
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();
}
}
Aggregations