What's the full query you're running, including field weights? Or are they set 
in your define_index block?

Also, what's the output of the following:
  media = Media.search('query here',
    :group_by       => 'parent_media',
    :group_function => :attr,
    :field_weights  => {'title' => 100}
  )
  media.results

And finally, how are you expecting the field weights to modify the search 
results? What are you seeing, and what do you expect to see?

Cheers

-- 
Pat

On 13/01/2011, at 7:58 PM, p. wrote:

> okay, got this to work using:
> 
> Media.search 'query here', :group_by =>
> 'parent_media', :group_function => :attr
> 
> BUT
> 
> I also have field weights (:field_weights => { :title => 100}), which
> seem to have
> no effect once the group_by is added.
> 
> On Jan 12, 11:46 pm, "p." <[email protected]> wrote:
>> okay, i have different types of media (tv, movies, web videos). my
>> media model is self-referencing to handle the case of tv series and
>> episodes; series_id is null except for specific tv episodes, which
>> reference the associated series (see below). Here's what I'd like to
>> do:
>> 
>> If a search matches anything except a tv episode or series, simply
>> return associated media. In the case of tv or episodes, I'd like to
>> group them together. so i figured i'd create "derived" attribute,
>> named parent_media, which was the series_id if series_id wasn't null
>> and was the id when series_id was null. then i could group_by that
>> attribute. below is what i tried...
>> 
>> class Media < ActiveRecord::Base
>>   has_many :episodes, :class_name => 'Media', :foreign_key =>
>> 'series_id'
>>   belongs_to :series, :class_name => 'Media', :foreign_key =>
>> 'series_id'
>> 
>>   define_index do
>>     indexes title
>>     indexes description
>>     has duration
>>     has series_id
>>     has 'IF(series_id, series_id, id)', :type => :integer, :as
>> => :parent_media
>> end
>> 
>> Media.search 'query here', :group_by => :parent_media
>> 
>> and got
>> 
>> NoMethodError: undefined method `bytesize' for :parent_media:Symbol
>>         from /Library/Ruby/Gems/1.8/gems/riddle-1.1.0/lib/riddle/client/
>> message.rb:21:in `send'
>>         from /Library/Ruby/Gems/1.8/gems/riddle-1.1.0/lib/riddle/client/
>> message.rb:21:in `append_string'
>>         from /Library/Ruby/Gems/1.8/gems/riddle-1.1.0/lib/riddle/client.rb:
>> 641:in `query_message'
>>         from /Library/Ruby/Gems/1.8/gems/riddle-1.1.0/lib/riddle/client.rb:
>> 315:in `query'
>>         from /Library/Ruby/Gems/1.8/gems/thinking-sphinx-2.0.0.rc2/lib/
>> thinking_sphinx/search.rb:326:in `populate'
>>         from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
>> ruby/1.8/benchmark.rb:308:in `realtime'
>>         from /Library/Ruby/Gems/1.8/gems/thinking-sphinx-2.0.0.rc2/lib/
>> thinking_sphinx/search.rb:325:in `populate'
>>         from /Library/Ruby/Gems/1.8/gems/thinking-sphinx-2.0.0.rc2/lib/
>> thinking_sphinx/search.rb:441:in `call'
>>         from /Library/Ruby/Gems/1.8/gems/thinking-sphinx-2.0.0.rc2/lib/
>> thinking_sphinx/search.rb:441:in `retry_on_stale_index'
>>         from /Library/Ruby/Gems/1.8/gems/thinking-sphinx-2.0.0.rc2/lib/
>> thinking_sphinx/search.rb:322:in `populate'
>>         from /Library/Ruby/Gems/1.8/gems/thinking-sphinx-2.0.0.rc2/lib/
>> thinking_sphinx/search.rb:135:in `method_missing'
>>         from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
>> ruby/1.8/irb.rb:302:in `output_value'
>>         from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
>> ruby/1.8/irb.rb:151:in `eval_input'
>>         from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
>> ruby/1.8/irb.rb:263:in `signal_status'
>>         from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
>> ruby/1.8/irb.rb:147:in `eval_input'
>>         from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
>> ruby/1.8/irb.rb:146:in `eval_input'
>>         from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
>> ruby/1.8/irb.rb:70:in `start'
>>         from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
>> ruby/1.8/irb.rb:69:in `catch'
>>         from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
>> ruby/1.8/irb.rb:69:in `start'
>>         from /Library/Ruby/Gems/1.8/gems/railties-3.0.0/lib/rails/commands/
>> console.rb:44:in `start'
>>         from /Library/Ruby/Gems/1.8/gems/railties-3.0.0/lib/rails/commands/
>> console.rb:8:in `start'
>>         from 
>> /Library/Ruby/Gems/1.8/gems/railties-3.0.0/lib/rails/commands.rb:
>> 23
>>         from script/rails:6:in `require'
>> 
>> I'm fairly certain I'm using group_by wrong. Any suggestions?
> 
> -- 
> 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.
> 

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