【问题标题】:How can i make Sitecore Content Search boost work within an Expression Tree如何使 Sitecore 内容搜索提升在表达式树中工作
【发布时间】:2015-07-25 08:50:43
【问题描述】:

我正在尝试创建一个 Sitecore 搜索实现,它允许内容编辑器定义要搜索的项目属性并针对这些字段单独设置提升值。

为了做到这一点,我使用表达式树构建了一个谓词,如下所示:

foreach (KeyValuePair<string, float> searchResultProperty in searchResultProperties)
{
    Expression constant = Expression.Constant(term);
    ParameterExpression parameter = Expression.Parameter(typeof(FAQSearchResultItem), "s");
    Expression property = Expression.Property(parameter, typeof(FAQSearchResultItem).GetProperty(searchResultProperty.Key));
    Expression expression = Expression.Equal(property, constant);
    predicate = predicate.Or(Expression.Lambda<Func<FAQSearchResultItem, bool>>(expression, parameter)).Boost(searchResultProperty.Value);
}

return predicate;

然后我打算在执行搜索时使用它,以便按传入的任何字段进行过滤:

var query = _context
    .GetQueryable<CustomSearchResultItem>()
    .Where(predicate);

我遇到的问题是对使用表达式树构建的谓词应用提升不起作用。

如果我这样做:

var query = _context
                .GetQueryable<FAQSearchResultItem>();

query = query
   .Where(s => (s.Question == term).Boost(1.1f)
    || (s.WebsiteAnswer == term).Boost(1.5f));

然后查询使用的表达式计算为:

{s => ((s.Question == "water").Boost(1.1) OrElse (s.WebsiteAnswer == "water").Boost(1.5))}

但是我想使用的方法评估为:

{param => ((True AndAlso (False OrElse (param.Question == "water"))) AndAlso (param.Language == Context.Language.Name))}

没有应用提升。

如何将提升添加到使用表达式树生成的谓词中?

【问题讨论】:

    标签: c# linq sitecore lucene.net solr-boost


    【解决方案1】:

    最后,我不得不求助于似乎对提升具有内置支持的谓词构建器。遗憾的是,我无法使用反射来获取 SearchResultObject 的属性,但我可以实现我打算做的事情......只需更多代码

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-23
      • 1970-01-01
      • 2017-12-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多