Kentico CMS 6.0 Tutorial ASPX

Search page

Search page

Previous topic Next topic Mail us feedback on this topic!  

Search page

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

Kentico CMS allows you to perform index-based searching through all documents in the Kentico CMS repository. For this to work, you need to have a search index created. Go to Site Manager -> Administration -> Smart search and choose to create a NewIndex New index. In the following dialog, enter the following details:

 

Display name: My website

Code name: MyWebSite

Index type: Documents

Analyzer type: Standard

Stop words: Default

Assign index to website MyWebSite: enabled

 

Click OK. You will be redirected to the index's editing interface. Switch to the Index tab and click Add allowed content (View). In the following dialog, enter /% into the Path field and click OK. Switch to the Sites tab and make sure that the index is assigned to My website. Switch to the Cultures tab and choose the default culture of your site (typically English - United States).

 

Finally, switch to the General tab and Rebuild (RebuildIndex) the index. Once the index gets rebuilt, the documents on the site are prepared to be searched.

 

 

 

Searching through uploaded text files

 

It is possible to configure the CMS to search the text inside uploaded files, such as PDF, DOC or XLS documents. The configuration is described in Developer's Guide -> Installation and deployment -> Additional configuration tasks -> Configuration of full-text search in files. It's not necessary to configure it at this moment since we will only use the document content search.

 

Now go to Visual Studio and choose to create a new web form in the CMSTemplates\MySite folder. Name the page SearchPage.aspx and check the Select master page box. Choose the CMSTemplates\MySite\MyMaster.master page in the next dialog.

 

Add the following directive to the beginning of the page code:

 

<%@ Register src="~/CMSWebParts/SmartSearch/SearchDialogWithResults.ascx" tagname="SearchDialogWithResults" tagprefix="cms" %>

 

Now enter the following code inside the <asp:content> element of the newly created page:

 

<h1>Search</h1>

 

<cms:SearchDialogWithResults ID="SearchDialogWithResults1" runat="server"

TransformationName="cms.root.smartsearchresultswithimages" Indexes="MyWebSite" />

 

This adds a header and the appropriate user control that will provide search functionality and display results. Notice that the code name of the previously created search index is specified as the value of the Indexes property of the user control.

 

Switch to the code behind and add a reference to the CMS.UIControls namespace:

 

[C#]

 

using CMS.UIControls;

 

[VB.NET]

 

Imports CMS.UIControls

 

You also need to change the class definition so that it inherits from the TemplatePage class:

 

[C#]

 

public partial class CMSTemplates_MySite_SearchPage : TemplatePage

 

[VB.NET]

 

Partial Class CMSTemplates_MySite_SearchPage

  Inherits TemplatePage

 

Save the changes.

 

Now we need to register the new page template. Go to Site Manager -> Development -> Page templates, select the My website category and click AddTemplate New template. Create a new page template with the following values:

 

Template display name: Search page

Template code name: searchpage

 

On the General tab of the page template, please set the following:

 

Template type: ASPX page

File name: ~/CMSTemplates/MySite/SearchPage.aspx

 

Click Save Save and switch to the Sites tab. Assign the new page template to My website.

 

Go to CMS Desk -> Content, select the root and click New. Choose to create a new Page (menu item) using the My website/Search page template and name the page Search. Click Save Save. Click the Down arrow in the main toolbar until you move the Search page to the end of the list.

 

tutorial_clip0134

 

Select the new /Search page and enter PC into the Search for box and click Go.

 

tutorial_clip0135

 

When you click a search result, you will be redirected to the appropriate document.

 

 

 

Modifying the search results format

 

If you prefer a different design of the search results, you can modify the format by editing the Site Manager -> Development -> Document types -> Root -> Transformations -> SmartSearchResults (or SmartSearchResultsWithImages) transformation.