Suggestions within context below:

On 15/10/2008, at 6:38 AM, Leximo wrote:

> I'm a ruby and sphinx newb, and I'm having some trouble sorting using
> integers.
>
> I have a words table that keeps track of the total votes for a word.
> However, I can't seem to sort it by votes. This is what I have so far:
>
> # In words controller
>
> def search
>       @words = ThinkingSphinx::Search.search params[:search], :page =>
> params[:page], :per_page => 1#, :order => :votes_count\
>
>  end

Well, firstly uncomment the :order part, and then...
>
>
> #In words model
>
>       define_index do
>               indexes word
>
> #             set_property :delta => true
>
> #             has id, created_at
>       end

Add 'has votes_count' to your index - you can only order by attributes  
(or fields flagged as sortable). Then reindex your data.

>
>
> # In search model
>
>      def search
>       @words = Word.search params[:search]
>      end

search model? controller? Not sure... but this doesn't seem to tie  
into the rest of your samples, as far as I can tell.

>
>
> # In my search results
>
>   <h1>Search words for your query</h1>
>    <% for word in @words %>
>      <% if word.class.name == "Word" %>
>            <%= render :partial => "words/word", :locals => { :word =>
> word } %>
>      <% else %>
>          <h1>There were no words for your query</h1><br/><br/>
>      <% end %>
>   <% end %>
> <%= will_paginate @words %>
>
> # and in my Database
>
> create_table "words", :force => true do |t|
>    t.string   "word"
>    t.string   "language"
>    t.text     "definition"
>    t.string   "example"
>    t.datetime "created_at"
>    t.datetime "updated_at"
>    t.integer  "user_id",     :limit => 11
>    t.integer  "votes_count", :limit => 11, :default => 0
>  end
>
>
> I'm trying to sort the search results by "votes_count" so that the
> word with the most votes appears first (Descending).


Adding the votes_count and reindexing should do the trick - let us  
know if you need any more help.

Cheers

-- 
Pat


--~--~---------~--~----~------------~-------~--~----~
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