Is ther a way to fix search capabilities on showstore.

greenspun.com : LUSENET : S-Mart Shopping Cart : One Thread

I have a questions hoping someone will know. Is there a way to have the search feature search for products in both words instead of products containing both words.

Example:

you do a search on "car models" the search only pulls up products containing "car models" exactly...

Is there a way to pull up products with the word "car" and products that have the word "models" and lastly "car models"

Thanks for your help and time.

Jo S joselito_s@email.com

-- Jo S (joselito_s@email.com), July 21, 1999

Answers

BPPilot@aol.com provided an excellent answer to my question. Thank you for your help. I will post his help below

This isn't the exact answer to your question but should give you a good jump-start to doing what you need to do. This will give you the first steps in the process: ie: making the script find items with ANY of the words in the search string. After a lot of thinking and playing around with different ideas I finally figured out how to get the S-mart shopping cart script to do a Booleen-type OR search. Ie: Currently when a customer types in the words BIG RED BOX the search would only find a match if there was a product with the EXACT name of BIG RED BOX. What if the product was actually named LARGE RED BOX? The user would not get any hits on their product search. I was finding on my site at least that users were typing in several words like they would do in a traditional search engine and would not find the product they were looking for. In my online store I've got over 5,400 products so it was not as though the user could just easily browse through the find the product they wanted.So, I figured out a way to make the script do an OR search instead of the exact terms in the exact order the user specified. Ie: If the user types in BIG RED BOX it will pull up ANY items that have either the word BIG or RED or BOX. It's not a perfect system, but it's a little bit closer to what I'm looking for. Basically to make this work all you need to do is add three lines to the script like I've shown below.

First, find the line that says - elsif ($type eq 'search') { then add the following lines and change the one line where it says $FORM{'search'}to make it just say $search. Here's the code:

elsif ($type eq 'search') { ADD LINE ---> @search = split(/\s+/, $FORM{'search'}); my($matches) = 0; my($i) = $pos; while (($matches < $numtolist) && ($i < $SIZE)) { ADD LINE ---> foreach $search(@search) { CHANGE LINE -----> if (index(lc $LINES[$i],lc $search) >= 0) { $matches++; my(%ITEM); $ITEM{'itemid'}, $ITEM{'name'}, $ITEM{'price'}, $ITEM{'descrip'}, $ITEM{'image'}, $ITEM{'weight'}, $ITEM{'itemurl'}, $ITEM{'group'}) = split(/\|/,$LINES[$i]); &print_item(\%ITEM); } ADD LINE ---> } $i++; } print "\n";

------------------------------------- That's all there is to making it work! Hope this helps you out a little bit so that you have a little bit more advanced of a search function. -BP

-- Jo S (joselito_s@email.com), September 21, 1999.


Moderation questions? read the FAQ