Percipient Studios logo

User modification to XSLTsearch for easier multi-site searching

11 November 2010
Filed under: umbraco, xslt, xsltsearch - by Douglas Robar

Sebastiaan Janssen (@cultiv) mentioned a nice modification he makes to XSLTsearch on the our.umbraco forum today, simplifying its use in multi-lingual websites. It is so useful and simple I thought I would explain it in detail.

XSLTsearch 3.0 uses Umbraco dictionary keys to translate the various bits of text that appear on the search page. The same search macro can be used everywhere on your site and will display in the site's language and culture.

You can either search all pages or specify the page to begin searching beneath (the 'source' parameter in the XSLTsearch macro). If you have multiple websites within one Umbraco installation you can make a small change to XSLTsearch and each site will instantly search only within its own pages.

Here's what a typical multi-site installation would look like:

XSLTsearch in multiple umbraco sites

We'd rather not create multiple templates for XSLTsearch for each site, nor insert the XSLTsearch macro in a richtext editor page on each site, forcing editors to decide what to enter in each of the macro properties.

Thankfully XSLTsearch is easy to modify to meet your needs. The key, as Sebastiaan says, is to use the ancestor-or-self XPATH axis to set the source used when searching. We want to use the top-most page in whatever site is currently being viewed. That is, to the page that is at the first level in the content tree.

By default, XSLTsearch will search all pages if you don't tell it otherwise.

<xsl:call-template name="search">
  <xsl:with-param name="items" select="umbraco.library:GetXmlAll()/*"/>
</xsl:call-template>

 

What we want to do is change the default behavior to this:


<xsl:call-template name="search">
  <xsl:with-param name="items" select="$currentPage/ancestor-or-self::*[@level = '1']"/>
</xsl:call-template>

 

That's all there is to it! Thanks for the tip, Sebastiaan!

0 comments for “User modification to XSLTsearch for easier multi-site searching”

 
powered by <XSLTsearch>

Categories

Follow Us

RSS Feed
Follow us on Twitter
Follow us on Flickr