Kristaps J.
Kristaps J.

Reputation: 352

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",

Upvotes: 3

Views: 3536

Answers (4)

Shravan S
Shravan S

Reputation: 69

"sort": "popular ASC",
"bq": "(product_id: 123)^100",

Convert this to this:

"sort": "score desc, popular ASC",
"bq": "(product_id: 123)^100",

Upvotes: 2

Kalpesh Boghara
Kalpesh Boghara

Reputation: 461

By default, this component respects the requested sort parameter: if the request asks to sort by date, it will order the results by date. If forceElevation=true (the default), results will first return the boosted docs, then order by date.

Upvotes: 0

Eric
Eric

Reputation: 24890

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:


@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:

Upvotes: 4

Bruno dos Santos
Bruno dos Santos

Reputation: 1361

If you want to use edismax the right way you need to consider sorting by relevance score. The bf (boost function) just apply an addictive factor to the score but it doesn't make any change to the order because you are not sorting by the score. If you want the popular factor increase the document score you can use for example the boost parameter to do this. Follow an example you can use to get good results:

"sort": "score DESC",
"bq": "(product_id: 123)^100",
"boost": "popular"

Upvotes: 2

Related Questions