Symphony Section Search
November 03, 2006
Recently I’ve had a couple of e-mails asking about how to set up the Section Search CS in Symphony. The sample code and example XML is certainly very good but some people still find it a tad confusing.
Here’s a quicky guide to getting it setup!
Step 1 – Setting Up
Download the campfire service and then make yourself a new page with the Section Search DS attached to it. In this case I’m going to call mine search, for the simplicity but you’re unrestricted in how you name yours.
Step 2 – The Form
Once you’ve got your page setup you need a search form. Here’s an example of one from this site:
<form action="http://creativeflux.co.uk/search/" method="get">
<label>Enter your query <input name="query" type="text" /></label>
<input name="submit-search" type="submit" value="Search" />
<input name="page-offset" type="hidden" value="1" />
<input name="search-mode" type="hidden" value="simple" />
<input name="limit" type="hidden" value="50" />
<input name="section" type="hidden" value="entries" />
</form>
So the above form is doing the following:
- On submission it’s taking us to my search page and sending all of the variables as GET requests
- My Page offset is
1meaning I’m showing the first 50 results - My search mode is simple, other options are Boolean and normal, you can get explanations on what they do from the DS page.
- I have set a limit of 50 entries be returned.
- I’m searching the entries section. (It’s not possible to search multiple section currently)
You can put this form anywhere on your site, I have it in my master so you can search from every page for example. Once we’ve got our form it’s onto the last step…
Step 3 – Displaying Results
The Section Search CS is very helpful in that it offers some sample XML at the bottom of the DS info page to help us write our code. I won’t include it here as I don’t want you to be scrolling forever but if you open it then you’ll see how the following code works:
<xsl:if test="search-results/pagination-info/@total-results != '0'">
<xsl:for-each select="search-results/entry">
<div class="entry">
<h2><a href="{$root}/entries/{@handle}"><xsl:value-of select="fields/title"></xsl:value-of></a></h2>
<xsl:copy-of select="fields/body/p[1]"></xsl:copy-of>
</div>
</xsl:for-each>
</xsl:if>
All I’m doing there is saying:
- If I have search results then move on and
- For each entry node, display the title of the entry, it’s permalink and then just the 1st paragraph of the entry. (For usability, 50 full entries would take up a lot of space!)
And that, is all there is too it. You can obviously make it a bit fancier, offer more feedback to the user based on their input but this should get you up and running for a start.
Feedback?
If you’ve found errors or have some feedback please . Comments aren’t currently enabled due to spam but I’m sure they’ll return in the future.