Search code examples
javasolrsolrjedismaxdismax

How to use solrj with the DismaxRequestHandler?


Due to lack of proper documentation , I am unable to figure out on how to use the dismaxRequestHandler with SolrJ.

On another note , is the standard request handler ,the default in SolrJ's implementation ?


Solution

  • The default="true" in solrconfig.xml decides which is the default request handler. In the examples with solr, the standard request handler is the default.

    <requestHandler name="search" class="solr.SearchHandler" default="true">
    .....
    </requestHandler>
    

    You can easily map this attribute to the other request handlers to make them default.

    Example with edismax -

    <requestHandler name="/browse" class="solr.SearchHandler" default="true">
     <lst name="defaults">
       <str name="echoParams">explicit</str>
       <str name="defType">edismax</str>
       <str name="q.alt">*:*</str>
       <str name="rows">10</str>
       <str name="fl">*,score</str>
       <str name="qf">
          text^0.5 features^1.0 name^1.2 sku^1.5 id^10.0 manu^1.1 cat^1.4
       </str>
     </lst>
    </requestHandler>
    

    The qt parameter can be used with Solrj to query through specific request handler.

    Example for Solrj -

    CommonsHttpSolrServer commonsHttpSolrServer = new CommonsHttpSolrServer("solr_path_url");
    commonsHttpSolrServer.setParser(new XMLResponseParser());
    ModifiableSolrParams params = new ModifiableSolrParams();
    // Specify the Request handler
    params.add("qt", "dismax_request_handler");
    params.add("q", "query_string");
    QueryResponse response = commonsHttpSolrServer.query(params);