News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

VM Search module - very poor search results

Started by taro8, October 19, 2018, 09:46:54 AM

Previous topic - Next topic

taro8

VirtueMart 3.4.2

Hello, I'm making a simple shop using VM and I have a big issue with the search module. Basically it only works if you know exactly what to look for. I have the lorem ipsum placeholder text put into the descriptions and I look for lorem ipsum it displays all of the products with that placeholder description, but if I search for ipsum lorem I get no results at all. Similar thing with product names: searching for a gaming laptop shows me the product with that name, but laptop gaming returns no results.

In short the search module is kinda not useful at all.

I operate on no budget at all so buying any commercial search solution is kinda out of my reach as well I have no idea if it will actually work.

Is there any way to fix the search code so it looks for each word separately?

GJC Web Design

you would need to alter the code in the function sortSearchListQuery() in the
if (!empty($this->keyword) and $group === FALSE) {
section or make use of the plugin trigger in that function to alter your query

      if ($this->searchplugin !== 0) {
         JPluginHelper::importPlugin('vmcustom');
         $dispatcher = JDispatcher::getInstance();
         $dispatcher->trigger('plgVmBeforeProductSearch', array(&$select, &$joinedTables, &$where, &$groupBy, &$orderBy,&$joinLang));
      }
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

taro8

I have found this thread and followed the solution.

http://forum.virtuemart.net/index.php?topic=129146.0

And added
$keyword = preg_replace('/%/', ' ', $keyword); at the line 393 (as of 3.42) in administrator / components / com_virtuemart / models / product.php so I get something like this:

if($prodLangFB){
$fields = self::joinLangLikeField($searchField,$keyword);
vmdebug('my search fields',$fields);
$filter_search = array_merge($filter_search, $fields);
$keyword = preg_replace('/%/', ' ', $keyword); // Added bit
} else {
if (strpos ($searchField, '`') !== FALSE){
$keywords_plural = preg_replace('/\s+/', '%" AND '.$searchField.' LIKE "%', $keyword);
$filter_search[] =  $searchField . ' LIKE ' . $keywords_plural;
} else {
$keywords_plural = preg_replace('/\s+/', '%" AND `'.$searchField.'` LIKE "%', $keyword);
$filter_search[] = '`'.$searchField.'` LIKE '.$keywords_plural;
}
}


I partially works as now it searches for separate words. The issue is that it only does that for the product description. Also it does not seem to look for words in description, name etc. at the same time. ie. if I look for gaming laptop, hit, laptop gaming, hit (Gaming laptop is the product name), but if I look for laptop lorem, then I get no hits (it has lorem ipsum description). Now if I put the product name into the description the search, then it will pick the name up and lets you search for the mixed words.

It would be nice if search engine actually treated the name, descriptions, manofacturers, etc. as a whole and return hits even if words are spread between the fields.

GJC Web Design

#3
depends what fields u have chosen to search in via the admin surely

ah .. see what u mean -- field x has game, field y has lorum -- both returned.. 

code away..   ;)

as I say .. there is a plugin trigger that in theory can fully adjust the query to what ever u want ( though have never tried)
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Studio 42

TO achieve this you have to do a SQL like per word
code  example
$keywords = explode(' ',$keyword);
foreach($keywords as $word) {
$filter_search[] = '`'.$searchField.'` LIKE '.$word;
}

It's only theorical, but it permit to hit for this search "Gaming laptop":
Gaming or laptop in all $searchField
But of course he find any so you can have false returned and too many results.

Another solution is to revert words so it search for "Gaming laptop" and "laptop Gaming"
$keywords = explode(' ',$keyword);
$reversed = implode(' ',array_reverse($keywords );
$filter_search[] = '`'.$searchField.'` LIKE '.$keyword;
$filter_search[] = '`'.$searchField.'` LIKE '.$reversed;


taro8

#5
Ok it seems that the fix I mentioned earlier only applies to the description. The search through product name still does not work correctly.  :(

EDIT: ok seems that adding another $keyword = preg_replace('/%/', ' ', $keyword); at line 373 fixed the product name search somehow.

There is a still an issue with VM search not returning hits on a product that has all the searched words, but spread out across different fields like this:

Product Name: Gaming Laptop
Manofacturer: Macrohard
Short Product description: Stuff
Product Description: Lorem ipsum

Now if you search, even with the fix, for something like Laptop Macrohard Stuff ipsum you will NOT get a hit on that product, simply because the words are from different fields. If the all of the words were in one filed, like the description for example, then you will get search hit.

Studio 42

See my code  example ho you can search for all words.
Of course it need some changes to add in in the real code