How to configure SOLR parameter override in solrconfig.xml file

This is my first question on stackoverflow, so apologize in advance if I am breaking any rules, but I did research and also made sure this is not a duplicate question.

So, according to this http://yonik.com/solr-query-parameter-substitution/ it is possible to configure the search handler in solrconfig such that

request default handlers, append and invariants configured for the handler can refer to request parameters

I have the following request which works fine with curl

curl http://localhost:7997/solr/vb_popbio/select -d 'q=*:*&fq=bundle:pop_sample_phenotype AND phenotype_type_s:"insecticide%20resistance"
&rows=0&wt=json&json.nl=map&indent=true
&fq=phenotype_value_type_s:${PFIELD}&
&PGAP=5&PSTART=0&PEND=101&PFIELD="mortality rate"&
json.facet = {
            pmean: "avg(phenotype_value_f)",
            pperc: "percentile(phenotype_value_f,5,25,50,75,95)",
            pmin: "min(phenotype_value_f)",
            pmax: "max(phenotype_value_f)",
            denplot : {
                type : range,
                field : phenotype_value_f,
                gap : ${PGAP:0.1},
                start: ${PSTART:0},
                end: ${PEND:1}
            }
    }'

      

I have translated this request into search handler config in solrconfig.xml file, so user must provide PFIELD, PGAP, PSTART and PEND parameters. Here's what the config looks like for the handler

     <!--A request handler to serve data for violin plots (limited to IR assays)-->
<requestHandler name="/irViolin" class="solr.SearchHandler">
    <!-- default values for query parameters can be specified, these
         will be overridden by parameters in the request
      -->
    <lst name="defaults">
        <str name="echoParams">explicit</str>
        <int name="rows">0</int>
        <str name="df">text</str>
        <str name="wt">json</str>
        <str name="json.nl">map</str>
        <str name="json.facet">{
            pmean: "avg(phenotype_value_f)",
            pperc: "percentile(phenotype_value_f,5,25,50,75,95)",
            pmin: "min(phenotype_value_f)",
            pmax: "max(phenotype_value_f)",
            denplot : {
            type : range,
            field : phenotype_value_f,
            gap: ${PGAP:0.1},
            start: ${PSTART:0},
            end: ${PEND:1}
            }
            }
        </str>
    </lst>
    <lst name="appends">
        <str name="fq">bundle:pop_sample_phenotype</str>
        <str name="fq">phenotype_type_s:"insecticide resistance"</str>
        <str name="fq">has_geodata:true</str>
        <str name="fq">phenotype_value_type_s:${PFIELD:"mortality rate"}</str>

    </lst>
    <lst name="invariants">
    </lst>

</requestHandler>

      

Please note that I have provided default values ​​for all parameters, otherwise SOLR will not be able to load the config. The problem is that with a request like this

curl http://localhost:7997/solr/vb_popbio/irViolin?q=*:*&
    &PGAP=5&PSTART=0&PEND=101&PFIELD="mortality rate"

      

does not work. SOLR will read the query parameters ok (I can see them in the debug output), but will ignore them and use the defaults in the config.

SOLR version - 5.2.1.

I tried to move the config options to defaults, add or invariants, but nothing works. After researching this for the past two days, I'm almost ready to give up and just build the whole query on the fly.

Any help would be greatly appreciated.

Many thanks

+3


source to share


1 answer


I'm not sure when the Config API came to be in Solr, but if query parameter substitution works when added to configoverlay.json

{
  "requestHandler": {
     "/myHandler": {
       "name": "/myHandler",
        "class": "solr.SearchHandler",
        "defaults": {
           "fl": "id,name,color,size",
        },
       "invariants": {
          "rows": 10,
       },
       "appends": {
          "json": "{filter:[\"color:${color:red}\",\"size:${size:M}\"]}"
       }
    }
  }
}

      



Now you can pass URL parameters & color = green & size = XXL to / MyHandler request.

0


source







All Articles