Class ContentSearchHandler
Manages the index of searchable content item information.
Inheritance
Implements
Inherited Members
Namespace: EPiServer.Core
Assembly: EPiServer.dll
Version: 8.11.0Syntax
[ServiceConfiguration(ServiceType = typeof(IReIndexable), FactoryMember = "CreateInstance")]
[ServiceConfiguration(ServiceType = typeof(ContentSearchHandler), FactoryMember = "CreateInstance")]
public class ContentSearchHandler : IReIndexable
Examples
Example of how you could search for pages.
Constructors
ContentSearchHandler(SearchHandler, IContentRepository, IContentTypeRepository, SearchIndexConfig)
Initializes a new instance of the ContentSearchHandler class.
Declaration
public ContentSearchHandler(SearchHandler searchHandler, IContentRepository contentRepository, IContentTypeRepository contentTypeRepository, SearchIndexConfig searchIndexConfig)
Parameters
Type | Name | Description |
---|---|---|
EPiServer.Search.SearchHandler | searchHandler | The search handler. |
IContentRepository | contentRepository | The content repository. |
IContentTypeRepository | contentTypeRepository | The content type repository. |
SearchIndexConfig | searchIndexConfig | The search index config. |
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 string NamedIndex { get; }
Property Value
Type | Description |
---|---|
System.String |
NamedIndexingService
Gets the named indexing service.
Declaration
public string NamedIndexingService { get; }
Property Value
Type | Description |
---|---|
System.String |
ServiceActive
Gets or sets a value indicating whether the search service is active.
Declaration
public virtual bool ServiceActive { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Remarks
This value will be initialized from the configuration settings of EPiServer.Search.
Methods
CreateInstance(SearchHandler, IContentRepository, IContentTypeRepository, SearchIndexConfig)
Creates a new initialized instance of the search index.
Declaration
public static ContentSearchHandler CreateInstance(SearchHandler searchHandler, IContentRepository contentRepository, IContentTypeRepository contentTypeRepository, SearchIndexConfig searchIndexConfig)
Parameters
Type | Name | Description |
---|---|---|
EPiServer.Search.SearchHandler | searchHandler | The search handler. |
IContentRepository | contentRepository | The content repository. |
IContentTypeRepository | contentTypeRepository | The content type repository. |
SearchIndexConfig | searchIndexConfig | The search index config. |
Returns
Type | Description |
---|---|
ContentSearchHandler | A new ContentSearchHandler instance. |
GetContent<T>(IndexItemBase)
Converts the indexItem
to the correct IContent instance.
Declaration
public T GetContent<T>(IndexItemBase indexItem)
where T : IContent
Parameters
Type | Name | Description |
---|---|---|
EPiServer.Search.IndexItemBase | indexItem | The index item. |
Returns
Type | Description |
---|---|
T |
|
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 virtual 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 |
Returns
Type | Description |
---|---|
T |
|
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 virtual 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 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 virtual 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 |
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, IContentLoader)
Gets a collection of virtual path nodes for a content item to use in the search index.
Declaration
public static ICollection<string> GetVirtualPathNodes(ContentReference contentLink, IContentLoader contentLoader)
Parameters
Type | Name | Description |
---|---|---|
ContentReference | contentLink | The content link. |
IContentLoader | contentLoader | The content repository queryable. |
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 virtual 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 virtual 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()
Re-Index the published content.
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 virtual 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 virtual 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 virtual 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.