Search Field

21 posts by 3 authors in: Forums > CMS Builder
Last Post: July 6, 2011   (RSS)

I currently have a search field that is searching name_keyword. However, I have a product that is called Beam4. If you search Beam 4, with the space, you get no results found.

Can I have it search each word or ignore spaces?

Please advise.

Re: [dccreatives] Search Field

By Jason - June 23, 2011

Hi,

On your search results page, you can use this to remove white spaces before you do your getRecords query:

// remove white space
if (@$_REQUEST['name_keyword']) {
$_REQUEST['name_keyword'] = str_replace(" ", "", $_REQUEST['name_keyword']);
}


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 Field

Where should I put this code?

I placed it in the header and I am still getting a record not found.

Attached is my header.
Attachments:

header_001.php 7K

Re: [dccreatives] Search Field

By Jason - June 28, 2011

Hi,

This code should go right before the getRecords() function at gets your search results. I took a look at your code and it looks like your form is submitting to "search.php", so your code would have to go there.

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 Field

Thanks Jason, you're great.

One small issue left.

When I search Dia 1x1 or Dia 2x4 which are product names, I am not getting results.

When I search Dia without the sizing, I do get results. How can I get the results for the Dia 1x1,etc?

Re: [dccreatives] Search Field

By Jason - June 28, 2011

Hi,

CMS Builder's automatic searching looks to see if the string appears somewhere in that field. It searches for the entire string, not each individual word.

To see what your query is actually searching for, you can add:

'debugSql' => true,

to your getRecords options. this will output the query that is being executed. You can then compare what is being searched for against the records you're expecting to see.

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 Field

This is the debug code:SELECT SQL_CALC_FOUND_ROWS `items`.*FROM `cms_items` as `items` WHERE (1 AND (`name` LIKE '%plano1x1%')) AND items.hidden = 0 ORDER BY dragSortOrder DESC LIMIT 45Where it is searching plano1x1, but in the backend, it has a space. How can I get it to ignore white space in both the search field and the name field?I want if someone searches dia 1x1 or dia1x1, it should provide the same results. It is interesting that Beam3 and BEam 3, both work, but the above example does not work.

Re: [dccreatives] Search Field

By Jason - June 29, 2011

Hi,

You can use the MYSQL function REPLACE to remove the white space from name field in the WHERE clause.

For example:

'where' => "REPLACE(name, ' ', '') LIKE '%".mysql_escape(@$_REQUEST['name_keywords'])."%'",

Hope this helps get you started.
---------------------------------------------------
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 Field

Where should I put it in my search.php document?

I put it on line 14

Instead of this:

list($itemsRecords, $itemsMetaData) = getRecords(array(
'tableName' => 'items',
'where' => whereRecordNumberInUrl(1),
'limit' => '45',
));

I put this, but it did not work, still giving me no results.

list($itemsRecords, $itemsMetaData) = getRecords(array(
'tableName' => 'items',
'where' => "REPLACE(name, ' ', '') LIKE '%".mysql_escape(@$_REQUEST['name_keywords'])."%'",

'limit' => '45',
));



I attached the php file.
Attachments:

search_009.php 5K

search_010.php 5K