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:
- Write a class that extends from
SearchHandler
and handles the custom logic. - 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>