tire-erez 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +14 -0
- data/.travis.yml +32 -0
- data/.yardopts +1 -0
- data/Gemfile +10 -0
- data/MIT-LICENSE +20 -0
- data/README.markdown +775 -0
- data/Rakefile +51 -0
- data/examples/rails-application-template.rb +263 -0
- data/examples/tire-dsl.rb +932 -0
- data/lib/tire.rb +59 -0
- data/lib/tire/alias.rb +296 -0
- data/lib/tire/configuration.rb +38 -0
- data/lib/tire/count.rb +85 -0
- data/lib/tire/dsl.rb +114 -0
- data/lib/tire/http/client.rb +62 -0
- data/lib/tire/http/clients/curb.rb +61 -0
- data/lib/tire/http/clients/faraday.rb +71 -0
- data/lib/tire/http/response.rb +27 -0
- data/lib/tire/index.rb +443 -0
- data/lib/tire/logger.rb +60 -0
- data/lib/tire/model/callbacks.rb +40 -0
- data/lib/tire/model/import.rb +27 -0
- data/lib/tire/model/indexing.rb +134 -0
- data/lib/tire/model/naming.rb +100 -0
- data/lib/tire/model/percolate.rb +99 -0
- data/lib/tire/model/persistence.rb +72 -0
- data/lib/tire/model/persistence/attributes.rb +148 -0
- data/lib/tire/model/persistence/finders.rb +54 -0
- data/lib/tire/model/persistence/storage.rb +77 -0
- data/lib/tire/model/search.rb +322 -0
- data/lib/tire/multi_search.rb +263 -0
- data/lib/tire/results/collection.rb +156 -0
- data/lib/tire/results/item.rb +94 -0
- data/lib/tire/results/pagination.rb +68 -0
- data/lib/tire/rubyext/hash.rb +8 -0
- data/lib/tire/rubyext/ruby_1_8.rb +1 -0
- data/lib/tire/rubyext/symbol.rb +11 -0
- data/lib/tire/rubyext/uri_escape.rb +74 -0
- data/lib/tire/search.rb +211 -0
- data/lib/tire/search/facet.rb +81 -0
- data/lib/tire/search/filter.rb +28 -0
- data/lib/tire/search/highlight.rb +37 -0
- data/lib/tire/search/queries/match.rb +40 -0
- data/lib/tire/search/query.rb +250 -0
- data/lib/tire/search/scan.rb +114 -0
- data/lib/tire/search/script_field.rb +23 -0
- data/lib/tire/search/sort.rb +25 -0
- data/lib/tire/tasks.rb +138 -0
- data/lib/tire/utils.rb +17 -0
- data/lib/tire/version.rb +18 -0
- data/test/fixtures/articles/1.json +1 -0
- data/test/fixtures/articles/2.json +1 -0
- data/test/fixtures/articles/3.json +1 -0
- data/test/fixtures/articles/4.json +1 -0
- data/test/fixtures/articles/5.json +1 -0
- data/test/integration/active_model_indexing_test.rb +51 -0
- data/test/integration/active_model_searchable_test.rb +114 -0
- data/test/integration/active_record_searchable_test.rb +620 -0
- data/test/integration/boolean_queries_test.rb +43 -0
- data/test/integration/boosting_queries_test.rb +32 -0
- data/test/integration/bulk_test.rb +86 -0
- data/test/integration/count_test.rb +64 -0
- data/test/integration/custom_score_queries_test.rb +89 -0
- data/test/integration/dis_max_queries_test.rb +68 -0
- data/test/integration/dsl_search_test.rb +30 -0
- data/test/integration/explanation_test.rb +44 -0
- data/test/integration/facets_test.rb +311 -0
- data/test/integration/filtered_queries_test.rb +66 -0
- data/test/integration/filters_test.rb +75 -0
- data/test/integration/fuzzy_queries_test.rb +20 -0
- data/test/integration/highlight_test.rb +64 -0
- data/test/integration/index_aliases_test.rb +122 -0
- data/test/integration/index_mapping_test.rb +43 -0
- data/test/integration/index_store_test.rb +112 -0
- data/test/integration/index_update_document_test.rb +121 -0
- data/test/integration/match_query_test.rb +79 -0
- data/test/integration/mongoid_searchable_test.rb +309 -0
- data/test/integration/multi_search_test.rb +114 -0
- data/test/integration/nested_query_test.rb +135 -0
- data/test/integration/percolator_test.rb +111 -0
- data/test/integration/persistent_model_test.rb +205 -0
- data/test/integration/prefix_query_test.rb +43 -0
- data/test/integration/query_return_version_test.rb +70 -0
- data/test/integration/query_string_test.rb +52 -0
- data/test/integration/range_queries_test.rb +36 -0
- data/test/integration/reindex_test.rb +56 -0
- data/test/integration/results_test.rb +58 -0
- data/test/integration/scan_test.rb +56 -0
- data/test/integration/script_fields_test.rb +38 -0
- data/test/integration/sort_test.rb +52 -0
- data/test/integration/text_query_test.rb +39 -0
- data/test/models/active_model_article.rb +31 -0
- data/test/models/active_model_article_with_callbacks.rb +49 -0
- data/test/models/active_model_article_with_custom_document_type.rb +7 -0
- data/test/models/active_model_article_with_custom_index_name.rb +7 -0
- data/test/models/active_record_models.rb +131 -0
- data/test/models/article.rb +15 -0
- data/test/models/mongoid_models.rb +85 -0
- data/test/models/persistent_article.rb +11 -0
- data/test/models/persistent_article_in_index.rb +16 -0
- data/test/models/persistent_article_in_namespace.rb +12 -0
- data/test/models/persistent_article_with_casting.rb +28 -0
- data/test/models/persistent_article_with_defaults.rb +12 -0
- data/test/models/persistent_article_with_percolation.rb +5 -0
- data/test/models/persistent_articles_with_custom_index_name.rb +10 -0
- data/test/models/supermodel_article.rb +17 -0
- data/test/models/validated_model.rb +11 -0
- data/test/test_helper.rb +118 -0
- data/test/unit/active_model_lint_test.rb +17 -0
- data/test/unit/configuration_test.rb +84 -0
- data/test/unit/count_test.rb +67 -0
- data/test/unit/http_client_test.rb +79 -0
- data/test/unit/http_response_test.rb +49 -0
- data/test/unit/index_alias_test.rb +335 -0
- data/test/unit/index_test.rb +1098 -0
- data/test/unit/logger_test.rb +125 -0
- data/test/unit/model_callbacks_test.rb +116 -0
- data/test/unit/model_import_test.rb +75 -0
- data/test/unit/model_initialization_test.rb +31 -0
- data/test/unit/model_persistence_test.rb +548 -0
- data/test/unit/model_search_test.rb +964 -0
- data/test/unit/multi_search_test.rb +304 -0
- data/test/unit/results_collection_test.rb +372 -0
- data/test/unit/results_item_test.rb +173 -0
- data/test/unit/rubyext_test.rb +66 -0
- data/test/unit/search_facet_test.rb +186 -0
- data/test/unit/search_filter_test.rb +42 -0
- data/test/unit/search_highlight_test.rb +46 -0
- data/test/unit/search_query_test.rb +419 -0
- data/test/unit/search_scan_test.rb +113 -0
- data/test/unit/search_script_field_test.rb +26 -0
- data/test/unit/search_sort_test.rb +50 -0
- data/test/unit/search_test.rb +556 -0
- data/test/unit/tire_test.rb +144 -0
- data/tire.gemspec +83 -0
- metadata +586 -0
@@ -0,0 +1,68 @@
|
|
1
|
+
module Tire
|
2
|
+
module Results
|
3
|
+
|
4
|
+
# Adds support for WillPaginate and Kaminari
|
5
|
+
#
|
6
|
+
module Pagination
|
7
|
+
|
8
|
+
def default_per_page
|
9
|
+
10
|
10
|
+
end
|
11
|
+
module_function :default_per_page
|
12
|
+
|
13
|
+
def total_entries
|
14
|
+
@total
|
15
|
+
end
|
16
|
+
|
17
|
+
def per_page
|
18
|
+
(@options[:per_page] || @options[:size] || default_per_page ).to_i
|
19
|
+
end
|
20
|
+
|
21
|
+
def total_pages
|
22
|
+
( @total.to_f / per_page ).ceil
|
23
|
+
end
|
24
|
+
|
25
|
+
def current_page
|
26
|
+
if @options[:page]
|
27
|
+
@options[:page].to_i
|
28
|
+
else
|
29
|
+
(per_page + @options[:from].to_i) / per_page
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def previous_page
|
34
|
+
current_page > 1 ? (current_page - 1) : nil
|
35
|
+
end
|
36
|
+
|
37
|
+
def next_page
|
38
|
+
current_page < total_pages ? (current_page + 1) : nil
|
39
|
+
end
|
40
|
+
|
41
|
+
def offset
|
42
|
+
per_page * (current_page - 1)
|
43
|
+
end
|
44
|
+
|
45
|
+
def out_of_bounds?
|
46
|
+
current_page > total_pages
|
47
|
+
end
|
48
|
+
|
49
|
+
# Kaminari support
|
50
|
+
#
|
51
|
+
alias :limit_value :per_page
|
52
|
+
alias :total_count :total_entries
|
53
|
+
alias :num_pages :total_pages
|
54
|
+
alias :offset_value :offset
|
55
|
+
|
56
|
+
def first_page?
|
57
|
+
current_page == 1
|
58
|
+
end
|
59
|
+
|
60
|
+
def last_page?
|
61
|
+
current_page == total_pages
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'tire/rubyext/uri_escape'
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# Steal the URI escape/unescape compatibility layer from Rack
|
2
|
+
#
|
3
|
+
# See <http://www.ruby-doc.org/stdlib-1.9.3/libdoc/uri/rdoc/URI.html#method-c-encode_www_form_component>
|
4
|
+
|
5
|
+
# :stopdoc:
|
6
|
+
|
7
|
+
# Stolen from ruby core's uri/common.rb, with modifications to support 1.8.x
|
8
|
+
#
|
9
|
+
# https://github.com/ruby/ruby/blob/trunk/lib/uri/common.rb
|
10
|
+
#
|
11
|
+
#
|
12
|
+
|
13
|
+
module URI
|
14
|
+
TBLENCWWWCOMP_ = {} # :nodoc:
|
15
|
+
TBLDECWWWCOMP_ = {} # :nodoc:
|
16
|
+
|
17
|
+
# Encode given +s+ to URL-encoded form data.
|
18
|
+
#
|
19
|
+
# This method doesn't convert *, -, ., 0-9, A-Z, _, a-z, but does convert SP
|
20
|
+
# (ASCII space) to + and converts others to %XX.
|
21
|
+
#
|
22
|
+
# This is an implementation of
|
23
|
+
# http://www.w3.org/TR/html5/forms.html#url-encoded-form-data
|
24
|
+
#
|
25
|
+
# See URI.decode_www_form_component, URI.encode_www_form
|
26
|
+
def self.encode_www_form_component(s)
|
27
|
+
str = s.to_s
|
28
|
+
if RUBY_VERSION < "1.9" && $KCODE =~ /u/i
|
29
|
+
str.gsub(/([^ a-zA-Z0-9_.-]+)/) do
|
30
|
+
'%' + $1.unpack('H2' * Rack::Utils.bytesize($1)).join('%').upcase
|
31
|
+
end.tr(' ', '+')
|
32
|
+
else
|
33
|
+
if TBLENCWWWCOMP_.empty?
|
34
|
+
tbl = {}
|
35
|
+
256.times do |i|
|
36
|
+
tbl[i.chr] = '%%%02X' % i
|
37
|
+
end
|
38
|
+
tbl[' '] = '+'
|
39
|
+
begin
|
40
|
+
TBLENCWWWCOMP_.replace(tbl)
|
41
|
+
TBLENCWWWCOMP_.freeze
|
42
|
+
rescue
|
43
|
+
end
|
44
|
+
end
|
45
|
+
str.gsub(/[^*\-.0-9A-Z_a-z]/) {|m| TBLENCWWWCOMP_[m]}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Decode given +str+ of URL-encoded form data.
|
50
|
+
#
|
51
|
+
# This decods + to SP.
|
52
|
+
#
|
53
|
+
# See URI.encode_www_form_component, URI.decode_www_form
|
54
|
+
def self.decode_www_form_component(str, enc=nil)
|
55
|
+
if TBLDECWWWCOMP_.empty?
|
56
|
+
tbl = {}
|
57
|
+
256.times do |i|
|
58
|
+
h, l = i>>4, i&15
|
59
|
+
tbl['%%%X%X' % [h, l]] = i.chr
|
60
|
+
tbl['%%%x%X' % [h, l]] = i.chr
|
61
|
+
tbl['%%%X%x' % [h, l]] = i.chr
|
62
|
+
tbl['%%%x%x' % [h, l]] = i.chr
|
63
|
+
end
|
64
|
+
tbl['+'] = ' '
|
65
|
+
begin
|
66
|
+
TBLDECWWWCOMP_.replace(tbl)
|
67
|
+
TBLDECWWWCOMP_.freeze
|
68
|
+
rescue
|
69
|
+
end
|
70
|
+
end
|
71
|
+
raise ArgumentError, "invalid %-encoding (#{str})" unless /\A(?:%[0-9a-fA-F]{2}|[^%])*\z/ =~ str
|
72
|
+
str.gsub(/\+|%[0-9a-fA-F]{2}/) {|m| TBLDECWWWCOMP_[m]}
|
73
|
+
end
|
74
|
+
end
|
data/lib/tire/search.rb
ADDED
@@ -0,0 +1,211 @@
|
|
1
|
+
module Tire
|
2
|
+
module Search
|
3
|
+
class SearchRequestFailed < StandardError; end
|
4
|
+
|
5
|
+
class Search
|
6
|
+
|
7
|
+
attr_reader :indices, :types, :query, :facets, :filters, :options, :explain, :script_fields
|
8
|
+
|
9
|
+
def initialize(indices=nil, options={}, &block)
|
10
|
+
if indices.is_a?(Hash)
|
11
|
+
set_indices_options(indices)
|
12
|
+
@indices = indices.keys
|
13
|
+
else
|
14
|
+
@indices = Array(indices)
|
15
|
+
end
|
16
|
+
@types = Array(options.delete(:type)).map { |type| Utils.escape(type) }
|
17
|
+
@options = options
|
18
|
+
|
19
|
+
@path = ['/', @indices.join(','), @types.join(','), '_search'].compact.join('/').squeeze('/')
|
20
|
+
|
21
|
+
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def set_indices_options(indices)
|
26
|
+
indices.each do |index, index_options|
|
27
|
+
if index_options[:boost]
|
28
|
+
@indices_boost ||= {}
|
29
|
+
@indices_boost[index] = index_options[:boost]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def results
|
35
|
+
@results || (perform; @results)
|
36
|
+
end
|
37
|
+
|
38
|
+
def response
|
39
|
+
@response || (perform; @response)
|
40
|
+
end
|
41
|
+
|
42
|
+
def json
|
43
|
+
@json || (perform; @json)
|
44
|
+
end
|
45
|
+
|
46
|
+
def url
|
47
|
+
Configuration.url + @path
|
48
|
+
end
|
49
|
+
|
50
|
+
def params
|
51
|
+
options = @options.except(:wrapper)
|
52
|
+
options.empty? ? '' : '?' + options.to_param
|
53
|
+
end
|
54
|
+
|
55
|
+
def query(&block)
|
56
|
+
@query = Query.new
|
57
|
+
block.arity < 1 ? @query.instance_eval(&block) : block.call(@query)
|
58
|
+
self
|
59
|
+
end
|
60
|
+
|
61
|
+
def sort(&block)
|
62
|
+
@sort = Sort.new(&block).to_ary
|
63
|
+
self
|
64
|
+
end
|
65
|
+
|
66
|
+
def facet(name, options={}, &block)
|
67
|
+
@facets ||= {}
|
68
|
+
@facets.update Facet.new(name, options, &block).to_hash
|
69
|
+
self
|
70
|
+
end
|
71
|
+
|
72
|
+
def filter(type, *options)
|
73
|
+
@filters ||= []
|
74
|
+
@filters << Filter.new(type, *options).to_hash
|
75
|
+
self
|
76
|
+
end
|
77
|
+
|
78
|
+
def script_field(name, options={})
|
79
|
+
@script_fields ||= {}
|
80
|
+
@script_fields.merge! ScriptField.new(name, options).to_hash
|
81
|
+
self
|
82
|
+
end
|
83
|
+
|
84
|
+
def highlight(*args)
|
85
|
+
unless args.empty?
|
86
|
+
@highlight = Highlight.new(*args)
|
87
|
+
self
|
88
|
+
else
|
89
|
+
@highlight
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def from(value)
|
94
|
+
@from = value
|
95
|
+
@options[:from] = value
|
96
|
+
self
|
97
|
+
end
|
98
|
+
|
99
|
+
def size(value)
|
100
|
+
@size = value
|
101
|
+
@options[:size] = value
|
102
|
+
self
|
103
|
+
end
|
104
|
+
|
105
|
+
def fields(*fields)
|
106
|
+
@fields = Array(fields.flatten)
|
107
|
+
self
|
108
|
+
end
|
109
|
+
|
110
|
+
def partial_field(name, options)
|
111
|
+
@partial_fields ||= {}
|
112
|
+
@partial_fields[name] = options
|
113
|
+
end
|
114
|
+
|
115
|
+
def explain(value)
|
116
|
+
@explain = value
|
117
|
+
self
|
118
|
+
end
|
119
|
+
|
120
|
+
def version(value)
|
121
|
+
@version = value
|
122
|
+
self
|
123
|
+
end
|
124
|
+
|
125
|
+
def min_score(value)
|
126
|
+
@min_score = value
|
127
|
+
self
|
128
|
+
end
|
129
|
+
|
130
|
+
def track_scores(value)
|
131
|
+
@track_scores = value
|
132
|
+
self
|
133
|
+
end
|
134
|
+
|
135
|
+
def perform
|
136
|
+
@response = Configuration.client.get(self.url + self.params, self.to_json)
|
137
|
+
if @response.failure?
|
138
|
+
STDERR.puts "[REQUEST FAILED] #{self.to_curl}\n"
|
139
|
+
raise SearchRequestFailed, @response.to_s
|
140
|
+
end
|
141
|
+
@json = MultiJson.decode(@response.body)
|
142
|
+
@results = Results::Collection.new(@json, @options)
|
143
|
+
return self
|
144
|
+
ensure
|
145
|
+
logged
|
146
|
+
end
|
147
|
+
|
148
|
+
def to_curl
|
149
|
+
to_json_escaped = to_json.gsub("'",'\u0027')
|
150
|
+
%Q|curl -X GET '#{url}#{params.empty? ? '?' : params.to_s + '&'}pretty' -d '#{to_json_escaped}'|
|
151
|
+
end
|
152
|
+
|
153
|
+
def to_hash
|
154
|
+
@options[:payload] || begin
|
155
|
+
request = {}
|
156
|
+
request.update( { :indices_boost => @indices_boost } ) if @indices_boost
|
157
|
+
request.update( { :query => @query.to_hash } ) if @query
|
158
|
+
request.update( { :sort => @sort.to_ary } ) if @sort
|
159
|
+
request.update( { :facets => @facets.to_hash } ) if @facets
|
160
|
+
request.update( { :filter => @filters.first.to_hash } ) if @filters && @filters.size == 1
|
161
|
+
request.update( { :filter => { :and => @filters.map {|filter| filter.to_hash} } } ) if @filters && @filters.size > 1
|
162
|
+
request.update( { :highlight => @highlight.to_hash } ) if @highlight
|
163
|
+
request.update( { :size => @size } ) if @size
|
164
|
+
request.update( { :from => @from } ) if @from
|
165
|
+
request.update( { :fields => @fields } ) if @fields
|
166
|
+
request.update( { :partial_fields => @partial_fields } ) if @partial_fields
|
167
|
+
request.update( { :script_fields => @script_fields } ) if @script_fields
|
168
|
+
request.update( { :version => @version } ) if @version
|
169
|
+
request.update( { :explain => @explain } ) if @explain
|
170
|
+
request.update( { :min_score => @min_score } ) if @min_score
|
171
|
+
request.update( { :track_scores => @track_scores } ) if @track_scores
|
172
|
+
request
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def to_json(options={})
|
177
|
+
payload = to_hash
|
178
|
+
# TODO: Remove when deprecated interface is removed
|
179
|
+
if payload.is_a?(String)
|
180
|
+
payload
|
181
|
+
else
|
182
|
+
MultiJson.encode(payload, :pretty => Configuration.pretty)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def logged(endpoint='_search')
|
187
|
+
if Configuration.logger
|
188
|
+
|
189
|
+
Configuration.logger.log_request endpoint, indices, to_curl
|
190
|
+
|
191
|
+
took = @json['took'] rescue nil
|
192
|
+
code = @response.code rescue nil
|
193
|
+
|
194
|
+
if Configuration.logger.level.to_s == 'debug'
|
195
|
+
body = if @json
|
196
|
+
MultiJson.encode( @json, :pretty => Configuration.pretty)
|
197
|
+
else
|
198
|
+
MultiJson.encode( MultiJson.load(@response.body), :pretty => Configuration.pretty) rescue ''
|
199
|
+
end
|
200
|
+
else
|
201
|
+
body = ''
|
202
|
+
end
|
203
|
+
|
204
|
+
Configuration.logger.log_response code || 'N/A', took || 'N/A', body || 'N/A'
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
end
|
209
|
+
|
210
|
+
end
|
211
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module Tire
|
2
|
+
module Search
|
3
|
+
|
4
|
+
#--
|
5
|
+
# TODO: Implement all elastic search facets (geo, histogram, range, etc)
|
6
|
+
# http://elasticsearch.org/guide/reference/api/search/facets/
|
7
|
+
#++
|
8
|
+
|
9
|
+
class Facet
|
10
|
+
|
11
|
+
def initialize(name, options={}, &block)
|
12
|
+
@name = name
|
13
|
+
@options = options
|
14
|
+
@value = {}
|
15
|
+
block.arity < 1 ? self.instance_eval(&block) : block.call(self) if block_given?
|
16
|
+
end
|
17
|
+
|
18
|
+
def terms(field, options={})
|
19
|
+
size = options.delete(:size) || 10
|
20
|
+
all_terms = options.delete(:all_terms) || false
|
21
|
+
@value[:terms] = if field.is_a?(Enumerable) and not field.is_a?(String)
|
22
|
+
{ :fields => field }.update({ :size => size, :all_terms => all_terms }).update(options)
|
23
|
+
else
|
24
|
+
{ :field => field }.update({ :size => size, :all_terms => all_terms }).update(options)
|
25
|
+
end
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
def date(field, options={})
|
30
|
+
interval = { :interval => options.delete(:interval) || 'day' }
|
31
|
+
fields = options[:value_field] || options[:value_script] ? { :key_field => field } : { :field => field }
|
32
|
+
@value[:date_histogram] = {}.update(fields).update(interval).update(options)
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
def range(field, ranges=[], options={})
|
37
|
+
@value[:range] = { :field => field, :ranges => ranges }.update(options)
|
38
|
+
self
|
39
|
+
end
|
40
|
+
|
41
|
+
def histogram(field, options={})
|
42
|
+
@value[:histogram] = (options.delete(:histogram) || {:field => field}.update(options))
|
43
|
+
self
|
44
|
+
end
|
45
|
+
|
46
|
+
def statistical(field, options={})
|
47
|
+
@value[:statistical] = (options.delete(:statistical) || {:field => field}.update(options))
|
48
|
+
self
|
49
|
+
end
|
50
|
+
|
51
|
+
def terms_stats(key_field, value_field, options={})
|
52
|
+
@value[:terms_stats] = {:key_field => key_field, :value_field => value_field}.update(options)
|
53
|
+
self
|
54
|
+
end
|
55
|
+
|
56
|
+
def query(&block)
|
57
|
+
@value[:query] = Query.new(&block).to_hash
|
58
|
+
end
|
59
|
+
|
60
|
+
def filter(type, options={})
|
61
|
+
@value[:filter] = Filter.new(type, options)
|
62
|
+
self
|
63
|
+
end
|
64
|
+
|
65
|
+
def facet_filter(type, *options)
|
66
|
+
@value[:facet_filter] = Filter.new(type, *options).to_hash
|
67
|
+
self
|
68
|
+
end
|
69
|
+
|
70
|
+
def to_json(options={})
|
71
|
+
to_hash.to_json
|
72
|
+
end
|
73
|
+
|
74
|
+
def to_hash
|
75
|
+
@value.update @options
|
76
|
+
{ @name => @value }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|