File tree 3 files changed +11
-2
lines changed
elasticsearch-persistence
lib/elasticsearch/persistence
3 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -108,6 +108,7 @@ def deserialize(document)
108
108
object . instance_variable_set :@_index , document [ '_index' ]
109
109
object . instance_variable_set :@_type , document [ '_type' ]
110
110
object . instance_variable_set :@_version , document [ '_version' ]
111
+ object . instance_variable_set :@_source , document [ '_source' ]
111
112
112
113
# Store the "hit" information (highlighting, score, ...)
113
114
#
Original file line number Diff line number Diff line change @@ -49,6 +49,12 @@ def _version
49
49
@_version
50
50
end
51
51
52
+ # Return the raw document `_source`
53
+ #
54
+ def _source
55
+ @_source
56
+ end
57
+
52
58
def to_s
53
59
"#<#{ self . class } #{ attributes . to_hash . inspect . gsub ( /:(\w +)=>/ , '\1: ' ) } >"
54
60
end ; alias :inspect :to_s
Original file line number Diff line number Diff line change @@ -89,11 +89,13 @@ def run!; DummyGatewayModel.gateway { |g| @b += 1 }; end
89
89
assert DummyGatewayModel . gateway . deserialize ( '_id' => 'abc123' , '_source' => { } ) . instance_variable_get ( :@persisted )
90
90
end
91
91
92
+ should "allow accessing the raw _source" do
93
+ assert_equal 'bar' , DummyGatewayModel . gateway . deserialize ( '_source' => { 'foo' => 'bar' } ) . _source [ 'foo' ]
94
+ end
95
+
92
96
should "allow to access the raw hit from results as Hashie::Mash" do
93
97
assert_equal 0.42 , DummyGatewayModel . gateway . deserialize ( '_score' => 0.42 , '_source' => { } ) . hit . _score
94
98
end
95
99
96
-
97
-
98
100
end
99
101
end
You can’t perform that action at this time.
0 commit comments