What happens if you remove the comments and tag references? I think it may be a 
case of the other joins increasing the number of records, and thus vote counts 
are increased for some records.

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

On 08/12/2012, at 2:42 AM, Mike C. wrote:

> #PERSON MODEL
> 
> define_index do
>   indexes name
>   indexes tag_taggings.tag(:name), as: :tags
>   has :id
>   has view_count, as: :impressions
>   has "COUNT(comments.id)", as: :reviews, type: :integer
>   has "COUNT(DISTINCT votes.id)", as: :rating_count, type: :integer
>   has "SUM(CASE votes.vote WHEN TRUE THEN 1.0 ELSE -1.0 END)", as: :rating, 
> type: :float
>   has "RADIANS(lat)", as: :lat, type: :float
>   has "RADIANS(lng)", as: :lng, type: :float
>   has created_at, updated_at
>   group_by "lat", "lng"
>   join comments
>   join votes
> end
> 
> #PERSON CONTROLLER
> 
> conditions = {}
> %w(name tags).each do |i|
>   i = i.to_sym
>   next unless params[i]
>   conditions[i] = params[i]
> end
>       
> #SORT RATINGS
> if params[:o] == "rate_desc"
>   order_by = "rating DESC"
> elsif params[:o] == "rate_asc"
>   order_by = "rating ASC"
> elsif params[:o] == "rate_count_desc"
>   order_by = "rating_count DESC"
> elsif params[:o] == "rate_count_asc"
>   order_by = "rating_count ASC"
>       
> #SORT REVIEWS
> elsif params[:o] == "reviews_desc"
>   order_by = "reviews DESC"
> elsif params[:o] == "reviews_asc"
>   order_by = "reviews ASC"
> 
> #SORT VIEWS
> elsif params[:o] == "views_desc"
>   order_by = "impressions DESC"
> elsif params[:o] == "views_asc"
>   order_by = "impressions ASC"
> 
> #SORT TIME
> elsif params[:o] == "day"
>   filters = { :created_at => 1.day.ago..Time.now }
>   order_by = "created_at DESC"
> elsif params[:o] == "week"
>   filters = { :created_at => 1.week.ago..Time.now }
>   order_by = "created_at DESC"
> elsif params[:o] == "month"
>   filters = { :created_at => 1.month.ago..Time.now }
>   order_by = "created_at DESC"
> elsif params[:o] == "year"
>   filters = { :created_at => 1.year.ago..Time.now }
>   order_by = "created_at DESC"
> else
>   order_by = "created_at DESC"
> end
> 
> #SEARCH IT!
> p = Person.search(params[:q], :conditions => conditions, :order => order_by, 
> :with => filters, :per_page => 9999999)
> 
> On Friday, December 7, 2012 5:32:59 AM UTC-5, Pat Allan wrote:
> Hi Mike
> 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.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to 
> > [email protected].
> > For more options, visit this group at 
> > http://groups.google.com/group/thinking-sphinx?hl=en.
> 
> 
> 
> 
> 
> 
> 
> 
> -- 
> 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/-/ESfL1edDbL4J.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/thinking-sphinx?hl=en.

 

-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/thinking-sphinx?hl=en.

Reply via email to