2015-09-17 39 views
0

我正在使用Sitecore Solr搜索使用关键字字符串进行搜索,有没有办法知道每个返回结果项目的匹配数量?Sitecore Solr搜索结果项匹配计数

以下是我使用的代码:

using (var context = Index.CreateSearchContext()) 
{ 
    List<Item> ResultList = new List<Item>(); 

    var contentPredicate = PredicateBuilder.True<customSearchResultItem>(); 
    contentPredicate = contentPredicate.And(p => p.Content.Contains(SearchKey)); 
    contentPredicate = contentPredicate.And(p => p.Name != "__Standard Values"); 

    var languagePredicate = PredicateBuilder.True<customSearchResultItem>(); 
    languagePredicate = languagePredicate.And(p => p.Language == Context.Language.Name); 

    var CombinPredicates = PredicateBuilder.True<customSearchResultItem>(); 
    CombinPredicates = CombinPredicates.And(languagePredicate); 
    CombinPredicates = CombinPredicates.And(contentPredicate); 

    // execute the search 
    IQueryable<customSearchResultItem> query = context.GetQueryable<customSearchResultItem>().Where(CombinPredicates); 
    var hits = query.GetResults().Hits; 
} 

回答

1

据我所知,您可以根据使用的搜索关键字不会得到匹配的数目为每个结果项目。你可以得到的是来自Solr的得分

var hits = query.GetResults().Hits; 
foreach (var hit in hits) 
{ 
    var score = hit.Score; 
} 

这是整个查询的价值,所以包括像language,你的情况not Standard Valueskeywords所有谓词。

请记住,如果您使用Solr并且您使用Lucene,则此值可能会有所不同,这取决于内部计算。

+0

我以前尝试这样做,得分值将是所有的结果项相同的,如果关键字谓词匹配,我需要像递增在当前项目上找到的每个比赛的得分值? –