Author Topic: VM Search module - very poor search results  (Read 1246 times)

taro8

  • Beginner
  • *
  • Posts: 3
  • A beginner
VM Search module - very poor search results
« on: October 19, 2018, 09:46:54 am »
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

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 8828
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 2.6.22 & 3.2.14
Re: VM Search module - very poor search results
« Reply #1 on: October 19, 2018, 10:39:47 am »
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 http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

taro8

  • Beginner
  • *
  • Posts: 3
  • A beginner
Re: VM Search module - very poor search results
« Reply #2 on: October 19, 2018, 11:27:48 am »
I have found this thread and followed the solution.

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

And added
Code: [Select]
$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:

Code: [Select]
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

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 8828
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 2.6.22 & 3.2.14
Re: VM Search module - very poor search results
« Reply #3 on: October 19, 2018, 11:30:03 am »
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 http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 3678
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: VM Search module - very poor search results
« Reply #4 on: October 19, 2018, 11:54:26 am »
TO achieve this you have to do a SQL like per word
code  example
Code: [Select]
$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"
Code: [Select]
$keywords = explode(' ',$keyword);
$reversed = implode(' ',array_reverse($keywords );
$filter_search[] = '`'.$searchField.'` LIKE '.$keyword;
$filter_search[] = '`'.$searchField.'` LIKE '.$reversed;

taro8

  • Beginner
  • *
  • Posts: 3
  • A beginner
Re: VM Search module - very poor search results
« Reply #5 on: October 19, 2018, 12:17:42 pm »
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
Code: [Select]
$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

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 3678
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: VM Search module - very poor search results
« Reply #6 on: October 19, 2018, 12:56:03 pm »
See my code  example ho you can search for all words.
Of course it need some changes to add in in the real code