Tutorial: CMS Builder Search Engine (Outdated, See Docs for Searching)

10 posts by 4 authors in: Forums > CMS Builder
Last Post: November 1, 2008   (RSS)

By Dave - December 11, 2007 - edited: January 21, 2008

I don't think it's been mentioned, but building a search engine to search a specific section of your website is very easy with CMS Builder.

If anyone has a search engine they want to build just post and I'll help you out with it.

Update: This is now outdated. Searching is now built in. See this doc page: http://www.interactivetools.com/docs/cmsbuilder/viewer_search.html
Dave Edis - Senior Developer
interactivetools.com

Re: [aev] Tutorial: CMS Builder Search Engine

By Dave - December 12, 2007

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&amp;page={$listDetails['prevPage']}";
$listDetails['nextPageLink'] = "$scriptUrl?keyword=$encodedKeyword&amp;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

Re: [Dave] Tutorial: CMS Builder Search Engine

By Dave - January 11, 2008

Update, this is now all automatic in v1.07. All you need is to make a search form. Use "myfieldname_match" for exact matches and "myfieldname_keyword" for keyword matches.

<form method="get" action="<?php echo $_SERVER['PHP_SELF'] ?>">
Keyword: <input type="text" name="myfield_keyword" value="" size="15">
<input type="submit" name="" value="Search">
</form>

Dave Edis - Senior Developer
interactivetools.com

Re: [aev] Tutorial: CMS Builder Search Engine

By Theo - January 21, 2008

Here's a link to CMS Builder's search engine docs:

http://www.interactivetools.com/docs/cmsbuilder/viewer_search.html
Theo Wiersma

Re: [Dave] Tutorial: CMS Builder Search Engine

Hi, Dave.

Do you have any sample code for getting the matching results to appear on the listViewer.php (results) page?

Thanks.
Nigel Gordijk

Common Sense Design: User-focused Web design
Tel: 001 519 342 5348 | Web: www.commonsensedesign.net

Re: [NigelGordijk] Tutorial: CMS Builder Search Engine

By Dave - October 30, 2008

Hi Nigel,

If you start with a page that lists "all" the results, the search engine will just filter those. So use a regular list page, and then point your search form at that.

Hope that makes sense, let me know if you need more details.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Tutorial: CMS Builder Search Engine

Hi, Dave.

I actually needed the tags that displays the results on a search results page. I have a search form on this page that goes to the results page when you click on the submit button: http://www.satoa.com/membersList.php. However, I don't know what to put in the results page code - http://www.satoa.com/listViewer.php - so that the matching results are shown.

Regards,
Nigel Gordijk

Common Sense Design: User-focused Web design
Tel: 001 519 342 5348 | Web: www.commonsensedesign.net

Re: [NigelGordijk] Tutorial: CMS Builder Search Engine

By Dave - October 31, 2008

Hi Nigel,

Start by making this page list "all results":
http://www.satoa.com/listViewer.php

Then it should work. Let me know if you're still having trouble once you get that page displaying all results.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Tutorial: CMS Builder Search Engine

Thanks, Dave. I've got it working perfectly! :-)
Nigel Gordijk

Common Sense Design: User-focused Web design
Tel: 001 519 342 5348 | Web: www.commonsensedesign.net