Sitecore Solr 搜索结果项匹配计数
Sitecore Solr Search result items matching count
我正在使用 Sitecore Solr search 使用关键字字符串进行搜索,有没有办法知道每个返回结果项的匹配数?
以下是我使用的代码:
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;
}
据我所知,您无法根据用于搜索的关键字获得每个结果项的匹配数。您可以获得的是来自 Solr 的 score 值。
var hits = query.GetResults().Hits;
foreach (var hit in hits)
{
var score = hit.Score;
}
这是整个查询的值,因此它包括所有谓词,例如您的案例中的 language
、not Standard Values
和 keywords
。
请记住,如果您使用 Solr 和使用 Lucene,此值可能会有所不同 - 这取决于内部计算。
我通过为每个谓词添加提升值来解决这个问题,然后为每个结果项我得到分数并将其除以 .59,在我的例子中是当所有谓词都稳定时出现的最大值;详细代码可以参考以下博客post:
http://sitecoreinfo.blogspot.com/2015/10/sitecore-solr-search-result-items.html
我正在使用 Sitecore Solr search 使用关键字字符串进行搜索,有没有办法知道每个返回结果项的匹配数?
以下是我使用的代码:
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;
}
据我所知,您无法根据用于搜索的关键字获得每个结果项的匹配数。您可以获得的是来自 Solr 的 score 值。
var hits = query.GetResults().Hits;
foreach (var hit in hits)
{
var score = hit.Score;
}
这是整个查询的值,因此它包括所有谓词,例如您的案例中的 language
、not Standard Values
和 keywords
。
请记住,如果您使用 Solr 和使用 Lucene,此值可能会有所不同 - 这取决于内部计算。
我通过为每个谓词添加提升值来解决这个问题,然后为每个结果项我得到分数并将其除以 .59,在我的例子中是当所有谓词都稳定时出现的最大值;详细代码可以参考以下博客post:
http://sitecoreinfo.blogspot.com/2015/10/sitecore-solr-search-result-items.html