ContentSearchHandler Class

Assembly: EPiServer (in EPiServer.dll) Version: 10.10.4.0 (10.10.4.0)

Syntax:

C#
public abstract class ContentSearchHandler : IReIndexable

Manages the index of searchable content item information.

Methods

Name
ContentSearchHandler Constructor
GetContent(T)(IndexItemBase)
GetContent(T)(IndexItemBase, Boolean)
GetCultureIdentifier
GetItemType(T)
GetItemType(Type)
GetItemTypeSection(T)
GetItemTypeSection(Type)
GetSearchResults(T)(String, ContentReference, Int32, Int32, Boolean)
GetSearchResults(T)(String, Int32, Int32)
GetVirtualPathNodes
IndexPublishedContent
MoveItem
ReIndex
RemoveItemsByVirtualPath
RemoveLanguageBranch
UpdateItem

Properties

Name
NamedIndex
NamedIndexingService
ServiceActive

Examples

Example of how you could search for pages.

CopyC#
public class PageSearchSample : TemplatePage
{
    public IEnumerable<PageData> FindPages(string searchQuery, ContentReference searchRoot, string cultureId, int pagingNumber, int pagingSize)
    {
        // The group query is needed to combine the different criteria
        GroupQuery groupQuery = new GroupQuery(LuceneOperator.AND);

        // The content query makes sure we only get hits that are of the type PageData
        groupQuery.QueryExpressions.Add(new ContentQuery<PageData>());

        // The field query contains the search phrase
        groupQuery.QueryExpressions.Add(new FieldQuery(searchQuery));

        // The virtual path query makes sure that we only get hits for children of the specified search root
        VirtualPathQuery pathQuery = new VirtualPathQuery();
        pathQuery.AddContentNodes(searchRoot);
        groupQuery.QueryExpressions.Add(pathQuery);

        // The access control list query will remove any pages the user doesn't have read access to
        AccessControlListQuery aclQuery = new AccessControlListQuery();
        aclQuery.AddAclForUser(PrincipalInfo.Current, HttpContext.Current);
        groupQuery.QueryExpressions.Add(aclQuery);

        // Add a specific field query for the Culture field in order to search for a specific culture
        groupQuery.QueryExpressions.Add(new FieldQuery(cultureId, Field.Culture));

        SearchResults results = Locate.SearchHandler().GetSearchResults(groupQuery, pagingNumber, pagingSize);

        ContentSearchHandler contentSearchHandler = Locate.ContentSearchHandler();
        foreach (var hit in results.IndexResponseItems)
        {
            // Use the content search handler to convert the page hit into a PageData
            yield return contentSearchHandler.GetContent<PageData>(hit);
        }
    }
}

Inheritance