voila
voila

Reputation: 1666

Solr : Write custom request Handler

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.

Upvotes: 1

Views: 1929

Answers (2)

cjungel
cjungel

Reputation: 3791

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>

Upvotes: 2

Paige Cook
Paige Cook

Reputation: 22555

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.

Upvotes: 1

Related Questions