lib/elastics/result/rails_helper.rb in elastics-rails-1.1.11 vs lib/elastics/result/rails_helper.rb in elastics-rails-1.2.0
- old
+ new
@@ -12,27 +12,28 @@
end
def method_missing(meth, *args, &block)
meth.to_s =~ RE
attribute = $1
- if attribute
- opts = {:fragment_separator => ' ... '}.merge(args.first||{})
- if self['highlight']
- key, high = self['highlight'].find { |k,v| k.gsub('.','_') == attribute }
- high = Array.wrap(high) if high
- end
- if high.blank?
- respond_to?(attribute.to_sym) ? send(attribute.to_sym) : ''
- else
- high.join(opts[:fragment_separator]).html_safe
- end
+ attribute ? higlighted(attribute, args.first || {}) : super
+ end
+
+ # TODO: add the doc for this method
+ def higlighted(attribute, opts={})
+ opts = { :fragment_separator => ' ... ' }.merge(opts)
+ if self['highlight']
+ # works also with nested attributes
+ key, high = self['highlight'].find { |k, v| k.gsub('.', '_') == attribute }
+ high = Array.wrap(high) if high
+ end
+ if high.blank?
+ respond_to?(attribute.to_sym) ? send(attribute.to_sym) : ''
else
- super
+ high.join(opts[:fragment_separator]).html_safe
end
end
end
-
# extend if result is a Search or MultiGet
def self.should_extend?(result)
result.is_a?(Search) || result.is_a?(MultiGet)
end