Skip to content

Commit

Permalink
Correctly cast and return stored values for multi-valued fields
Browse files Browse the repository at this point in the history
[sunspot#111 state:resolved]
  • Loading branch information
outoftime committed Dec 27, 2010
1 parent bd94817 commit cf00a3f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
7 changes: 6 additions & 1 deletion sunspot/lib/sunspot/search/hit.rb
Expand Up @@ -126,7 +126,12 @@ def highlights_cache
def stored_value(field_name, dynamic_field_name)
setup.stored_fields(field_name, dynamic_field_name).each do |field|
if value = @stored_values[field.indexed_name]
return field.cast(value)
case value
when Array
return value.map { |item| field.cast(item) }
else
return field.cast(value)
end
end
end
nil
Expand Down
5 changes: 5 additions & 0 deletions sunspot/spec/api/search/hits_spec.rb
Expand Up @@ -133,6 +133,11 @@ class SubclassedPost < Post; end;
session.search(Post).hits.first.stored(:last_indexed_at).should == time
end

it 'should return stored values for multi-valued fields' do
stub_full_results('instance' => User.new, 'role_ids_ims' => %w(1 4 5))
session.search(User).hits.first.stored(:role_ids).should == [1, 4, 5]
end

it 'should return geo distance' do
post = Post.new
stub_results(post)
Expand Down
7 changes: 6 additions & 1 deletion sunspot/spec/mocks/user.rb
@@ -1,8 +1,13 @@
class User
attr_accessor :name
attr_accessor :name, :roles

def id
1
end
end

Sunspot.setup(User) do
text :name
string :name
integer :role_ids, :multiple => true, :stored => true
end

0 comments on commit cf00a3f

Please sign in to comment.