Class: Tire::Search::Query::CustomFiltersScoreQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/tire/search/queries/custom_filters_score.rb

Defined Under Namespace

Classes: CustomFilter

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ CustomFiltersScoreQuery

Returns a new instance of CustomFiltersScoreQuery



88
89
90
91
# File 'lib/tire/search/queries/custom_filters_score.rb', line 88

def initialize(&block)
  @value = {}
  block.arity < 1 ? self.instance_eval(&block) : block.call(self) if block_given?
end

Instance Method Details

#filter(&block) ⇒ Object



98
99
100
101
102
103
104
# File 'lib/tire/search/queries/custom_filters_score.rb', line 98

def filter(&block)
  custom_filter = CustomFilter.new
  block.arity < 1 ? custom_filter.instance_eval(&block) : block.call(custom_filter) if block_given?
  @value[:filters] ||= []
  @value[:filters] << custom_filter.to_hash
  @value
end

#params(value) ⇒ Object



111
112
113
114
# File 'lib/tire/search/queries/custom_filters_score.rb', line 111

def params(value)
  @value[:params] = value
  @value
end

#query(options = {}, &block) ⇒ Object



93
94
95
96
# File 'lib/tire/search/queries/custom_filters_score.rb', line 93

def query(options={}, &block)
  @value[:query] = Query.new(&block).to_hash
  @value
end

#score_mode(value) ⇒ Object



106
107
108
109
# File 'lib/tire/search/queries/custom_filters_score.rb', line 106

def score_mode(value)
  @value[:score_mode] = value
  @value
end

#to_hashObject



116
117
118
119
120
# File 'lib/tire/search/queries/custom_filters_score.rb', line 116

def to_hash
  @value[:filters] ?
  @value :
  @value.merge(:filters => [CustomFilter.new{ filter(:match_all); boost(1) }.to_hash]) # Needs at least one filter
end

#to_jsonObject



122
123
124
# File 'lib/tire/search/queries/custom_filters_score.rb', line 122

def to_json
  to_hash.to_json
end