Lucene Search Content Field

Xing Liu • 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)))

Xing Liu

Xing Liu is a Sitecore MVP with expertise in all aspects of ASP.NET and SQL Server development across a variety of industries including Government, Banking, Healthcare and Energy. He provides technical thought leadership and consulting to SymSoft and client development teams. Xing has deep expertise in using Sitecore Helix in an Agile delivery model to streamline the construction of complex Sitecore websites, portals and their associated authoring environments. Xing is also a globally recognized photographer with an Instagram following approaching 100,000.

Explore topics:

Other Blog Posts from Xing Liu