Search code examples
c#solrsitecoresitecore7.2boosting

Sorting with Boosting item solr in sitecore v7


I'm using boosting item for solr seach in sitecore 7.2. I added value in Boost Value then rebuild index so how can i sorting for result item by boosting value? I tried st like that :

var dataQuerycontext.GetQueryable<SearchResultItem>()
....
dataQuery = dataQuery.OrderByDescending(i => i["score"]);
var results = dataQuery.GetResults().Hits.Select(h => h.Document);

But it's not working. Seem store always have value is 1


Solution

  • When using Sitecore with SOLR it appears that index time boosting does not work because Sitecore writes the queries using the standard query parameter. For the query to use the boost given to the item at index time it needs to use a DISMAX or EDISMAX query. Currently the Sitecore API is not setup to do that.

    So you would have to do your boosting at query time.

    Also, your order by on the score is not required, the results from .GetResults() should already be ordered by the score. If not, you should use the .Score value of the Hits list.

    var dataQuerycontext.GetQueryable<SearchResultItem>()
        .where(x => (x.MyField == "myvalue").Boost(2f)
        ... more query options ...
        )
    ....
    var results = dataQuery.GetResults().Hits
        .OrderByDescending(h => h.Score).Select(h => h.Document);
    

    That will then boost the field in the query.