Class: Estella::Parser
- Inherits:
-
Object
- Object
- Estella::Parser
- Defined in:
- lib/estella/parser.rb
Instance Method Summary collapse
-
#boost(name, opts = {}) ⇒ Object
document level boost.
-
#field(name, opts = {}) ⇒ Object
index a field.
-
#initialize(model) ⇒ Parser
constructor
A new instance of Parser.
Constructor Details
#initialize(model) ⇒ Parser
Returns a new instance of Parser.
5 6 7 |
# File 'lib/estella/parser.rb', line 5 def initialize(model) @model = model end |
Instance Method Details
#boost(name, opts = {}) ⇒ Object
document level boost
11 12 13 14 15 16 17 |
# File 'lib/estella/parser.rb', line 11 def boost(name, opts = {}) raise ArgumentError, 'Boost field is not indexed!' unless @model.indexed_fields.include? name raise ArgumentError, 'Please supply a modifier and a factor for your boost!' unless (opts.keys & %i[modifier factor]).length == 2 @model.field_boost = { boost: { field: name }.merge(opts) } end |
#field(name, opts = {}) ⇒ Object
index a field
20 21 22 23 24 25 26 27 28 |
# File 'lib/estella/parser.rb', line 20 def field(name, opts = {}) using = opts[:using] || name analysis = opts[:analysis] & @model.default_analysis_fields.keys opts[:fields] ||= Hash[analysis.zip(@model.default_analysis_fields.values_at(*analysis))] if analysis include_raw = opts.delete(:include_raw) opts[:fields][:raw] = { type: 'keyword' } if include_raw @model.indexed_json.merge!(name => using) @model.indexed_fields.merge!(name => opts) end |