Sort search results by votes

Register an Account
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 06-27-2009, 09:49 PM
New Pligger
 
Join Date: Jul 2008
Posts: 21
Does anyone know of a way to sort search results by the number of votes? For a given tag, I'd like the story with the most votes to show up on the top of the search results page.

In libs/search.php I changed

$sortarray[$thelink['link_id']] = $thelink['link_date'];
}
asort($sortarray);

to

$sortarray[$thelink['link_id']] = $thelink['link_votes'];
}
asort($sortarray);

That almost did it. The list is reversed, though -- the story with the most votes is the last result. I tried changing "asort" to "arsort" but that didn't change anything. Any ideas?

Last edited by phrankle; 06-27-2009 at 09:54 PM.
Reply With Quote
  #2 (permalink)  
Old 07-05-2009, 04:10 PM
New Pligger
 
Join Date: Jul 2008
Posts: 21
No thoughts? I'm using 9.9.5, by the way.
Reply With Quote
  #3 (permalink)  
Old 07-13-2009, 06:01 PM
Constant Pligger
 
Join Date: Jan 2009
Posts: 223
Any idea on this? I would like to know as well?
Reply With Quote
  #4 (permalink)  
Old 07-13-2009, 06:06 PM
cmstheme's Avatar
Donor/Coder
Pligg Version: 9.9
Pligg Template: Squaretle
 
Join Date: Jan 2007
Location: Philippines
Posts: 528
Open /libs/search.php and find around LINE 178:
PHP Code:
asort($sortarray); 
then replace with:
PHP Code:
arsort($sortarray); 
References:
PHP: asort - Manual
PHP: arsort - Manual
Reply With Quote
  #5 (permalink)  
Old 07-13-2009, 06:31 PM
Constant Pligger
 
Join Date: Jan 2009
Posts: 223
Thank you Cmstheme :-)
Reply With Quote
  #6 (permalink)  
Old 07-19-2009, 02:51 PM
New Pligger
 
Join Date: Jul 2008
Posts: 21
Quote:
Originally Posted by cmstheme View Post
Open /libs/search.php and find around LINE 178:
PHP Code:
asort($sortarray); 
then replace with:
PHP Code:
arsort($sortarray); 
References:
PHP: asort - Manual
PHP: arsort - Manual
Thanks for the response, but that unfortunately didn't work for me. As I wrote in my original post, I've already tried it.

Changing "asort" to "arsort" only affects the order when I'm using

$sortarray[$thelink['link_id']] = $thelink['link_date'];
}

when I use

$sortarray[$thelink['link_id']] = $thelink['link_votes'];
}

(when I'm sorting by vote number instead of date)

it doesn't do anything.

Last edited by phrankle; 07-19-2009 at 03:00 PM.
Reply With Quote
  #7 (permalink)  
Old 07-20-2009, 07:09 AM
cmstheme's Avatar
Donor/Coder
Pligg Version: 9.9
Pligg Template: Squaretle
 
Join Date: Jan 2007
Location: Philippines
Posts: 528
My previous post was for Pligg Beta 9.9.5 and for date sort only.

Here's how to sort search results (by standard search or by tags) by votes on Pligg 1.0.0. The file to be edit is /libs/search.php

Find:
PHP Code:
$this->sql "SELECT link_id, link_date, link_published_date $from_where $search_clause "
replace with:
PHP Code:
$this->sql "SELECT link_id, link_date, link_published_date, link_votes $from_where $search_clause "




Find the two (2) instances of:
PHP Code:
$newfoundlinks[$link_id->link_id]['link_id'] = $link_id->link_id
below that, add:
PHP Code:
$newfoundlinks[$link_id->link_id]['link_votes'] = $link_id->link_votes




Find:
PHP Code:
$sortarray[$thelink['link_id']] = $thelink['link_date']; 
replace with:
PHP Code:
$sortarray[$thelink['link_id']] = $thelink['link_votes']; 
In Pligg 1.0.0, the search search results are already ordered in reverse order, thus no need to change the asort/arsort thing.
Reply With Quote
  #8 (permalink)  
Old 07-28-2009, 02:53 PM
New Pligger
 
Join Date: Jul 2008
Posts: 21
Amazing! Thank you so much.
Reply With Quote
Reply

Tags
search, sort

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Let the user sort the search results by different ways? Niko Questions and Comments 0 11-17-2007 04:49 AM
Search Yields Too Many Results mitchb13 Questions and Comments 0 04-02-2007 03:40 PM
Search Results - all stories canadapc Questions and Comments 2 08-08-2006 05:40 PM
Search: No Results konakevin Questions and Comments 21 07-06-2006 02:12 AM


Pligg Modules and Pligg Templates from Pligg Pro Find support on the Pligg CMS Forum - 24 hours a day! Make a donation to support Pligg CMS development