Search page

Top  Previous  Next

Kentico CMS allows you to full-text search all documents in Kentico CMS repository. You can also configure it so that it searches the text inside uploaded documents, such as PDF, DOC or XLS documents. The configuration is described in Developer's Guide -> Installation and deployment -> Configuration of full-text search in files. It's not necessary to configure it at this moment since we will use the database search only.

 

Go to Visual Studio and choose to create a new ASPX page in folder CMSTemplates\MySite. Call the page SearchPage.aspx and check the box Select master page. Choose the CMSTemplates\MySite\MyMaster.master page on the next dialog.

 

Add the following HTML code inside the <asp:content> element:

 

<h1>Search</h1>

 

Switch to the Design tab and drag and drop the user control CMSWebParts/search/cmscompletesearchdialog.ascx under the Search header:

 

clip0104

 

Set its properties:

 

TransformationName: cms.root.searchresults
ShowSearchScope: false

 

Switch to the code behind and add 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 our new page template. Go to CMS Site Manager -> Development -> Page Templates and click My Web Site and click New template. Enter the following values:
 

Template display name: Search page
Template code name: searchpage

 

Click OK. Enter the following values on the General tab:

Template type: ASPX page
File name: ~/CMSTemplates/MySite/SearchPage.aspx

 

Switch to the Sites tab and assign the template to My web site site.

 

Go to CMS Desk -> Content, click the root and click New. Choose to create a new Page (menu item) and enter the following values:

Page name: Search
Use page template: My web site/Search page

 

Click Save. Click the Down arrow in the main toolbar until you move the Search page at the end of the list.

 

clip0037

 

Click the new /Search page. You will see the search page. Enter PC in the Search for box and click Go.

 

clip0035

 

When you click some search result, you are 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 in Site Manager -> Development -> Document types -> Root -> Transformations -> searchresults transformation.