我正在为基于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查询中。

09-25 16:47
查看更多