Class: Mastico::Query
- Inherits:
-
Object
- Object
- Mastico::Query
- Defined in:
- lib/mastico/query.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ term_boost: 1.0, prefix_boost: 0.7, infix_boost: 0.4, fuzzy_boost: 0.2, minimum_term_length: 2, minimum_prefix_length: 3, minimum_infix_length: 3, minimum_fuzzy_length: 5, fuzziness: 4 }.freeze
- QUERY_TYPES =
[:term, :prefix, :infix, :fuzzy].freeze
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#word_weight ⇒ Object
readonly
Returns the value of attribute word_weight.
Instance Method Summary collapse
- #apply(scope) ⇒ Object
-
#initialize(query:, fields:, word_weight: ->(_w) { 1.0 }, options: DEFAULT_OPTIONS) ⇒ Query
constructor
A new instance of Query.
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 = @parts = nil end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
18 19 20 |
# File 'lib/mastico/query.rb', line 18 def fields @fields end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
20 21 22 |
# File 'lib/mastico/query.rb', line 20 def @options end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
17 18 19 |
# File 'lib/mastico/query.rb', line 17 def query @query end |
#word_weight ⇒ Object (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 |