Search code examples
sortingsolrlucenesunspot

Unexpected Solr scores for documents boosted by the same boost values


I have 2 documents:

{
    title: "Popular",
    registrations_count: 700,
    is_featured: false
}

and

{
    title: "Unpopular",
    registrations_count: 100,
    is_featured: true
}

I'm running this Solr query (via the Ruby Sunspot gem):

fq: ["type:Event"],
sort: "score desc",
q: "*:*",
defType: "edismax",
fl: "* score",
bq: ["registrations_count_i:[700 TO *]^10", "is_featured_bs:true^10"],
start: 0, rows: 30

or, for those who are more used to ruby:

Challenge.search do    
    boost(10) do
       with(:registrations_count).greater_than_or_equal_to(700)
    end

    boost(10) do
        with(:is_featured, true)
    end

    order_by :score, :desc
end

One document matches the first boost query, and the other matches the other boost query. They have the same boost value.

What I would expect is that both documents get the same score. But they don't, they get something like that

1.2011336 # score for 'unpopular' (featured)
0.6366436 # score for 'popular' (not featured)

I also checked that if i boost an attribute that they both have in common, they get the exact same score, and they do. I also tried to change the 700 value, to something like 7000, but it makes no difference (which makes total sense).

Can anyone explain why they get such a different score, while they both match one of the boost queries?


Solution

  • I'm guessing the confusion stems from "the queries being boosted by the same value" - that's not true - the boost is the score of the query itself, which is then amplified 10x by your ^10.

    The bq is additive - the score from the query is added to the score of the document (while boost is multiplicative, the score is multiplied by the boost query).

    If you instead want to add the same score value to the original query based on either one matching, you can use ^=10 which makes the query constant scoring (the score will be 10 for that term, regardless of the regular score of the document).

    Also, if you want to apply these factors independent of each other (instead of as a single, merged score with contributions from both factors), use multiple bq entries instead.