Modify Search results

When doing a search for rings on my website it returns earrings which i do not want obviously, so my questions is how would I modify the search results so it doesn’t return results containing part of the search term when in occurs in middle of a word (as opposed to the beginning of a word which I do want the search results to show)

the whole search area needs to be more tailorable. An admin needs to be able to specify what options to make available to their customers and the customers need to be able to choose more simply. I.e. for any search phrase there needs to be a selector for “contains”, ‘exact match’, 'all words’or ‘one or more words’.

No cart can meet the needs of all merchants without making this stuff configurable.

I could probably dig out the area of code where you’d change a condition from ‘LIKE’ to ‘=’ but that would be a mod to the core.

I don’t have a working solution yet, but it looks like the change needs to be made to fn.catalog.php around line #3030.

```php if ($params[‘pfull’] == ‘Y’) {

$tmp .= db_quote(" OR descr1.full_description LIKE ?l", “%$piece%”);

} ```

The LIKE in those queries could be replaced with a REGEXP like this:WHERE full_description REGEXP '[[:<:]]$string[[:>:]]' = 1

That REGEXP does a nice job of only returning whole-word matches when I test it in phpmyadmin. Unfortunately, I don’t know PHP well enough to integrate it correctly. Can you lend a hand, Tony?

A better solution might be to add a “stop-word list” field to the product. Words in this field would explicitly prevent the item from appearing in search results upon a keyword match.

While investigating this, I noticed that the Search Words are always used by the search function - even when the “keywords” checkbox is unchecked. Bug report submitted.


thanks guys, I’ll try playing around with this to see if I get anywhere.

Assuming your REGEX is what you want, then the code should be changed to:

if ($params['pfull'] == 'Y') {
$tmp .= db_quote(" OR descr1.full_description REGEX ?s = 1", "[[:<:]]$piece[[:>:]]");

I’m not familiar enough with using REGEX in mySQL statements. I’m assuming it returns the number of matches, hence the " = 1".

Did you all ever figure out how to have the search match who words only?