Class: Eson::Search::CustomFiltersScore

Inherits:
Object
  • Object
show all
Includes:
Queries, Query
Defined in:
lib/eson/search/custom_filters_score.rb

Instance Attribute Summary collapse

Attributes included from Queries

#queries

Instance Method Summary collapse

Methods included from Query

included, #method_missing

Methods included from Queries

#queries?, register

Constructor Details

#initialize(options = {}) ⇒ CustomFiltersScore

Returns a new instance of CustomFiltersScore.



12
13
14
15
# File 'lib/eson/search/custom_filters_score.rb', line 12

def initialize(options = {})
  self.options = options
  self.filters = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Eson::Search::Query

Instance Attribute Details

#filters(&block) ⇒ Object

Returns the value of attribute filters.



10
11
12
# File 'lib/eson/search/custom_filters_score.rb', line 10

def filters
  @filters
end

#optionsObject

Returns the value of attribute options.



10
11
12
# File 'lib/eson/search/custom_filters_score.rb', line 10

def options
  @options
end

Instance Method Details

#custom_filters_score { ... } ⇒ self

Generates a ‘custom_filters_score` query in a query context.

Yields:

  • the block containing further options and subqueries

Returns:

  • (self)

    the generated facet



8
# File 'lib/eson/search/custom_filters_score.rb', line 8

short_name :custom_filters_score

#filter(options, &block) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/eson/search/custom_filters_score.rb', line 21

def filter(options, &block)
  sub = SubQuery.new(args)
  
  @filters << [options, sub]
  
  sub.send(context, &block)
end

#to_query_hashObject



29
30
31
32
33
34
35
36
37
38
# File 'lib/eson/search/custom_filters_score.rb', line 29

def to_query_hash
  result = {}

  result[:query] = queries.to_query_hash
  result[:filters] = @filters.map do |options, filter|
    {:filter => filter.to_query_hash}.merge!(options)
  end

  {name => result.merge(options)}
end