Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Thinking Sphinx how to index the plusminus rank of Thumbs_up gem
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Mike C.  
View profile  
 More options Nov 7 2012, 2:19 pm
From: "Mike C." <corki...@gmail.com>
Date: Wed, 7 Nov 2012 11:19:09 -0800 (PST)
Local: Wed, Nov 7 2012 2:19 pm
Subject: Re: Thinking Sphinx how to index the plusminus rank of Thumbs_up gem

Thumbs_up generates a votes model:

class Vote < ActiveRecord::Base

  scope :for_voter, lambda { |*args| where(["voter_id = ? AND voter_type =
?", args.first.id, args.first.class.name]) }
  scope :for_voteable, lambda { |*args| where(["voteable_id = ? AND
voteable_type = ?", args.first.id, args.first.class.name]) }
  scope :recent, lambda { |*args| where(["created_at > ?", (args.first ||
2.weeks.ago)]) }
  scope :descending, order("created_at DESC")

  belongs_to :voteable, :polymorphic => true
  belongs_to :voter, :polymorphic => true

  attr_accessible :vote, :voter, :voteable

  # Comment out the line below to allow multiple votes per user.
  validates_uniqueness_of :voteable_id, :scope => [:voteable_type,
:voter_type, :voter_id]

end

and a vote migration containing:

create_table "votes", :force => true do |t|
  t.boolean  "vote",          :default => false
  t.integer  "voteable_id",                      :null => false
  t.string   "voteable_type",                    :null => false
  t.integer  "voter_id"
  t.string   "voter_type"
  t.datetime "created_at",                       :null => false
  t.datetime "updated_at",                       :null => false
end

I added this to my person model to filter by Most/Least amount of ratings:

has_many :votes, as: :voteable

define_index do

  has "COUNT(votes.id)", as: :rating, type: :integer  
  join votes

end

Although it isn't filtering the results by the number of votes that person
has correctly.

The other issue is figuring out how to index the Highest and Lowest Rating.
(AKA plusminus method in thumbs_up)

plusminus = (votes_for - votes_against)

votes_for is total votes that are equal to 1 for voteable_id and
voteable_type
votes_against is total votes that are equal to 0 for voteable_id and
voteable_type

Anyone able to make sense of this in sql for the attributes to index =)

On Monday, November 5, 2012 10:56:18 PM UTC-5, Mike C. wrote:

> Anyone have experience with indexing vote ranks with the Thumbs_up gem?<https://github.com/bouchard/thumbs_up>

> I'm trying to figure out these 4 attributes:

> has Highest Rating (the plusminus tally in gem) DESC
> has Lowest Rating (the plusminus tally in gem) ASC
> has Most Ratings (total amount of votes) DESC
> has Least Ratings (total amount of votes) ASC


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.