Re: [aev] Tutorial: CMS Builder Search Engine
Sure. We're still figuring out the best way to "officially" add this functionality. Probably it will be some sort of "search engine code generator". But here's how to do it right now. There's a little bit of PHP and MySQL but I'll walk you through it.
Start with your standard "List Viewer" that you're using to display your content.
Add the search form at top. Here's a simple one:
<form method="get" action="<?php echo $_SERVER['PHP_SELF'] ?>">
Keyword: <input type="text" name="keyword" value="" size="15">
<input type="submit" name="" value="Search">
</form>
Next, in the record list loader code, replace the "$options['where'] = ''" line with this code (using your own fields if you don't have title, summary, and content):
$escapedKeyword = escapeMysqlString( @$FORM['keyword'] );
$options['where'] = "title LIKE '%$escapedKeyword%' OR
summary LIKE '%$escapedKeyword%' OR
content LIKE '%$escapedKeyword%'";
This adds on to the WHERE part of the MySQL statement which tells it what records to return. The "LIKE" means "looks like" and the "%" means anything. So it will return record where the title has the title has the keyword in it -OR- the summary -OR- etc. (Don't forget to use your own fieldnames or you'll get an error).
You can also do numeric (greater than, less than) searches and exact match search (show only articles from category X).
Then finally, add this code _below_ the line with getListRows();
$scriptUrl = $_SERVER['PHP_SELF'];
$encodedKeyword = urlencode(@$FORM['keyword']);
$listDetails['prevPageLink'] = "$scriptUrl?keyword=$encodedKeyword&page={$listDetails['prevPage']}";
$listDetails['nextPageLink'] = "$scriptUrl?keyword=$encodedKeyword&page={$listDetails['nextPage']}";
This updates your prev/next links to pass the keyword along when you switch from page to page so you're still only getting filtered results.
So, we haven't automated this part of yet, but it's still possible with a few lines of code. Let me know if it works or if you need more help with it. :)
Dave Edis - Senior Developer
interactivetools.com