简体   繁体   English

如何在solrconfig.xml中设置SOLR参数替换

[英]How to set up SOLR parameter substitution in solrconfig.xml

This is my first question at stackoverflow so apologies in advance if I break any rules but I did study them and also made sure this isn't a duplicate question. 这是我在stackoverflow的第一个问题,所以如果我违反任何规则,请提前道歉,但我确实研究了它们,并确保这不是一个重复的问题。

So, according to this http://yonik.com/solr-query-parameter-substitution/ one can set up a search handler in solrconfig in a way that the 所以,根据这个http://yonik.com/solr-query-parameter-substitution/,可以在solrconfig中设置搜索处理程序,方式是

request handler defaults, appends, and invariants configured for the handler may reference request parameters 请求处理程序默认值,追加和为处理程序配置的不变量可以引用请求参数

I have the following query which works just 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 query to a search handler configuration in solrconfig.xml so a user only has to provide the PFIELD, PGAP, PSTART and PEND parameters. 我已将此查询转换为solrconfig.xml中的搜索处理程序配置,因此用户只需提供PFIELD,PGAP,PSTART和PEND参数。 Here's how the configuration for the handler looks 以下是处理程序的配置外观

     <!--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>

Notice that I provided default values for all the parameters otherwise SOLR will fail to load the configuration. 请注意,我为所有参数提供了默认值,否则SOLR将无法加载配置。 The problem is that using a query like this 问题是使用这样的查询

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

is not working. 不管用。 SOLR will read the request parameters fine (I can see them on the debug output) but will ignore them and use the default values in the configuration instead. SOLR将正确读取请求参数(我可以在调试输出上看到它们),但会忽略它们并使用配置中的默认值。

SOLR version is 5.2.1. SOLR版本是5.2.1。

I tried moving the configuration parameters to either defaults, appends or invariants but nothing is working. 我尝试将配置参数移动到默认值,追加或不变量,但没有任何工作。 After researching this for the past 2 days I'm almost ready to give up and just build the whole query on-the-fly instead. 经过2天的研究,我几乎已经准备好放弃,而是在运行中构建整个查询。

Any help will be greatly appreciated. 任何帮助将不胜感激。

Many thanks 非常感谢

I think (the post) is too old, but using a search engine I arrived at this page. 我认为(帖子)太旧了,但是使用搜索引擎我到了这个页面。 A simple solution was to escape the dollar symbol. 一个简单的解决方案是逃避美元符号。 After that, you should achieve your desired result. 之后,您应该达到理想的效果。

Example: <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> 示例: <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>

I'm not sure when the Config API came to Solr but if query parameter substitution does work when added to configoverlay.json 我不确定Config API什么时候来到Solr,但是当查询参数替换在添加到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 the /MyHandler query. 现在,您可以将URL参数&color = green&size = XXL传递给/ MyHandler查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM