Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Getting Quick Search to do Whole Word Searches

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 07-05-2011, 11:59 PM
 
xcart-dev xcart-dev is offline
 

Advanced Member
  
Join Date: Jun 2011
Posts: 59
 

Default Getting Quick Search to do Whole Word Searches

I've been looking around for an answer to this but can't seem to find one.

You can set the search results to be for 'any', 'all' or the exact phrase. What I need is to set the search to be the exact phrase and a whole word.

In php this would be
PHP Code:
if (preg_match("/\b$search_string\b/i"$database_output)) 
which results in a case insensitive result but only for whole words.

Now there must be somewhere in X-Carts many files where I can take the search result and change it into a 'whole word' requirement. This is important for part numbers such as the following:
Searching "EC-22" should only show up part number EC-22, not part number EC-22542.

Any suggestions how and where ... ?
__________________
X-Cart 4.4.3
Reply With Quote
  #2  
Old 07-06-2011, 04:22 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,201
 

Default Re: Getting Quick Search to do Whole Word Searches

include/search.php
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #3  
Old 07-06-2011, 09:39 AM
 
xcart-dev xcart-dev is offline
 

Advanced Member
  
Join Date: Jun 2011
Posts: 59
 

Default Re: Getting Quick Search to do Whole Word Searches

It was indeed include.search.php.

For anyone who stumbles on this thread I wanted to have whole word matches but only in the extra fields. So I changed:

Code:
foreach ($data['extra_fields'] as $k => $v) { $condition[] = '(' . $sql_tbl['extra_field_values'] . '.value LIKE \'%' . $data['substring'] . '%\' AND ' . $sql_tbl['extra_fields'] . '.fieldid = \'' . $k . '\')'; }

To:
Code:
foreach ($data['extra_fields'] as $k => $v) { $condition[] = '(' . $sql_tbl['extra_field_values'] . '.value REGEXP \'[[:<:]]' . $data['substring'] . '[[:>:]]\' AND ' . $sql_tbl['extra_fields'] . '.fieldid = \'' . $k . '\')'; }

The Regexp now demands that only whole words are found rather than words 'like'
__________________
X-Cart 4.4.3
Reply With Quote

The following user thanks xcart-dev for this useful post:
mcinque (08-22-2018)
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 12:06 PM.

   

 
X-Cart forums © 2001-2020