Class: Mastico::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/mastico/query.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  word_boost: 1.0,
  prefix_boost: 0.7,
  infix_boost: 0.4,
  fuzzy_boost: 0.2,
  minimum_word_length: 2,
  minimum_prefix_length: 3,
  minimum_infix_length: 3,
  minimum_fuzzy_length: 5,
  fuzziness: 4
}.freeze
QUERY_TYPES =
[:word, :prefix, :infix, :fuzzy].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query:, fields:, word_weight: ->(_w) { 1.0 }, options: DEFAULT_OPTIONS) ⇒ Query

Returns a new instance of Query.



22
23
24
25
26
27
28
# File 'lib/mastico/query.rb', line 22

def initialize(query:, fields:, word_weight: ->(_w) { 1.0 }, options: DEFAULT_OPTIONS)
  @query = query
  @fields = fields
  @word_weight = word_weight
  @options = options
  @parts = nil
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



18
19
20
# File 'lib/mastico/query.rb', line 18

def fields
  @fields
end

#optionsObject (readonly)

Returns the value of attribute options.



20
21
22
# File 'lib/mastico/query.rb', line 20

def options
  @options
end

#queryObject (readonly)

Returns the value of attribute query.



17
18
19
# File 'lib/mastico/query.rb', line 17

def query
  @query
end

#word_weightObject (readonly)

Returns the value of attribute word_weight.



19
20
21
# File 'lib/mastico/query.rb', line 19

def word_weight
  @word_weight
end

Instance Method Details

#apply(scope) ⇒ Object



30
31
32
# File 'lib/mastico/query.rb', line 30

def apply(scope)
  parts ? scope.query(parts) : scope
end