我正在为基于 Sitecore 的网站编写搜索站点。我已经能够走到这一步。
var query = SearchContext.GetQueryable<MySearchResultItem>().Where(i =>
i.ItemContent.Contains(this._View.SearchTerm)).ToArray();
MySearchResultsItem 定义如下。
public class MySearchResultItem
{
// Will match the _name field in the index
[IndexField("_name")]
public string Name
{
get;
set;
}
[IndexField(Sitecore.ContentSearch.BuiltinFields.Content)]
public string ItemContent
{
get;
set;
}
}
当我使用
进行搜索时[IndexField("_name")]
,我得到了正确的结果。但我想搜索项目的所有字段,我认为可以使用
[IndexField(Sitecore.ContentSearch.BuiltinFields.Content)]
。
我做错了什么?我应该使用哪个 IndexField 来查询所有内容?
谢谢
最佳答案
Sitecore.ContentSearch.BuiltinFields.Content
索引中的字段仅包含媒体库中二进制文件的内容。如果您查看它引用的配置 Sitecore.ContentSearch.ComputedFields.MediaItemContentExtractor
.
要搜索所有字段,您需要添加自定义 IComputedIndexField
到 <fields hint="raw:AddComputedIndexField">
它聚合了您要搜索的所有字段,或者仅包括您要在 linq 查询中搜索的所有字段。
关于c# - Sitecore 7 搜索所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17188360/