Solr : Write custom request Handler

被刻印的时光 ゝ 提交于 2020-01-07 07:09:58

问题


Well , I want to write custom request handler. So I thought of reviewing code of 'standard request handler' come with solr. Where can I find source code of handler. i didn't find it in my solr directory.


回答1:


You can view the source code of the StandardRequestHandler from this link. The entire tree of the source code can be accessed in readonly view via http://svn.apache.org/viewvc/lucene/dev/

I would encourage you to check out the RequestHandler documentation on the Solr Wiki as well for reference and guidance.




回答2:


In order to create and use a custom request handler in solr you need to:

  1. Write a class that extends from SearchHandler and handles the custom logic.
  2. Update solrconfig.xml to add en endpoint that uses the custom request handler.

Custom Solr Request Handler Class

public class MyCustomRequestHandler extends SearchHandler {

  @Override
  public void handleRequestBody(SolrQueryRequest solrRequest,
    SolrQueryResponse solrResponse) throws Exception {

    /// modify solr request object

    // let solr handle the modified request
    super.handleRequestBody(solrRequest, solrResponse); 

    // optionally modify solr response object
  }
}

Solr configuration

<requestHandler name="/custom_endpoint"
  class="org.example.MyCustomRequestHandler" default="true">
  <lst name="defaults">
    <str name="echoParams">explicit</str>
    <str name="wt">json</str>
    <str name="defType">edismax</str>

    ... rest of configuration

  </lst>
</requestHandler>


来源:https://stackoverflow.com/questions/16238731/solr-write-custom-request-handler

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!