获取SOLR搜索结果
我是使用 SOLR 作为搜索器的新手。我使用标准 SolrServlet 作为搜索器,例如
final SolrCore core = SolrCore.getSolrCore();
SolrServletRequest solrReq = new SolrServletRequest(core, request);
SolrQueryResponse solrRsp = new SolrQueryResponse();
try {
SolrRequestHandler handler = core.getRequestHandler(solrReq.getQueryType());
if (handler==null) {
log.warning("Unknown Request Handler '" + solrReq.getQueryType() +"' :" + solrReq);
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,"Unknown Request Handler '" + solrReq.getQueryType() + "'", true);
}
core.execute(handler, solrReq, solrRsp );
if (solrRsp.getException() == null) {
QueryResponseWriter responseWriter = core.getQueryResponseWriter(solrReq);
response.setContentType(responseWriter.getContentType(solrReq, solrRsp));
PrintWriter out = response.getWriter();
Set<String> fields = new HashSet<String>();
fields.add("content");
solrRsp.setReturnFields(fields);
responseWriter.write(out, solrReq, solrRsp);
我得到了正确的答案,但我要问的是如何在作者写入响应之前获取响应的内容?我知道返回的是 doc,并且我想要在生成响应页面之前获取文档中的“内容”字段。
多谢
i'm new in using SOLR as a searcher. I'm using the standard SolrServlet as a searcher, e.g.
final SolrCore core = SolrCore.getSolrCore();
SolrServletRequest solrReq = new SolrServletRequest(core, request);
SolrQueryResponse solrRsp = new SolrQueryResponse();
try {
SolrRequestHandler handler = core.getRequestHandler(solrReq.getQueryType());
if (handler==null) {
log.warning("Unknown Request Handler '" + solrReq.getQueryType() +"' :" + solrReq);
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,"Unknown Request Handler '" + solrReq.getQueryType() + "'", true);
}
core.execute(handler, solrReq, solrRsp );
if (solrRsp.getException() == null) {
QueryResponseWriter responseWriter = core.getQueryResponseWriter(solrReq);
response.setContentType(responseWriter.getContentType(solrReq, solrRsp));
PrintWriter out = response.getWriter();
Set<String> fields = new HashSet<String>();
fields.add("content");
solrRsp.setReturnFields(fields);
responseWriter.write(out, solrReq, solrRsp);
I'm getting the correct answers, but what I'm asking is how can I get the content of the response before it is written from the writer? I know that the return is doc, and I have a field "content" in the doc that I want to get, but before the response page is generated.
Thanks a lot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Java 中使用 Solr 的标准方法是通过 SolrJ。 SolrServletRequest、SolrRequestHandler 等是 Solr 的“内部”类,不适合消费者普遍使用。
您还可以将 Solr 嵌入到您的应用程序中,但通常不建议这样做。
The standard way of using Solr in Java is through SolrJ. SolrServletRequest, SolrRequestHandler, etc, are "internal" classes of Solr, not meant to be generally used by consumers.
You can also embed Solr in your application, although it's not generally recommended.