Forums / General Questions / Loosen Search Query

Loosen Search Query

Locked

Views: 1,576

Results 1 to 13 of 13
This thread is locked. New replies are disabled.
4 Dec 2007, 11:19 PM
#1
dizz avatar

dizz

Zen Follower

Join Date:
Oct 2006
Posts:
170
Plugin Contributions:
0

Loosen Search Query

Hi All,

I thought I had already posted this issue, but cannot seem to find the thread so my apologies if this is a duplicate...

My client would like to 'loosen' the search terms so that when a user runs a 'Product Search' using any of the following:

billet grille
billetgrille
redbilletgrille nissan

It would basically return any product with 'Billet Grille' in the title, regardless of spacing. I'm pretty sure adjusting the query to something such as: LIKE %$search_keywords% would do the trick, but I'm not sure where to make the change. Can anyone point me in the right direction, or perhaps offer a better solution?

4 Dec 2007, 11:54 PM
#2
hem avatar

hem

Totally Zenned

Join Date:
Sep 2007
Location:
Dublin, Ireland
Posts:
1,281
Plugin Contributions:
5

Re: Loosen Search Query

DiZZ:

I'm pretty sure adjusting the query to something such as: LIKE %$search_keywords% would do the trick, but I'm not sure where to make the change. Can anyone point me in the right direction, or perhaps offer a better solution?

It won't- what you need to do is a multi query against various lengths of your search string or do a remove of all whitespace in the search term and the field that is being searched.

I think what is needed is a 'loose search' contrib- returning each search with a percentage confidence level (and sorted by)

Andrew

Andrew Moore
Omnicia Agile Development
www.omnicia.com

5 Dec 2007, 2:00 PM
#3
dizz avatar

dizz

Zen Follower

Join Date:
Oct 2006
Posts:
170
Plugin Contributions:
0

Re: Loosen Search Query

Do you know which file contains the search query?

5 Dec 2007, 3:34 PM
#4
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Loosen Search Query

With the OR connector used on the search, you will find:
billet grille
billet
grille

brings up all three ...

You can also utilize meta tags keywords and description for building in more combinations ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

5 Dec 2007, 3:36 PM
#5
paulm avatar

paulm

Totally Zenned

Join Date:
Nov 2003
Posts:
1,878
Plugin Contributions:
5

Re: Loosen Search Query

Hi Dizz,

I think you are looking for this file:
includes\modules\pages\advanced_search_result\header_php.php

Some time ago I added this as a quick hack:

$_GET['keyword'] = trim($_GET['keyword']);

(somewhere at the top of the file)
But I am not really satisfied and will probably make other adjustments.

The part of the file you are looking for probably is:

        $where_str .= "(pd.products_name LIKE '%:keywords%'
                                         OR p.products_model
                                         LIKE '%:keywords%'
                                         OR m.manufacturers_name
                                         LIKE '%:keywords%'";

If you find your solution I hope you will post it here :smile:

5 Dec 2007, 4:38 PM
#6
hem avatar

hem

Totally Zenned

Join Date:
Sep 2007
Location:
Dublin, Ireland
Posts:
1,281
Plugin Contributions:
5

Re: Loosen Search Query

Thinking about this further, SOUNDEX could possibly be a winner. Especially as MySQL has a SOUNDS LIKE expression. Run a SELECT for description SOUNDS LIKE search_clue OR search_clue SOUNDS LIKE description

Andrew

Andrew Moore
Omnicia Agile Development
www.omnicia.com

5 Dec 2007, 8:45 PM
#7
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: Loosen Search Query

hem:

Thinking about this further, SOUNDEX could possibly be a winner. Especially as MySQL has a SOUNDS LIKE expression. Run a SELECT for description SOUNDS LIKE search_clue OR search_clue SOUNDS LIKE description

There could be some big challenges with multi-lingual sites when using that approach. Something to keep in mind as you research further.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

5 Dec 2007, 10:09 PM
#8
hem avatar

hem

Totally Zenned

Join Date:
Sep 2007
Location:
Dublin, Ireland
Posts:
1,281
Plugin Contributions:
5

Re: Loosen Search Query

DrByte:

There could be some big challenges with multi-lingual sites when using that approach. Something to keep in mind as you research further.

That's true- SOUNDEX only works on English. Plus it won't handle multi-byte either.

Andrew

Andrew Moore
Omnicia Agile Development
www.omnicia.com

6 Dec 2007, 8:44 AM
#9
paulm avatar

paulm

Totally Zenned

Join Date:
Nov 2003
Posts:
1,878
Plugin Contributions:
5

Re: Loosen Search Query

paulm:

Some time ago I added this as a quick hack:

$_GET['keyword'] = trim($_GET['keyword']);

> (somewhere at the top of the file) 
> But I am not really satisfied and will probably make other adjustments.
Sorry I made a mistake, this will not help for any spacing issues, it only helps to for several other characters that the customer may enter, like "-" for example.
(which may not seem logical at first when you look at the code, which explains why I mixed up things myself too, must add a comment to this line ... )
6 Dec 2007, 9:27 PM
#10
dizz avatar

dizz

Zen Follower

Join Date:
Oct 2006
Posts:
170
Plugin Contributions:
0

Re: Loosen Search Query

Ah thanks anyway Paul - I guess the '%' in '%$keyword%' only accounts for actual characters, not spaces?

Honestly I think this is really minor, but my client is stuck on the idea that all users are idiots and that by 'loosening' the search query the site will become more idiot-proof.

I'd appreciate any rebuttals if you have them - LOL!

6 Dec 2007, 11:26 PM
#11
paulm avatar

paulm

Totally Zenned

Join Date:
Nov 2003
Posts:
1,878
Plugin Contributions:
5

Re: Loosen Search Query

:D

If I remember correctly, all input spaces are first being used as word separators and then trimmed, and after that several other characters are converted to spaces and then ...... ?

Anyway, soundex might indeed help a bit (if the only language is English). I would certainly not call it a winner though. It's easy to beat the soundex results by some simple string replacements in PHP (even if the language is English), but for obvious reasons a php script can not be a real winner either....

6 Dec 2007, 11:47 PM
#12
hem avatar

hem

Totally Zenned

Join Date:
Sep 2007
Location:
Dublin, Ireland
Posts:
1,281
Plugin Contributions:
5

Re: Loosen Search Query

I've also checked RLIKE (REXEXP) and MATCH() AGAINST () but they are not going to do what you are looking for. My ideas would be:

1: str_replace the space character into '%'s and then tacking futher '%' each end of a TRIMed search and use this as the search in the MySQL query.

2: Explode the search into an array and then use a FOREACH to create a search of 'product_name LIKE '%'.search_word.'%' and OR all the results together.

However this won't get over someone searching for 'redbilletgrillenissan' matching to 'billet grille'. But then I don't think it should- someone putting that much info into a search criteria is obviously trying to narrow down the search and probably won't be happy if the search returns every occurance of 'grille' it finds.

Andrew

Andrew Moore
Omnicia Agile Development
www.omnicia.com

7 Dec 2007, 2:39 PM
#13
hem avatar

hem

Totally Zenned

Join Date:
Sep 2007
Location:
Dublin, Ireland
Posts:
1,281
Plugin Contributions:
5

Re: Loosen Search Query

The more I think about this the more I get the feeling that just setting Admin->My Store->Default Search Operator to 'OR' would probably be the best solution...

Andrew

Andrew Moore
Omnicia Agile Development
www.omnicia.com