开发者

Get the result from SOLR searching

开发者 https://www.devze.com 2023-02-09 18:11 出处:网络
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();

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消