How can I boost a result in SOLR based on a parame

2019-09-07 18:38发布

问题:

I am new to SOLR and I am trying to boost a result based on a parameter "country".

For example, I want to set the country to US and move all the results with US to the top.

This is how I am doing it right now but it doesn't work. :

sort=query({!qf=market v='US'}) desc

This is how the dismax request handler is set up:

 <requestHandler name="dismax" class="solr.SearchHandler" >
    <lst name="defaults">
     <str name="defType">dismax</str>
     <str name="echoParams">explicit</str>
     <float name="tie">0.01</float>
     <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>
     <str name="pf">
        text^0.2 features^1.1 name^1.5 manu^1.4 manu_exact^1.9
     </str>
     <str name="bf">
        popularity^0.5 recip(price,1,1000,1000)^0.3
     </str>
     <str name="fl">
        id,name,price,score
     </str>
     <str name="mm">
        2&lt;-1 5&lt;-2 6&lt;90%
     </str>
     <int name="ps">100</int>
     <str name="q.alt">*:*</str>
     <!-- example highlighter config, enable per-query with hl=true -->
     <str name="hl.fl">text features name</str>
     <!-- for this field, we want no fragmenting, just highlighting -->
     <str name="f.name.hl.fragsize">0</str>
     <!-- instructs Solr to return the field itself if no query terms are
          found -->
     <str name="f.name.hl.alternateField">name</str>
     <str name="f.text.hl.fragmenter">regex</str> <!-- defined below -->
    </lst>
  </requestHandler>

回答1:

If you are using dismax/edismax query parser you can follow the way suggested by Karthik.

But, even if you use the standard query parser, you can query q=market:US^2. This should give you results having more priority where market:US.

Note: "market" is a field and "US" is it's value.