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 has 5 years of experience with developing web solutions using ASP.NET and SQL Server. For the past 3 years, he has been actively engaged in website development projects using Sitecore CMS. He enjoys creating web solutions for clients using Sitecore CMS and, using its flexibility, provides cohesive and integrated solutions. Xing is a Sitecore Technology MVP, 2016.

Explore topics:

Other Blog Posts from Xing Liu



Subscribe for insights, trends and big ideas