Sitecore 内容搜索:我必须指定语言吗?

Sitecore Content Search: do I have to specify the language?

我正在使用 IProviderSearchContext 在 Sitecore 8.1(Lucene 搜索)中搜索特定项目,我得到每个项目的两个版本 (en, ar)。 我的问题是:我是否必须为每个查询指定:item.Language == Sitecore.Context.Language.Name,或者是否有办法使 IProviderSearchContext 根据当前 Sitecore 上下文中的语言获取数据?

索引提供者对索引的了解非常初级。 使用 Sitecore.Data.Item 进行正常查询时,您的结果会根据上下文语言和最新项目版本自动过滤,使用索引时不会发生此类过滤。 除非您在 Linq 查询中指定,否则您将收到所有版本和所有语言。

With indexing 必须使用:item.Language == Sitecore.Context.Language.Name 如果你想过滤当前语言的结果。 要使用上述过滤,您还需要从 SearchResultItem 继承您的 ResultItem class。否则,您的 ResultItem 需要向您的 class 添加一个新的索引字段,如上所示:

  [IndexField(“_language”)]
  public string Language { get; set; }

您还可以将 CultureExecutionContext 传递给您的查询,这将按语言限制结果。

var culture = Sitecore.Context.Language.CultureInfo;

var queryable = context.GetQueryable<SearchResultItem>(new CultureExecutionContext(culture));

thispost

中有更多相关信息