Lucene Search Content Field

Posted by Xing Liu on 6/8/2016

Sitecore provides content search API for developers to create their custom search interface in their Sitecore websites.  Here is an example of how the query is constructed.

var queryAll = context.GetQueryable<TRCSearchResult>().Where(x => (x.Topic.Contains(search) || x.Content.Contains(search)))

One thing to be aware of is that when querying specific field in the Content Search API, make sure your data template doesn’t have a field called “Content”.  Content is one of the default fields in the search result object SearchResultItem. If the query contains x.Content.Contains(search), it will search on all the fields.  In this case, you need to change the field Content in the data template to something else such as Body.

var queryAll = context.GetQueryable<TRCSearchResult>().Where(x => (x.Topic.Contains(search) || x.Body.Contains(search)))


Looking for a partner who will exceed your expectations? Get in touch.

SYMSOFT SOLUTIONS 4090 Truxel Road, Suite 200 Sacramento, CA 95834
United States (916) 567-1740