#107 ✓resolved
dylanvaughn (at yahoo)

Error when retrieving stored fields for subclassed objects

Reported by dylanvaughn (at yahoo) | April 3rd, 2010 @ 05:23 PM | in Bugs

Snippet from my post on the google group[1]:

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

class SecretShortcut < Shortcut

>> 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
        from /var/lib/gems/1.8/gems/sunspot-1.0.5/lib/sunspot/setup.rb:299:in
        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

I ended up not using constantize (since it's Rails specific) but instead the Util.full_const_get method already in Sunspot. Patch with spec attached.



  1. http://groups.google.com/group/ruby-sunspot/browse_frm/thread/f63bf...

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Awesome Solr interaction for Ruby

People watching this ticket



Referenced by