Lucene - search this site

Lucene Module in Sitecore: Part 2 - Using the Module

Jun 28, 2012
Carlos Martinez
Carlos Martinez

Now that you know how to install the Lucene Search Module into your Sitecore project, you can use the module to perform search on your site.

After you have installed the Lucene Search module, you will see two sub layouts in the content tree: LuceneSearchBox and LuceneSearchResults.

1. Adding the Search Box

In order to use the Lucene Search module, you must first add the Search Box to your site. It is recommended to add it to the main layout or to a sub layout that is present along all the pages of the site. This insures that search would be available from everywhere.

There are several ways to add a sub layout in Sitecore:

  • The easiest and most common is using the Page Editor. However, some configuration needs to be done on the CMS (/sitecore/Layout/Placeholder Settings) in order for this to work on the default empty site. For more information on this, please refer to Sitecore’s Presentation Component Reference.
  • Another approach is adding the sub layout to a template using the Presentation > Layout Details wizard as shown in the screen below.

  • Finally, you can use some mark-up code to add the LuceneSearchBox sub layout. This can be done in the main layout (.aspx) or a specific sub layout (.ascx). Simply add the following code to the corresponding page:

    <sc:Sublayout runat=“server”

    Path=“~/sitecore modules/LuceneSearch/LuceneSearchBox.ascx”/>

In any case the LuceneSearchBox sub layout will be displayed on the site as shown below.

Once added, the LuceneSearchBox accepts one or more search terms in the input area, and when the button is clicked or the <ENTER> key is pressed it redirects to the /sitecore/Content/Home/Standard_Items/Search_Results item.

This item will show the results found, but it needs to have the LuceneSearchResults sub layout assigned so it works properly. This is shown in the next step.

2. Adding the Results Page

Go to /sitecore/Content/Home/Standard_Items/Search_Results and using the Presentation > Layout Details wizard add the LuceneSearchResults sublayout to the item; then publish the page.

The results page will show the items found in the following format:

If you want to use the default styling, remember to add a reference to the LuceneSearch style sheet on the layout you place the search results sub layout on.

How to customize the Lucene Search Module

Lucene Search module offers a place where you customize some of the search behavior and messages shown in the site. Because these setting are stored as text, you can use them to add another language if necessary.

You will find these items under /sitecore/Content/Settings/Common Text.

Name Description
Search Text shown in the search box.
Search Category Full Title This string is used as the category header on the search results page. The header will display text like:

Results 1 to 43 in the Products area of this site

{0} - Total number of results
{1} - Site area (corresponds to the site sections)
Search Category Partial Title This string is used as the category header on the search results page. The header will display text like:

The first 3 of 43 results in the Products area of this site

{0} - Number of results shown
{1} - Total number of results
{2} - Site area (corresponds to the site sections)
Search Criteria Label shown before the search criteria on the Search Results page.
Search Index The name of the index used for searching. Do not change unless you are sure that you know what you are doing.

The search feature uses the system index associated with the master database because the starter kit sites run in "Live Mode". If you change the site to support a separate web database, you must create an associated web database index and specify its name above in order to support search.
Search Last Updated Label shown on the Search Results page for the Last Updated date.
Search Max Initial Results Indicates the maximum number of results per category to show on the initial search results page.
Search No Criteria Warning given when users click the search button without providing any search criteria.
Search No Results Message provided when search criteria returns an empty result set.

Additionally, you can go into the Custom Controls code or one of the classes that were installed and change the code to fit your requirements.

Latest insights