VirtueMart Forum

VirtueMart 1.1.x [ Old version - no longer supported ] => Mambots, Plugins VM 1.1 => Topic started by: bobop on August 31, 2008, 19:47:07 pm

Title: Duplicate search results when multiple categories are used
Post by: bobop on August 31, 2008, 19:47:07 pm
Hi everybody, i've been searching for a solution in the last few days but i havent figured out any.

Heres my problem:

Im using VM 1.1.2 on Joomla 1.5 and i installed the search plugin. My products belong to many categories and so when i search for anything the same product appear for each category. I would like to know if there's a way to avoid this and only show it once (any category will do)

Thanks
Title: Re: Duplicate search results when multiple categories are used
Post by: Lee Wilson on September 08, 2008, 16:08:28 pm
I have the exact same problem but on J1.0.15 and VM 1.0.15.

There really is no need to duplicate the same product ID for listings in multiple categories.

Any ideas how to over come this ?
Title: Re: Duplicate search results when multiple categories are used
Post by: ncase on September 12, 2008, 03:41:25 am
Just want to give this thread a bump.
Same problem using J! 1.5.3 and VM 1.1.2

Multi category products are unwantedly listed multiple times in search.
Title: Re: Duplicate search results when multiple categories are used
Post by: racex on September 18, 2008, 15:29:14 pm
Hi boys,
I have the same problem/bug.

Anyone has solved it?
Title: Re: Duplicate search results when multiple categories are used
Post by: pandorra on September 23, 2008, 00:25:47 am
Same Problem... > using VM 1.1.2, Joomla 1.5...
Title: Re: Duplicate search results when multiple categories are used
Post by: racex on September 23, 2008, 08:25:37 am
In the italian community's forum there is a solution to this problem (not yet tested...)

Please see here http://forum.vmitalia.net/index.php/topic,1893.msg9553.html#msg9553 (http://forum.vmitalia.net/index.php/topic,1893.msg9553.html#msg9553)

bye
Title: Re: Duplicate search results when multiple categories are used
Post by: brandonjp on October 27, 2008, 00:01:14 am
In the italian community's forum there is a solution to this problem (not yet tested...)
Please see here http://forum.vmitalia.net/index.php/topic,1893.msg9553.html#msg9553 (http://forum.vmitalia.net/index.php/topic,1893.msg9553.html#msg9553)
bye

THANKS racex!  IT WORKS!!  I did a google translate on the link you provided (http://tinyurl.com/56ljqw) .  Here's the gist of it...

 - Open the file: JOOMLA ROOT/plugins/search/vmxsearch.plugin.php
 - Find this line...  (for me it was around line 184)
Code: [Select]
pg_keydenseSort( $row, 'count', 'DESC' ) ;

- Just before that line add the following:

Code: [Select]
//GOOSEFISH  - fix duplicate search results from multiple VM categories - http://tinyurl.com/5sde5c
$aid=array();
$rownew=array();
foreach( $row as $result ) {
if (!array_key_exists ( $result->product_id, $aid))
{
$aid[$result->product_id]=$result->product_id;
array_push($rownew, $result);
}
}
$row=$rownew;
//END GOOSEFISH

**Note:  This hacks your actual Joomla search feature, not just VirtueMart product search, so take that into consideration.  Some users mentioned that this hack seems to only use the product with the lowest product_id, so if you have two products with the same PRODUCT_NAME then some actual search results are accidentally omitted.  For my shop, this did not matter, but for some this could pose greater issues.
Title: Re: Duplicate search results when multiple categories are used
Post by: Michael on November 08, 2008, 23:29:30 pm
Her is another solution that only involves changing vmxsearch.plugin.php

on line 147 change

Code: [Select]
$query = "SELECT DISTINCT p.product_id, p.product_name as title,
to

Code: [Select]
$query = "SELECT DISTINCT p.product_id, count(*) as n, p.product_name as title,
Then after line 163 which is

Code: [Select]
$oos_where
insert

Code: [Select]
group by p.product_id
having  n > 1

Save the file, upload it back to your server replacing the old file and now the search results will only return one listing for each product. (thanks to http://webxadmin.free.fr/article.php?i=74 (http://webxadmin.free.fr/article.php?i=74) for the sql hint that solved this problem.)
Title: Re: Duplicate search results when multiple categories are used
Post by: Michael on November 08, 2008, 23:39:36 pm
also if you want to add a checkbox to filter search results to just products insert the the following code after line 26 in vmxsearch.plugin.php which reads

Code: [Select]
$mainframe->registerEvent( 'onSearch', 'vmExtendedSearch' ) ;
add

Code: [Select]
$mainframe->registerEvent( 'onSearchAreas', 'vmExtendedSearchAreas' );


function &vmExtendedSearchAreas() {
static $areas = array(
'vmxsearch' => 'Products'
);
return $areas;
}


You can change the word 'Products' to whatever you want it to be or create a language define if you need multiple languages.
Title: Re: Duplicate search results when multiple categories are used
Post by: clabbers on February 06, 2009, 12:32:59 pm
I deleted next code in the VM extended plug-in because this caused me errors (begins on line 190):
Code: [Select]
function pg_keydenseSort( &$data, $key, $order ) {
for( $i = count( $data ) - 1 ; $i >= 0 ; $i -- ) {
$swapped = false ;
for( $j = 0 ; $j < $i ; $j ++ ) {
if( $order == 'ASC' ) {
if( $data[$j]->$key > $data[$j + 1]->$key ) {
$tmp = $data[$j] ;
$data[$j] = $data[$j + 1] ;
$data[$j + 1] = $tmp ;
$swapped = true ;
}
} else {
if( $data[$j]->$key < $data[$j + 1]->$key ) {
$tmp = $data[$j] ;
$data[$j] = $data[$j + 1] ;
$data[$j + 1] = $tmp ;
$swapped = true ;
}
}

}
if( ! $swapped )
return ;
}
}

Now the plugin works great!


Title: Re: Duplicate search results when multiple categories are used
Post by: Lee Wilson on May 22, 2009, 10:51:31 am
Fantastic,

Just what I was after and should be included in VM if you ask me !
Title: Re: Duplicate search results when multiple categories are used
Post by: HulaQueen on June 12, 2009, 00:02:03 am
Thank you so much Michael,

This was EXACTLY what I needed and it was such a quick easy solution. THANK YOU!!!!!
Title: Re: Duplicate search results when multiple categories are used
Post by: slakalot on July 08, 2009, 17:26:38 pm
Thanks Michael, this sorted the multiple category products out, but I need to return results from one category only (I have two categories set up, one for public, one for restricted, which have the exact same products in them. They use separate flypages for one to show documents for restricted users that the public cannot see. When I search, it returns either the public or restricted flypage and I cannot limit the search to one flypage/category only... So I have had to turn the search mod off entirely to avoid the public seeing restricted content. (Hope that makes sense!))

SO I guess what I'm asking is - how can I restrict the search to one category only? Or make it display on a particular flypage only if I cannot determine the category? I have been searching for a solution for a while and can't seem to find an answer so any ideas would be appreciated...
Title: Re: Duplicate search results when multiple categories are used
Post by: sdebaun on October 05, 2010, 00:23:25 am
This should definitely be part of the core VM files...
Title: Re: Duplicate search results when multiple categories are used
Post by: crazihel on November 23, 2011, 20:50:57 pm
Sorry to post in a topic so long after the original, but I am having duplicate search result problems & I used Michael's code to try sort it which did stop the products duplicating, but it also seems to mess with the parameters a bit, as a few products are now unsearchable & do not appear in the results. When I took the code out again, they reappeared in the results...as did all the duplicates. Can anyone suggest why this is? Thanks in advance!
Title: Re: Duplicate search results when multiple categories are used
Post by: pm4698 on May 23, 2015, 20:52:43 pm
Any solution for vm 2.6.10?