Try our conversational search powered by Generative AI!

Class ContentSearchHandler

Manages the index of searchable content item information.

Inheritance
System.Object
ContentSearchHandler
Implements
EPiServer.Search.IReIndexable
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: EPiServer.Core
Assembly: EPiServer.dll
Version: 10.10.4
Syntax
public abstract class ContentSearchHandler : IReIndexable
Examples

Example of how you could search for pages.

    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&lt;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&apos;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&lt;PageData>(hit);
}

} }

Constructors

ContentSearchHandler()

Declaration
protected ContentSearchHandler()

Fields

InvariantCultureIndexedName

The identifier used to store invariant culture name.

Declaration
public const string InvariantCultureIndexedName = "iv"
Field Value
Type Description
System.String
Remarks

System.Globalization.CultureInfo.Name for System.Globalization.CultureInfo.InvariantCulture is String.Empty which is not possible to query for therfore content stored in System.Globalization.CultureInfo.InvariantCulture is indexed with "iv" as culture name.

Properties

NamedIndex

Gets the index of the named.

Declaration
public abstract string NamedIndex { get; }
Property Value
Type Description
System.String

NamedIndexingService

Gets the named indexing service.

Declaration
public abstract string NamedIndexingService { get; }
Property Value
Type Description
System.String

ServiceActive

Gets or sets a value indicating whether the search service is active.

Declaration
public abstract bool ServiceActive { get; set; }
Property Value
Type Description
System.Boolean

true if search service is active; otherwise, false.

Remarks

This value will be initialized from the configuration settings of EPiServer.Search.

Methods

GetContent<T>(IndexItemBase)

Converts the indexItem to the correct IContent instance.

Declaration
public virtual T GetContent<T>(IndexItemBase indexItem)
    where T : IContent
Parameters
Type Name Description
EPiServer.Search.IndexItemBase indexItem

The index item.

Returns
Type Description
T

null if indexItem is not valid; otherwise a PageData instance.

Type Parameters
Name Description
T
Remarks

The Id of indexItem must start with a guid that matches a page.

It will use the Culture of indexItem to specify of what culture the returned IContent should be.

GetContent<T>(IndexItemBase, Boolean)

Converts the indexItem to the correct IContent instance.

Declaration
public abstract T GetContent<T>(IndexItemBase indexItem, bool filterOnCulture)
    where T : IContent
Parameters
Type Name Description
EPiServer.Search.IndexItemBase indexItem

The index item.

System.Boolean filterOnCulture

if set to true filter on culture.

Returns
Type Description
T

null if indexItem is not valid; otherwise a PageData instance.

Type Parameters
Name Description
T
Remarks

The Id of indexItem must start with a guid that matches a page.

if filterOnCulture is false it will use the Culture of indexItem to specify of what culture the returned IContent should be. If filterOnCulture is false it will only get content in the current culture.

GetCultureIdentifier(CultureInfo)

Gets the culture identifier that is used when indexing a content item.

Declaration
public static string GetCultureIdentifier(CultureInfo culture)
Parameters
Type Name Description
System.Globalization.CultureInfo culture

The culture.

Returns
Type Description
System.String
Remarks

Normally System.Globalization.CultureInfo.Name is used. However for System.Globalization.CultureInfo.InvariantCulture is InvariantCultureIndexedName used.

GetItemType(Type)

Gets the item type representation for the provided content item type that is used in the search index.

Declaration
public abstract string GetItemType(Type contentType)
Parameters
Type Name Description
System.Type contentType

Type of the content.

Returns
Type Description
System.String

A string representing the full ItemType.

Remarks

This string will be made up by the base type of the provided type together with a generic name idicating that it is a content item.

GetItemType<T>()

Gets the item type representation for the provided content item type that is used in the search index.

Declaration
public virtual string GetItemType<T>()
Returns
Type Description
System.String

A string representing the full ItemType.

Type Parameters
Name Description
T

Type of the content

Remarks

This string will be made up by the base type of the provided type together with a generic name idicating that it is a content item.

GetItemTypeSection(Type)

Gets the section that the provided type appends to the ItemType field of the search index.

Declaration
public static string GetItemTypeSection(Type type)
Parameters
Type Name Description
System.Type type

The type of item in the index.

Returns
Type Description
System.String

A string that represents the type in the ItemType field.

GetItemTypeSection<T>()

Gets the section that the provided type appends to the ItemType field of the search index.

Declaration
public static string GetItemTypeSection<T>()
Returns
Type Description
System.String

A string that represents the type in the ItemType field.

Type Parameters
Name Description
T

The type of item in the index

GetSearchResults<T>(String, ContentReference, Int32, Int32, Boolean)

Gets the search result for the specified query.

Declaration
public abstract SearchResults GetSearchResults<T>(string searchQuery, ContentReference root, int page, int pageSize, bool filterOnAccess)
    where T : IContent
Parameters
Type Name Description
System.String searchQuery

The search query.

ContentReference root

The root for the search.

System.Int32 page

The page index of the result. Used to handle paging. Most be larger than 0.

System.Int32 pageSize

Number of items per page. Used to handle paging.

System.Boolean filterOnAccess

if set to true, items that the user doesn't have read access to will be removed.

Returns
Type Description
EPiServer.Search.SearchResults

The search result matching the search query.

Type Parameters
Name Description
T

The type of content that should be returned.

GetSearchResults<T>(String, Int32, Int32)

Gets the search result for the specified query.

Declaration
public virtual SearchResults GetSearchResults<T>(string searchQuery, int page, int pageSize)
    where T : IContent
Parameters
Type Name Description
System.String searchQuery

The search query.

System.Int32 page

The page index of the result. Used to handle paging. Most be larger than 0.

System.Int32 pageSize

Number of items per page. Used to handle paging.

Returns
Type Description
EPiServer.Search.SearchResults

The search result matching the search query.

Type Parameters
Name Description
T

The type of content that should be returned.

GetVirtualPathNodes(ContentReference)

Gets a collection of virtual path nodes for a content item to use in the search index.

Declaration
public abstract ICollection<string> GetVirtualPathNodes(ContentReference contentLink)
Parameters
Type Name Description
ContentReference contentLink

The content link.

Returns
Type Description
System.Collections.Generic.ICollection<System.String>

A collection of virtual path nodes.

IndexPublishedContent()

Adds all published content to the index by calling this.UpdateIndex for each item under RootPage

Declaration
public abstract void IndexPublishedContent()

MoveItem(ContentReference)

Updates the search index for the provided content item and it's descendants with a new virtual path location.

Declaration
public abstract void MoveItem(ContentReference contentLink)
Parameters
Type Name Description
ContentReference contentLink

The reference to the content item that is the root item that should get a new virtual path in the search index.

Remarks

The content of the provided item will also be included as a part of the update.

ReIndex()

Implementation of EPiServer.Search.IReIndexable, forwards to IndexPublishedContent

Declaration
public void ReIndex()

RemoveItemsByVirtualPath(ICollection<String>)

Removes all content items located at or under the provided virtual node from the search index. This will include all language versions as well.

Declaration
public abstract void RemoveItemsByVirtualPath(ICollection<string> virtualPathNodes)
Parameters
Type Name Description
System.Collections.Generic.ICollection<System.String> virtualPathNodes

The collection of virtual path nodes used to determine what items to remove.

RemoveLanguageBranch(IContent)

Removes a language branch of a content item from the search index.

Declaration
public abstract void RemoveLanguageBranch(IContent contentItem)
Parameters
Type Name Description
IContent contentItem

The content item that should be removed from the search index.

UpdateItem(IContent)

Updates the search index representation of the provided content item.

Declaration
public abstract void UpdateItem(IContent contentItem)
Parameters
Type Name Description
IContent contentItem

The content item that should be re-indexed.

Remarks

Note that only the exact language version that is provided is updated. If you want to update all language versions of a page, use alternative method overload.

Implements

EPiServer.Search.IReIndexable

Extension Methods