Percipient Studios logo

Using XSLTsearch with CWS

23 July 2012
Filed under: umbraco, xsltsearch - by Douglas Robar

Warren Buckley's excellent Creative Website Starter (CWS) is a great way to get started with Umbraco, allowing you to see how a finished site is constructed. In 2012 CWS was updated to use the built-in "Examine" search engine in Umbraco 4.7.

As powerful as Examine is (it's built on top of Lucene.Net), it isn't always convenient to get up and running quickly. Garrett Fisher asked how to use XSLTsearch instead. Let me show you how to do it.

How to do it

I'll assume that you have CWS installed already, and have also installed the XSLTsearch package. Because CWS already has almost everything we need we really only need to modify the original template to use the XSLTsearch macro

  • In the Settings section, open the XSLTsearch template. Copy the <umbraco:Macro ...></umbraco:Macro> lines to the clipboard.
  • Now open the Search (only called with template alias) template and delete the existing <umbraco:Macro runat="server" Alias="CWS_ExamineSearch" /> line.
  • Paste in the XSLTsearch macro from the clipboard in its place.
  • Save the template.

The updated template should now look like this:

<%@ Master Language="C#" MasterPageFile="~/masterpages/CWS_Master.master" AutoEventWireup="true" %>

<asp:content ContentPlaceHolderId="headerLinksContent" runat="server">  
</asp:content>

<asp:content ContentPlaceHolderId="SideBarContent" runat="server">  
</asp:content>

<asp:content ContentPlaceHolderId="ChildContent" runat="server">
    <div id="main" class="content oneCol left clearfix" role="main">
      <umbraco:Macro runat="server" Alias="XSLTsearch"
        macroAlias="XSLTsearch"
        source="-1"
        searchFields="@nodeName,metaKeywords,metaDescription,bodyText"
        previewFields="bodyText,metaDescription"
        previewType="beginning"
        searchBoxLocation="none"
        resultsPerPage="5"
        previewChars="255"
        showPageRange="0"
        showOrdinals="0"
        showScores="0"
        showStats="1">
      </umbraco:Macro>
  </div>
</asp:content>

Making it even better

By default, XSLTsearch will automatically look within the common document type properties. CWS has additional properties we should also search within. We can also stop displaying the search box on the results page since the site's banner has a search box already in it. Thus, we will make the following changes to the XSLTsearch macro parameters found on the Search template we edited a moment ago.

The XSLTsearch documentation (PDF) explains all the parameters in detail so I'll just show you the finished result. Every XSLTsearch user should look over the documentation to get the most out it and customize it to their needs.

searchFields="@nodeName,metaKeywords,metaDescription,headerText,bodyText,bodyTextColOne,bodyTextColTwo,photoText,formText"

previewFields="formText,photoText,bodyTextColTwo,bodyTextColOne,bodyText,headerText,metaDescription"

searchBoxLocation="none"

The fully updated macro should now contain the following parameters:

<umbraco:Macro runat="server" Alias="XSLTsearch"
    macroAlias="XSLTsearch"
    source="-1"
    searchFields="@nodeName,metaKeywords,metaDescription,headerText,bodyText,bodyTextColOne,bodyTextColTwo,photoText,formText"
    previewFields="formText,photoText,bodyTextColTwo,bodyTextColOne,bodyText,headerText,metaDescription"
    previewType="beginning"
    searchBoxLocation="none"
    resultsPerPage="5"
    previewChars="255"
    showPageRange="0"
    showOrdinals="0"
    showScores="0"
    showStats="1">
</umbraco:Macro>

Tidying up

Because we are using everything except the XSLTsearch macro we can delete the unused bits.

  • Delete the Search page from the Content section
  • Delete the XSLTsearch template from the Settings section
  • Delete the XSLTsearch document type from the Settings section

And that's all there is to it!

0 comments for “Using XSLTsearch with CWS”

 
powered by <XSLTsearch>

Categories

Follow Us

RSS Feed
Follow us on Twitter
Follow us on Flickr