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

时间:2016-01-31 14:26:26

标签: sitecore sitecore8

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

2 个答案:

答案 0 :(得分:3)

索引提供商在索引方面非常简陋。 使用Sitecore.Data.Item进行常规查询时,您的结果会自动按上下文语言和最新项目版本进行过滤,在使用索引时不会发生此类过滤。 除非您在Linq查询中指定,否则您将收到所有版本和所有语言。

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

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

答案 1 :(得分:1)

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

var culture = Sitecore.Context.Language.CultureInfo;

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

this帖子

中有更多相关信息