Anyone have experience with indexing vote ranks with the Thumbs_up gem?
I'm trying to figure out these 4 attributes:
has Highest Rating (the plusminus tally in gem) DESChas Lowest Rating (the plusminus tally in gem) ASChas Most Ratings (total amount of votes) DESC
has Least Ratings (total amount of votes) ASC
As for highest/lowest rating, this should do the trick:
has "SUM(CASE vote WHEN TRUE THEN 1.0 ELSE -1.0 END)", :as => :plusminus, :type => :float
It's important to note that Sphinx integer attributes are unsigned, so you wouldn't get totals less than zero working properly - hence using floats instead. If you're using MySQL, then you can use an IF function instead, or stick with the case change TRUE to 1.
Anything else you're still stuck on? Sorry I've been slow to respond, things have been flat out here.
--
Pat
> --
> You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/thinking-sphinx/-/SDTFBQML9nQJ.
> To post to this group, send email to thinkin...@googlegroups.com.
> To unsubscribe from this group, send email to thinking-sphi...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/thinking-sphinx?hl=en.
Thanks much for the response! You're right I removed the vote_ids attribute and also the has_many association since it seems the association is added with the acts_as_voteable call on the top of model and the votes are still working fine for Most amount of ratings and Least amount of ratings.
Although I haven't had luck yet with:
has "SUM(CASE vote WHEN TRUE THEN 1.0 ELSE -1.0 END)", :as => :plusminus, :type => :float
It seems like it should work the way you have it, although when I filter the results it doesn't show the top rated results.
I get something like this:
Person1 Person2 Person3 Person4
+5 +1 +2 +8
Instead of:
Person4 Person1 Person3 Person2
+8 +5 +2 +1
(Think I used a different email for the response and it wasn't showing up on the board so reposting it here.)
--
Pat
> To view this discussion on the web visit https://groups.google.com/d/msg/thinking-sphinx/-/oX6u-2OOl8EJ.
Can you share with us your full index definition?
Cheers
--
Pat
On 07/12/2012, at 5:20 AM, Mike C. wrote:
> Also, when I filter :order => "plusminus ASC"
>
> I added some down votes to 3 users. It did put those three users to the top of the results, the problem is that the order of those 3 results is wrong. It is showing up as the order I voted on them -1, -2, -2 (-1 being the last user I voted on)
>
> --
> You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/thinking-sphinx/-/ZACphJWXKDIJ.
If that's the case, then things will be tricky… I'd imagine you'd need to have an association each for positive and negative votes (add a condition on the vote column), and then use the count of distinct votes.id to figure out the value…
has_many :positive_votes, :class_name => 'Vote', :conditions => {:vote => true}
has_many :negative_votes, :class_name => 'Vote', :conditions => {:vote => false}
has "CAST(COUNT(DISTINCT positive_votes.id) - COUNT(DISTINCT negative_votes.id)) as float",
:as => :rating, :type => :float
join positive_votes
join negative_votes
I'm not entirely sure of that logic - and the join table aliases may be something other than positive_votes and negative_votes. In short: a bit of trial and error will be required.
Cheers
--
Pat
> To view this discussion on the web visit https://groups.google.com/d/msg/thinking-sphinx/-/ESfL1edDbL4J.
> OR
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/thinking-sphinx/-/0JjKshHjjoUJ.