close ad
WARNING PC USERS: Do Not Install the DREAMWEAVER CC 2017 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Search by exact string of words

Thread began 8/17/2011 2:45 pm by johnb | Last modified 8/18/2011 12:49 pm by johnb | 880 views | 6 replies |

johnb

Search by exact string of words

I have a clients site that has thousands of products. The client would like the search results to show only the exact combination of words. For example if they currently search for RED CAR then they'll get every single product that has the word RED or CAR. They want instead for it to always bring back only the Exact phrase RED CAR. We have noticed by putting quotes around "RED CAR" that it will perform the way they want but they can't expect all users to know how to do that. Is there something that I can change in the code that will make it always reveal only the exact phrase mach when searched?

BTW This is Powerstore 3

Sign in to reply to this post

Jason ByrnesWebAssist

you can try adding the following code at line 1 of the products_Results.php page:

php:
<?php

if(isset($_GET["S_ProductName"]) && $_GET["S_ProductName"] != "" && substr($_GET["S_ProductName"], 0,1) != "\""  && substr($_GET["S_ProductName"], -1,1) != "\"") {
    
$_GET["S_ProductName"] = "\"".$_GET["S_ProductName"]."\"";
}
?>



it will force quotes around the search string.


it may be better, though, to add a message to the FAQ section explaining how to do an exact match search.

Sign in to reply to this post

johnb

I realize this is a tad different spin on the question above but what if they wanted to return RED CAR results bringing up only products that use both words and not necessarily in order?

Sign in to reply to this post

Jason ByrnesWebAssist

well, if you used the code i supplied before, you would not be able to do that

the search is configured to use a space as the OR separator:
RED CAR would search:
WHERE column LIKE '%RED%' OR column LIKE '%CAR%'

it uses ", " (coma followed by a space) as the and separator:
RED, CAR Would search:
WHERE column LIKE '%RED%' AND column LIKE '%CAR%'

if you force quotes around all search strings, you loose that flexibility, which is why I suggested an FAQ entry to explain the full string search as a better alternative.

If you dont modify the code, you can do fairly complex searches like:

"RED CAR", "WHITE TRIM"

this would search for
WHERE column LIKE '%RED CAR%' AND column LIKE '%WHITE TRIM%'

Sign in to reply to this post

johnb

Would there be a solution to always force the space to be a comma similar to forcing the result to have quotes around it as in the fist example? I understand you couldn't do both quotes and comma rewrites.

I really appreciate your quick help on this.

Sign in to reply to this post

Jason ByrnesWebAssist

on the products results page, change the following line of code:


php:
$WADbSearch1->keywordComparison($KeyArr1,"".((isset($_GET["S_ProductName"]))?$_GET["S_ProductName"]:"")  ."","WHERE","Includes",",%20","%20","%22","%22",0);



to:

php:
$WADbSearch1->keywordComparison($KeyArr1,"".((isset($_GET["S_ProductName"]))?$_GET["S_ProductName"]:"")  ."","WHERE","Includes","%20",",%20","%22","%22",0);




this will change it so that " " (space) is used as the AND separator and ", " (comma space) is used as the OR separator.

Sign in to reply to this post

johnb

I really appreciate your help Jason! I hope this thread will benefit others with this need as well. It works famously!

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...