Possible bug with stored fields and Rails models

14 views
Skip to first unread message

Dylan Vaughn

unread,
Mar 31, 2010, 4:45:32 AM3/31/10
to Sunspot
Hello,

I'm starting to look at Sunspot (installed via gems) and have run into
an issue retrieving stored fields. I'm using the Rails integration
and am getting errors when trying to access stored fields off of hits
of subclasses, i.e. (contrived example):

class Shortcut < ActiveRecord::Base
searchable do
string :name, :stored => true
text :name
end
end

class SecretShortcut < Shortcut
end

>> Shortcut.all.map { |s| [s.class.to_s, s.name] }
=> [["Shortcut", "test name"], ["SecretShortcut", "second test"]]
>> result = Shortcut.search { keywords('test') }
=> <Sunspot::Search:
{:fq=>["type:Shortcut"], :q=>"test", :start=>0, :fl=>"*
score", :qf=>"name_text", :rows=>30, :defType=>"dismax"}>
>> result.hits
=> [#<Sunspot::Search::Hit:Shortcut 1>,
#<Sunspot::Search::Hit:SecretShortcut 2>]
>> result.hits.first.stored(:name)
=> "test name"
>> result.hits.last.stored(:name)
NoMethodError: undefined method `superclass' for
"SecretShortcut":String
from /var/lib/gems/1.8/gems/sunspot-1.0.5/lib/sunspot/setup.rb:299:in
`for'
from /var/lib/gems/1.8/gems/sunspot-1.0.5/lib/sunspot/search/hit.rb:
107:in `setup'
from /var/lib/gems/1.8/gems/sunspot-1.0.5/lib/sunspot/search/hit.rb:
127:in `stored_value'
from /var/lib/gems/1.8/gems/sunspot-1.0.5/lib/sunspot/search/hit.rb:
85:in `stored'
from (irb):23
>>

If i make this change:

root@dylan-laptop:/var/lib/gems/1.8/gems/sunspot-1.0.5/lib/sunspot/
search# diff hit.rb hit.rb.orig
107c107
< @setup ||= Sunspot::Setup.for(@class_name.constantize)
---
> @setup ||= Sunspot::Setup.for(@class_name)

Then it works. Is this a bug or user error? :) If it is a bug I will
submit a patch on lighthouse.

Thanks!

Dylan

Mat Brown

unread,
Mar 31, 2010, 7:56:38 AM3/31/10
to ruby-s...@googlegroups.com

Looks like a bug to me!


--
You received this message because you are subscribed to the Google Groups "Sunspot" group.
To post to this group, send email to ruby-s...@googlegroups.com.
To unsubscribe from this group, send email to ruby-sunspot...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ruby-sunspot?hl=en.

Dylan Vaughn

unread,
Apr 3, 2010, 5:25:44 PM4/3/10
to ruby-s...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages