Module: SearchFlip::Highlightable
- Included in:
- Aggregation, Criteria
- Defined in:
- lib/search_flip/highlightable.rb
Overview
The SearchFlip::Sortable mixin provides the chainable #highlight method to use elasticsearch highlighting
Class Method Summary collapse
Instance Method Summary collapse
-
#highlight(fields, options = {}) ⇒ SearchFlip::Criteria
Adds highlighting of the given fields to the request.
Class Method Details
.included(base) ⇒ Object
6 7 8 9 10 |
# File 'lib/search_flip/highlightable.rb', line 6 def self.included(base) base.class_eval do attr_accessor :highlight_values end end |
Instance Method Details
#highlight(fields, options = {}) ⇒ SearchFlip::Criteria
Adds highlighting of the given fields to the request.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/search_flip/highlightable.rb', line 32 def highlight(fields, = {}) fresh.tap do |criteria| criteria.highlight_values = (criteria.highlight_values || {}).merge() hash = case fields when Hash fields when Array fields.each_with_object({}) { |field, h| h[field] = {} } else { fields => {} } end criteria.highlight_values[:fields] = (criteria.highlight_values[:fields] || {}).merge(hash) end end |