获取SOLR搜索结果

发布于 2024-10-16 02:52:03 字数 1137 浏览 1 评论 0原文

我是使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深居我梦 2024-10-23 02:52:03

在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文