I love Perch, a very small, easy, but deceptively powerful CMS. I've been using it on a couple of clients' sites and have loved it so far. It is commercial (costs around $50), but as happens frequently, the warm-kumbaya-free-love-open-source feeling you miss out on by using a commercial solution is replaced with a better experience:
I don't want to am not going to reluctantly will make this quick argument for closed source: most of the open source software (not just CMSs) I've used has sub par interface design and a bad user experience. I'm looking at you, Drupal.
Anyway, one of the several key things missing from Perch is site-wide search. I wrote a very (and I mean very) simple search engine plugin few lines of code to search through a Perch site and list out links to relevant pages and quick summary of that page's content. PHP, naturally. This is pretty hacky: it just pokes around in the database and lists out regions it finds that match the search given, with a link to the page the region was found on (excluding shared regions). Your mileage may vary.
I wrote this before Perch introduced apps, which may or may not make this obsolete. I haven't had time to look at what apps brings to the table to help with this.
I'm very interested in getting some feedback on this—I'd like to be able to parse out the title of the page somehow instead of just using the URL as the identifier of the page to the user, for instance—but I wanted to get it out there in case there's any Perchers Perchians Perchites Perch developers out there looking for a quick and dirty solution.
Without further adieu, I give you Serch (*snort*):
// Serch
// A really little search engine
// Alex Ford, 2010
// http://isseriousbusiness.com
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details. */
function serch($query) {
$cleanQuery=mysql_escape_string($query);
echo "";
$SQL="SELECT * FROM perch_contentItems WHERE contentHTML LIKE '%".$cleanQuery."%' AND contentPage !='*'";
$query=@mysql_query($SQL);
if (!$query) die(mysql_error());
if (mysql_num_rows($query)<1 || !$cleanQuery) {
echo "No results.";
return;
}
$pages[]=Array();
echo "";
while ($result=mysql_fetch_array($query)) {
if (!array_search($result['contentPage'],$pages)) {
$pages[]=$result['contentPage'];
echo "- ";
echo "".$result['contentPage']."";
echo "".strip_tags(truncate($result['contentHTML'], 200))."";
echo "
";
}
}
echo "";
}
// Support function(s)
// Original PHP code by Chirp Internet: www.chirp.com.au
// Please acknowledge use of this code by including this header.
function truncate($string, $limit, $break=".", $pad="...") {
// return with no change if string is shorter than $limit
if(strlen($string) <= $limit) return $string;
// is $break present between $limit and the end of the string?
if(false !== ($breakpoint = strpos($string, $break, $limit))) {
if($breakpoint < strlen($string) - 1) {
$string = substr($string, 0, $breakpoint) . $pad;
}
}
return $string;
}
I wouldn't bother licensing this, except I think the WTFPL license is hilarious. So there's that.