Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solr sort after boost?

Is it possible to put boosted fields in front of other if its already sorted?

I have products that are sorted by popular ASC (its integer), but there are some specific products that I want to boost in front of other products, no matter what value is popular.

I am new with Solr, and I have got so far that I need to use edismax, right? But I dont exactly understand how it works, I always get popular products sorted first.

I have following query params:

"sort": "popular ASC",
"bq": "(product_id: 123)^100",
like image 701
Kristaps J. Avatar asked Dec 02 '25 13:12

Kristaps J.


1 Answers

This is called elevation in search. In solr, QueryElevationComponent might be what you need,

Brief usage step:

  • Config the component in solrconfig.xml.
  • Add a elevate.xml, and define the top rows, usually by specify the doc ids.
  • When query, use param enableElevation / forceElevation / .. to specify whether enable elevation. And yes, it works well with parser DisMax or eDisMax.

Refer:

  • https://cwiki.apache.org/confluence/display/solr/The+Query+Elevation+Component

  • http://wiki.apache.org/solr/QueryElevationComponent


@Update

I updated the above refer link with a better one, check that.

The doc id is the id field of the doc.

What's more important are:

  • The queryFieldType attribute of <searchComponent>, it specify the field type, thus decide the analyzer used, for English text, you might need text_en, don't use the default string, which won't analyze the query input.
  • Use request-handler /elevate instead of /select, when query.
  • Add the param enableElevation=true&forceElevation=true, so that to enable elevate sorts.
  • the additional field "[elevated]" indicate whether a record is elevated, it has boolean value, could add the field in 'fl' param, e.g fl=*,[elevated]

About params:

  • enableElevation, whether enable elevation, it don't override sort, means when sort param is specified, whether elevated docs are still on top depends on forceElevation param.
  • forceElevation, whether force elevation, it will override sort, means when sort param is specified, will still put elevated docs at top, then sort other docs.

Here is my example:

solrconfig.xml: (add before </config>)

  <!-- elevation -->
  <searchComponent name="elevator" class="org.apache.solr.handler.component.QueryElevationComponent" >
    <str name="queryFieldType">text_en</str>
    <str name="config-file">elevate.xml</str>
  </searchComponent>

  <requestHandler name="/elevate" class="solr.SearchHandler">
    <lst name="defaults">
      <str name="echoParams">explicit</str>
    </lst>
    <arr name="last-components">
      <str>elevator</str>
    </arr>
  </requestHandler>

elevate.xml: (e.g put it in solr-5.4.1/server/solr/dummy/conf/)

<?xml version="1.0" encoding="UTF-8" ?>
<elevate>

 <query text="Eric">
  <doc id="1" />
  <doc id="2" />
  <doc id="3" />
 </query>

</elevate>

This file is load once on startup, after change, need reload the core, e.g via solr admin.

query example:

  • http://localhost:8983/solr/dummy/elevate?q=eric&fl=*%2C%5Belevated%5D&wt=json&indent=true&defType=edismax&qf=name&stopwords=true&lowercaseOperators=true&enableElevation=true&forceElevation=true
like image 64
user218867 Avatar answered Dec 06 '25 07:12

user218867



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!