News:

Support the VirtueMart project and become a member

Main Menu

Search two or more words [SOLVED]

Started by lopezalejandro, May 22, 2012, 14:42:21 PM

Previous topic - Next topic

lopezalejandro

Hi Max!
Thanks for add this!!:
http://forum.virtuemart.net/index.php?topic=101724.0

Whe have another similar problem with the searches.
When we search two or more words it only find results if the words are exacly

Example:
- Search "Sony Vaio" found "Sony Vaio YB3V1E"
- Search "Sony YB3V1E" found nothing!! Because this mach don't are exactly in the product name,  the product name is "Sony Vaio YB3V1E"

We repaired quickly:
in the file administrator/components/com_virtuemart/models/product.php in line 222 aprox.
replace:
$filter_search[] = '`'.$searchField.'` LIKE '.$keyword;
by:
$keywords_plural = preg_replace('/\s+/', '%" AND `'.$searchField.'` LIKE "%', $keyword);
$filter_search[] = '`'.$searchField.'` LIKE '.$keywords_plural;

It's a little reparation, we replace blank space with searchfield:
Array of search fields before:
Array
(
   

       
  • => `product_name` LIKE "%asus network%"
  • [1] => `product_sku` LIKE "%asus network%"
        [2] => `product_s_desc` LIKE "%asus network%"
        [3] => `category_name` LIKE "%asus network%"
        [4] => `mf_name` LIKE "%asus network%"
    )
Array of seach fields after:
Array
(

       
  • => `product_name` LIKE "%asus%" AND `product_name` LIKE "%network%"
  • [1] => `product_sku` LIKE "%asus%" AND `product_sku` LIKE "%network%"
        [2] => `product_s_desc` LIKE "%asus%" AND `product_s_desc` LIKE "%network%"
        [3] => `category_name` LIKE "%asus%" AND `category_name` LIKE "%network%"
        [4] => `mf_name` LIKE "%asus%" AND `mf_name` LIKE "%network%"
    )
Thanks!!
Alejandro López
Grupo Odín Soluciones Informáticas
http://grupoodin.es

alexdixondesign

Very helpful mate, I thought I'd broke it when hacking other parts of the system.

I also trimmed the "\modules\mod_virtuemart_search\tmpl\default.php" file so the SEF URL displayed nicer.

For example - www.example.com/store/search?keyword=2012+AX+PRO


<?php // no direct access
defined('_JEXEC') or die('Restricted access'); ?>

<!--BEGIN Search Box -->
<form action="<?php echo JRoute::_('index.php?option=com_virtuemart&view=category&search=true&virtuemart_category_id='.$category_id ); ?>" method="get">
<div class="search<?php echo $params->get('moduleclass_sfx'); ?>">
<?php $output '<input style="height:16px;vertical-align :middle;" name="keyword" id="mod_virtuemart_search" maxlength="'.$maxlength.'" alt="'.$button_text.'" class="inputbox'.$moduleclass_sfx.'" type="text" size="'.$width.'" value="'.$text.'"  onblur="if(this.value==\'\') this.value=\''.$text.'\';" onfocus="if(this.value==\''.$text.'\') this.value=\'\';" />'
 
$image JURI::base().'components/com_virtuemart/assets/images/vmgeneral/search.png' ;
 

if ($button) :
    if ($imagebutton) :
        $button '<input type="image" value="'.$button_text.'" class="button'.$moduleclass_sfx.'" src="'.$image.'" onclick="this.form.keyword.focus();"/>';
    else :
        $button '<input type="submit" value="'.$button_text.'" class="button'.$moduleclass_sfx.'" onclick="this.form.keyword.focus();"/>';
    endif;
endif;


echo $output;
?>

</div>
  </form>

<!-- End Search Box -->

Milbo

Idea taken, sorry that we did not add it so long time, but some good member showed me this thread. thanks guys, will be in vm2.0.16 and vm2.1
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

jillymot

Hi Milbo

Could you please also take a look at the following?

I have noticed that the Virtuemart Search Product module generally works when inputting the search while on a non-virtuemart page, i.e. on a Joomla article page.  I input the search words and it produces the expected result, returning results from multiple categories if the criteria is met.  If, however, I am on a virtuemart category layout page, the expected result will only be returned if I am on the category layout page that product is in, i.e. the product search filters only on that category.  If I try the same search while I am on another category page, it will return a 0 result.  This occurs whether Search Filter Category setting in the module is set to Yes or No - it makes no difference.

Would be great to be able to fix this, as the Virtuemart Search Product results look better than using the standard Joomla search module.

I am using Joomla 2.5.8 Virtuemart 2.0.12b

For example, refer to www.positiveimpact.net.au

From home page enter "oggi" in the Product Search on left.  Two results will be returned.  However if you go to Books category on left and perform same search from there, no results are returned.  I do not wish to limit search just to current category page.

Hope you can help.


nevan

I'm having the same type of problem. Not sure what has happened but my search results are now limited to the category you are in. The Search use to interrogate the entire product database.
Industry Surplus Australia
Perth, Australia

PRO

the search module settings have a "category filter" option.

Turn it off

jillymot

Yes PRO, as I explained in my post I have already tried changing the Search Filter Category option in the module to No, but it is still filtering on the category.  Only if I click onto a Joomla content page (rather than a Virtuemart Category Page) and submit the search am I able to get the correct result.

I do not think the Search Filter Category option in the module is working as it should.

furbino

Quote from: lopezalejandro on May 22, 2012, 14:42:21 PM
Hi Max!
Thanks for add this!!:
http://forum.virtuemart.net/index.php?topic=101724.0

Whe have another similar problem with the searches.
When we search two or more words it only find results if the words are exacly

Example:
- Search "Sony Vaio" found "Sony Vaio YB3V1E"
- Search "Sony YB3V1E" found nothing!! Because this mach don't are exactly in the product name,  the product name is "Sony Vaio YB3V1E"

We repaired quickly:
in the file administrator/components/com_virtuemart/models/product.php in line 222 aprox.
replace:
$filter_search[] = '`'.$searchField.'` LIKE '.$keyword;
by:
$keywords_plural = preg_replace('/\s+/', '%" AND `'.$searchField.'` LIKE "%', $keyword);
$filter_search[] = '`'.$searchField.'` LIKE '.$keywords_plural;

Hi there,
I have the same problem with the site of a friend, multiple search doesn't work if there isn't the exact sequential order of the searched words. I changed the product.php as above suggested but I'm unable to find  what is suggested to be repaired below. Any suggestion will be appreciated.
thanks alot.




Quote from: lopezalejandro on May 22, 2012, 14:42:21 PM
It's a little reparation, we replace blank space with searchfield:
Array of search fields before:
Array
(
   

       
  • => `product_name` LIKE "%asus network%"
  • [1] => `product_sku` LIKE "%asus network%"
        [2] => `product_s_desc` LIKE "%asus network%"
        [3] => `category_name` LIKE "%asus network%"
        [4] => `mf_name` LIKE "%asus network%"
    )
Array of seach fields after:
Array
(

       
  • => `product_name` LIKE "%asus%" AND `product_name` LIKE "%network%"
  • [1] => `product_sku` LIKE "%asus%" AND `product_sku` LIKE "%network%"
        [2] => `product_s_desc` LIKE "%asus%" AND `product_s_desc` LIKE "%network%"
        [3] => `category_name` LIKE "%asus%" AND `category_name` LIKE "%network%"
        [4] => `mf_name` LIKE "%asus%" AND `mf_name` LIKE "%network%"
    )
Thanks!!

kittmaster

Quote from: lopezalejandro on May 22, 2012, 14:42:21 PM
Hi Max!
Thanks for add this!!:
http://forum.virtuemart.net/index.php?topic=101724.0

Whe have another similar problem with the searches.
When we search two or more words it only find results if the words are exacly

Example:
- Search "Sony Vaio" found "Sony Vaio YB3V1E"
- Search "Sony YB3V1E" found nothing!! Because this mach don't are exactly in the product name,  the product name is "Sony Vaio YB3V1E"

We repaired quickly:
in the file administrator/components/com_virtuemart/models/product.php in line 222 aprox.
replace:
$filter_search[] = '`'.$searchField.'` LIKE '.$keyword;
by:
$keywords_plural = preg_replace('/\s+/', '%" AND `'.$searchField.'` LIKE "%', $keyword);
$filter_search[] = '`'.$searchField.'` LIKE '.$keywords_plural;

It's a little reparation, we replace blank space with searchfield:
Array of search fields before:
Array
(
   

       
  • => `product_name` LIKE "%asus network%"
  • [1] => `product_sku` LIKE "%asus network%"
        [2] => `product_s_desc` LIKE "%asus network%"
        [3] => `category_name` LIKE "%asus network%"
        [4] => `mf_name` LIKE "%asus network%"
    )
Array of seach fields after:
Array
(

       
  • => `product_name` LIKE "%asus%" AND `product_name` LIKE "%network%"
  • [1] => `product_sku` LIKE "%asus%" AND `product_sku` LIKE "%network%"
        [2] => `product_s_desc` LIKE "%asus%" AND `product_s_desc` LIKE "%network%"
        [3] => `category_name` LIKE "%asus%" AND `category_name` LIKE "%network%"
        [4] => `mf_name` LIKE "%asus%" AND `mf_name` LIKE "%network%"
    )
Thanks!!

This also works perfectly to look for partial strings of products and in my case song searching within the entire website.......well done and thank you!

usermee

Hi, I too am having a similar problem with the search (which has been "fixed" with the code here).

Let's say for instance the product name is "Alan Wake (xbox 360)" and you search for say:

alan wake xbox 360

It will find the product, however, if you now change the order of those words to say:

xbox 360 alan wake or any other variance it will not find the product and return "zero" results.

Anything I can do to fix this problem?

Thanks.

TeeJay.net

Quote from: usermee on September 16, 2013, 23:24:06 PM
Hi, I too am having a similar problem with the search (which has been "fixed" with the code here).

Let's say for instance the product name is "Alan Wake (xbox 360)" and you search for say:

alan wake xbox 360

It will find the product, however, if you now change the order of those words to say:

xbox 360 alan wake or any other variance it will not find the product and return "zero" results.

Anything I can do to fix this problem?

Thanks.

Hi, this problem is still up-to-date. Any information how to fix such issue? The same trouble applies to anything... looking for "red handbag" and "handbag red" goes for totally different search results.
Any help would be appreciated :) Thank you

usermee

Hi there, unfortunately not, I have not had the time to delve into the files to try and fix this. I believe it is your template replacing one of the core search files which is buggy, so what I need to do is go through each template replacement file and swap it out with the original one and see if that works, I am guessing this is what you will need to do as well.

TeeJay.net

Quote from: usermee on January 23, 2014, 09:51:28 AM
Hi there, unfortunately not, I have not had the time to delve into the files to try and fix this. I believe it is your template replacing one of the core search files which is buggy, so what I need to do is go through each template replacement file and swap it out with the original one and see if that works, I am guessing this is what you will need to do as well.

It's definitely not my template. I tried like 5 search modules to test if any of them would work as expected - none of them did. Not only on my site, but on demo webpages of the paid modules as well.

How is this even possible? It worked well on VM1, I have tried it today. You have Apple MacBook in your store, a client types "MacBook Apple" and it won't find anything. Like seriously? Only Joomla search (mod_search) works well for this purpose as well, but it has not the category view layout.

Milbo

Quote from: usermee on September 16, 2013, 23:24:06 PM
Let's say for instance the product name is "Alan Wake (xbox 360)" and you search for say:

alan wake xbox 360

It will find the product, however, if you now change the order of those words to say:

xbox 360 alan wake or any other variance it will not find the product and return "zero" results.

Interesting. We are open for suggestions.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

balai

I think that the solution is the joomla's finder. It just needs a plug-in for Virtuemart.

This is exactly what finder does.

It splits the various fields to words and gives a weight to each word. So the results depend on the used words and their weight rather than thei order