VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: guardiano78 on May 20, 2020, 22:01:35 PM

Title: searchable product fields
Post by: guardiano78 on May 20, 2020, 22:01:35 PM
Hello,
I'm having problems with the product search form.
The problem occurs both in the backend and in the frontend.

The searched terms are present in the product name, in the short description and in the extended description.

However the search result is empty (both in the backend and in the frontend).

Please see attached files.

Why?
could anyone give me an explanation?
Thanks.

Joomla 3.9.18 - VirtueMart 3.6.8 10197
Title: Re: searchable product fields
Post by: pinochico on May 20, 2020, 22:35:07 PM
if you use only micro, then search have right result.

I think your word order is wrong == does not match the order in the product name
Title: Re: searchable product fields
Post by: GJC Web Design on May 21, 2020, 00:10:03 AM
from memory the search will be  ->  LIKE %micro usb x25%

i.e. not an OR search

you haven't got a string like that
Title: Re: searchable product fields
Post by: guardiano78 on May 21, 2020, 15:08:08 PM
Hello,
thank you for the clarifications.
I thought VirtueMart looks for the presence of the terms officially searched by the order in which they are inserted as a search key.

something like this:

$search_key = explode(' ', 'micro usb x25');
$search_key_words = explode(' ', $search_key);
$query = "SELECT .... FROM ... WHERE ";
foreach ($search_key_words as $value)
{
    $query .= ".....'";
}


In your opinion is it possible to override default search query?
or do you not recommend it?

Thank you!!


Title: Re: searchable product fields
Post by: GJC Web Design on May 21, 2020, 18:57:05 PM
it is possible but not for the faint hearted..  ;)

the function is function sortSearchListQuery() in the products model

around line 369

      if (!empty($this->keyword) and $group === FALSE) {

         $keyword = vRequest::filter(html_entity_decode($this->keyword, ENT_QUOTES, "UTF-8"),FILTER_SANITIZE_STRING,FILTER_FLAG_ENCODE_LOW);
         $keyword = $db->escape( $keyword, true );
         $keyword =  '"%' .str_replace(array(' '),'%', $keyword). '%"';

there is a plugin trigger further down that can alter the query but I haven't experimented with this for years

      if ($this->searchplugin !== 0) {
         JPluginHelper::importPlugin('vmcustom');
         $dispatcher = JDispatcher::getInstance();
         $dispatcher->trigger('plgVmBeforeProductSearch', array(&$select, &$joinedTables, &$where, &$groupBy, &$orderBy,&$joinLang));
      }
Title: Re: searchable product fields
Post by: guardiano78 on May 29, 2020, 11:05:48 AM
Hello,

thanks for the suggestion.
I think I'll leave it as it is :)