Search - Whole Words

5 posts by 3 authors in: Forums > CMS Builder
Last Post: January 4, 2011   (RSS)

By newB - January 4, 2011

Hi,
I found a post in another interactivetools forum about Searching only whole words (It's from 2004 - http://www.interactivetools.com/iforum/Products_C2/CMS_Builder_F35/gforum.cgi?post=31614).

Right now, i have a search form on my CMS Builder and when client searches for Ice..the word Lice comes up. Is there an easy fix for this? I tried adding <input type="hidden" name="whole_word" value="2"> to the search form but it didnt seem to work.

Re: [newB] Search - Whole Words

By Jason - January 4, 2011

Hi,

There isn't a way to have CMS Builder do this automatically, however, we can do this be creating our own where clause.

In this example, we'll search a section called news, searching on the title field. The name of the field in our form will be title. Here is how we'll select the records:

$where = "title REGEXP '[[:<:]]". mysql_real_escape_string( @$_REQUEST['title'] ) ."[[:>:]]' = 1 ";

list($newsRecords,$newsMetaData)=getRecords(array(
'tableName' => 'news',
'where' => $where,
'allowSearch' => false,
));


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Search - Whole Words

By newB - January 4, 2011

Thanks Jason for replying! Not too familiar with mysql and tried your suggestion (by pasting it on the list page), but im getting an error. It think its because i am searching on multiple fields. Right now, this is how my form is...do you have a suggestion on searching multiple fields within that table?

<form name="search" method="post" action="search.php">

<input name="title,content_keyword,subtitle_keyword,category,author,summary_keyword,contents_keyword,about_the_author_keyword,category_keyword" type="text" id="textfield" size="17">

<input name="submit" type="image" value="Search" src="images/images/search_btn.jpg" alt="" align="left" width="37" height="48">
</form>

I am searching multiple fields on a table called "books"
This is what i have on the listviewer.php

list($booksRecords, $booksMetaData) = getRecords(array(
'tableName' => 'books',

Re: [newB] Search - Whole Words

By newB - January 4, 2011

Chris, that worked out very well! Thank you!