I am trying to get the score value for each returned result item but the problem is all items returned the same score value. I am using sitecore 7.2 site which was upgraded from sitecore 6.6. I am using solr version 4.10.2-0
The following is the code that I am using:
var contentPredicate = PredicateBuilder.True<customSearchResultItem>();
contentPredicate = contentPredicate.And(p => p.Content.Matches(SearchKey.Boost(1.0f)));
IQueryable<SearchResultItem> query = context.GetQueryable<customSearchResultItem>().Where(contentPredicate);
var hits = query.GetResults().Hits;
foreach (var item in hits)
{
scores.Add(item.Score);
}
Would you please advise if something is missing? or if there are any configuration that should be applied to make this work?
There is a post relating to this on the Sitecore Knowledge Base stating that Score of the hit is being multiplied by 0, therefore all results have the same score.
The post is relating the Lucene but I believe it is relevant to Solr as well.
To resolve
- In Sitecore navigate to the
/sitecore/templates/System/Templates/Sections/Indexing
section. - Create a Standard Values item for this section.
- Enter the value 1 in the
Boost Value
field of the above-mentioned Standard Values item. - Save, publish and re-index
As your instance of is an upgraded version 6.6, before ContentSearch existed, the Standard Value didn't exist nor created in upgrade scripts.
The following should be exist to apply boosting feature and sorting items accordingly:
- The search should be with more than one clause, else the items retrived will have the same score value
- When search contains more than clause ( predicate ) they will have the same weight on the score value unless applying the boost method ".Boost(10.0f).
- The combination between clauses should be "OR", Else the returned items must match all predicates to be retrieved which means same score value.
来源:https://stackoverflow.com/questions/31385013/sitecore-solr-search-score-value