Better Search?

Is there a better search module or some hacks somewhere or scan someone point me to where to edit the code? The quick search this cart uses is very stupid… it doesn’t remove leading/trailing spaces, it should use wild cards before and after each word so partial words match. Idealy it should also search for words in any order and rank them based on most occurances of the most words… but that’s wishful thinking.



A simple hack to replace all spaces with % before calling SQL would do just grand. Very simple fix/hack and helps searches match 10 fold. Where could I do that in the code base?



If I try to search for “cheat dice” it won’t fine “cheater dice”



If I try to search “d20 cheater” won’t pull up my “16mm cheater d20” product.







Thanks

James

http://www.RPGShop.com

Hmm… you mean like the Enhanced Search I wrote for magento? :wink:



[url]Magento Extensions & Themes for Your Online Store | Marketplace

In the file fn.catalog.php in the /core/ directory.



This function

fn_get_products($params, $items_per_page = 0, $lang_code = CART_LANGUAGE)

controls a lot of the search functionality.



What you are talking about with removing whitespace and wildcards was the next thing on my list after my more intutive product addition changes. Its complete **** that CS-Cart allows spaces to count as search criteria, and I too feel your disappointment with the search.



A good start would be looking around near this line line in the function above:



foreach ($pieces as $piece) {




which starts to loop through the search string the user put in and breaks it up into ‘pieces’ … haven’t quite figured out why the whitespace is still included. I am not saying this is where it is, but I am saying this is part of how search works. I just haven’t had enough time to look at it. its probably simple, but its not bothering me or my users enough yet, so its lower priority for me.



don’t forget to post back and let us know what you find! if I get to it before you, i will pm you or post here.

I don’t even use the cs-cart search function.



Here’s a partial search for ‘c66’:



[url]http://www.inkwow.com/index.php?dispatch=global_search.results&q=c66[/url]





Matches anything that contains ‘c66’

good point hyte, we could use a different search.



i want to modify the cs-cart one though… it seems good except for the space thing. its also nice if you modify it to take ALL the search words instead of ANY.

As I stated, a QUICK HACK would be to just find the string that’s passed into the search function and do a grep replace of all white space with %'s and ad one to the beginning and the end… doesn’t matter if you and up with a word like ‘%%cheap%%dice%’ or something as obnoxious, SQL will handle it just fine and the majority of the issues are solved.



So if I get a chance to try to find that bit of code where it’s passed in as one string I’ll see if I can make a quick hack and post it here.



James

http://www.MinionGames.com

[quote name=‘hyteckit’]I don’t even use the cs-cart search function.



Here’s a partial search for ‘c66’:



[url]http://www.inkwow.com/index.php?dispatch=global_search.results&q=c66[/url]



Matches anything that contains ‘c66’[/QUOTE]



Meaning that you wrote your own or that you hacked a call into the template to call the advanced function instead or what? Showing me that your cart works means nothing to me.



James

Ok, they might have updated the code since the last time I was upset :slight_smile: Cause it seems by default it’s now using % at the beginning and end of the keywords… but still that’s not really the best solution as it doesn’t trim.



The function also doesn’t search product codes (model numbers) which my staff and some customers actually enjoy doing in our old software.



So I made two quick hacks that actually make the search more friendly to mistakes and gives the ability to search on product codes.



Just edit this file: /core/fn.catalog.php



Right under this line (about line 3520) in function fn_get_products():


foreach ($pieces as $piece) {




Add the line:


$piece = str_replace(' ', '%', trim($piece));




Then if you want to add the part to allow searching by product code (both in the ADMIN and by customers), then right below the line:



$tmp = db_quote(" (descr1.search_words LIKE ?l)", "%$piece%"); // check search words




add this new line:


$tmp .= db_quote(" OR (products.product_code LIKE ?l) ", "%$piece%");




Good luck and make sure you make a copy of the original. During updates it’ll warn you to fix this code again.



Not sure yet how to allow the words to be in any order as this is the SQL where clause the above generates:


(descr1.search_words LIKE '%cheat%d20%') OR descr1.product LIKE '%cheat%d20%' OR descr1.short_description LIKE '%cheat%d20%' OR descr1.full_description LIKE '%cheat%d20%' OR (descr1.meta_keywords LIKE '%cheat%d20%' OR descr1.meta_description LIKE '%cheat%d20%' OR products.product_code LIKE '%cheat%d20%')




Which doesn’t find the “d20 cheat die”



James

http://www.RPGShop.com

Wow, works like a charm!!! Great. Thanks.

The Quick Search add-on in 2.1.2 includes an option for “search by product code”. In use, searches containing both a product code and other keywords work as expected. Oddly, the product code option still doesn’t exist in the standard search settings.



Glen

[quote name=‘gamegoblin’]Ok, they might have updated the code since the last time I was upset :slight_smile: Cause it seems by default it’s now using % at the beginning and end of the keywords… but still that’s not really the best solution as it doesn’t trim.



The function also doesn’t search product codes (model numbers) which my staff and some customers actually enjoy doing in our old software.



So I made two quick hacks that actually make the search more friendly to mistakes and gives the ability to search on product codes.



Just edit this file: /core/fn.catalog.php



Right under this line (about line 3520) in function fn_get_products():


foreach ($pieces as $piece) {




Add the line:


$piece = str_replace(' ', '%', trim($piece));




Then if you want to add the part to allow searching by product code (both in the ADMIN and by customers), then right below the line:



$tmp = db_quote(" (descr1.search_words LIKE ?l)", "%$piece%"); // check search words




add this new line:


$tmp .= db_quote(" OR (products.product_code LIKE ?l) ", "%$piece%");




Good luck and make sure you make a copy of the original. During updates it’ll warn you to fix this code again.



Not sure yet how to allow the words to be in any order as this is the SQL where clause the above generates:


(descr1.search_words LIKE '%cheat%d20%') OR descr1.product LIKE '%cheat%d20%' OR descr1.short_description LIKE '%cheat%d20%' OR descr1.full_description LIKE '%cheat%d20%' OR (descr1.meta_keywords LIKE '%cheat%d20%' OR descr1.meta_description LIKE '%cheat%d20%' OR products.product_code LIKE '%cheat%d20%')




Which doesn’t find the “d20 cheat die”



James

http://www.RPGShop.com[/QUOTE]



Thank you , Works :slight_smile:

in relation to this…has anyone figured out how to include product features in the main search?

I have “authors” and “ISBN” as a product feature and would like it to be searchable in the main search box.



I searched archives and didnt find one.



thanks!

hi guys, i don’t want to use the quick search addon. however i would like the search box to show the results if a user searches for even first and third keyword of my product name and also if the user searches for Item code it must display the particular product.



for example one of my products is Old Ford car parts. so if a user searches for old ford parts then it simply says no product found ! this is bad as i might end up loosing clients.



Please help!