3

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",
Kristaps J.
  • 325
  • 3
  • 10

4 Answers4

4

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:

Eric
  • 22,183
  • 20
  • 145
  • 196
  • I don't really understand how this work. I am stuck in doc id part, where can I see doc id? . It's unique every time when I execute query? – Kristaps J. Mar 21 '16 at 09:11
  • Ok. Now it returns only elevated docs I specified, not sure how to mix with other docs. But actually now I am not sure if this is what I am looking for, because these specific docs must be dynamical - in my system they can be added, removed and their order can be changed. Plus after these docs must follow remaining docs based on **popular ASC**. I could make script that generate elevate.xml docs inside, but still then I need to reload core every time I change these docs.. – Kristaps J. Mar 21 '16 at 11:58
  • @KristapsJaremčuks 1) They do include the match docs for sure, don't know why you didn't see that. 2) To make the ids dynamic, you can edit the elevate.xml file by program, automatically, then call a reload by program automatically, this need some utility class. 3) Another solution is to add a priority field to your data, and boost the field greatly, so that they always appear in front when match they query, in this case only matched rows will show, but with elevate non-mache rows could also be configured to show. – Eric Mar 21 '16 at 14:03
  • @KristapsJaremčuks If u have read the doc carefully, put elevate.xml in / then the file will be load for each request, not just on startup, thus reload by hand is not necessary. There is a trade off, depends on the traffic of your sites. – Eric Mar 21 '16 at 14:03
  • @EricWang We are able to get this done with your help. Thanks. However, we are unable to get elevated results on top when we apply sort by popularity field. We need to put elevated results on top of sorted by that field. Kindly advise how we can do that? – Krunal Jul 02 '16 at 05:03
  • @Krunal Not sure what you mean by `apply sort by popularity field`. – Eric Jul 02 '16 at 06:50
  • @EricWang Sorry. I should be more clear. I mean to apply elevation along with sorting. Pls check , I posted a separate question as well here: http://stackoverflow.com/questions/38156686/getting-solr-elevated-results-on-top-of-sorted-by-field-results – Krunal Jul 02 '16 at 13:11
  • 1
    @Krunal Don't forget the `enableElevation=true&forceElevation=true` parameters, try add that when query. – Eric Jul 02 '16 at 15:23
2

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"
Bruno dos Santos
  • 1,361
  • 1
  • 12
  • 21
2
"sort": "popular ASC",
"bq": "(product_id: 123)^100",

Convert this to this:

"sort": "score desc, popular ASC",
"bq": "(product_id: 123)^100",
Shravan S
  • 69
  • 6
0

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.

Kalpesh Boghara
  • 418
  • 3
  • 22