Search code examples
c#.netsitecoresitecore7

Sitecore 7 Search in all content


I am programming a search site for a Sitecore Based Website. I have been able to come to this point.

 var query = SearchContext.GetQueryable<MySearchResultItem>().Where(i =>        
                       i.ItemContent.Contains(this._View.SearchTerm)).ToArray();

MySearchResultsItem is defined as follows.

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;
    }

}

When I do a search with

[IndexField("_name")]

, I am getting the right results. But I would like to search in all fields of the items, and I think it is possible with
[IndexField(Sitecore.ContentSearch.BuiltinFields.Content)].

What am I doing wrong? Which IndexField should I use to query all the content?

Thanx


Solution

  • The Sitecore.ContentSearch.BuiltinFields.Content field in the index only contains content from binary files in the media library. If you look at the config it references Sitecore.ContentSearch.ComputedFields.MediaItemContentExtractor.

    To search across all fields you would need to add a custom IComputedIndexField to the <fields hint="raw:AddComputedIndexField"> which aggregated all the fields you want to search on, or just include all the fields you want to search on in your linq query.