load_balanced_tire 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/.gitignore +14 -0
  2. data/.travis.yml +29 -0
  3. data/Gemfile +4 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.markdown +760 -0
  6. data/Rakefile +78 -0
  7. data/examples/rails-application-template.rb +249 -0
  8. data/examples/tire-dsl.rb +876 -0
  9. data/lib/tire.rb +55 -0
  10. data/lib/tire/alias.rb +296 -0
  11. data/lib/tire/configuration.rb +30 -0
  12. data/lib/tire/dsl.rb +43 -0
  13. data/lib/tire/http/client.rb +62 -0
  14. data/lib/tire/http/clients/curb.rb +61 -0
  15. data/lib/tire/http/clients/faraday.rb +71 -0
  16. data/lib/tire/http/response.rb +27 -0
  17. data/lib/tire/index.rb +361 -0
  18. data/lib/tire/logger.rb +60 -0
  19. data/lib/tire/model/callbacks.rb +40 -0
  20. data/lib/tire/model/import.rb +26 -0
  21. data/lib/tire/model/indexing.rb +128 -0
  22. data/lib/tire/model/naming.rb +100 -0
  23. data/lib/tire/model/percolate.rb +99 -0
  24. data/lib/tire/model/persistence.rb +71 -0
  25. data/lib/tire/model/persistence/attributes.rb +143 -0
  26. data/lib/tire/model/persistence/finders.rb +66 -0
  27. data/lib/tire/model/persistence/storage.rb +69 -0
  28. data/lib/tire/model/search.rb +307 -0
  29. data/lib/tire/results/collection.rb +114 -0
  30. data/lib/tire/results/item.rb +86 -0
  31. data/lib/tire/results/pagination.rb +54 -0
  32. data/lib/tire/rubyext/hash.rb +8 -0
  33. data/lib/tire/rubyext/ruby_1_8.rb +7 -0
  34. data/lib/tire/rubyext/symbol.rb +11 -0
  35. data/lib/tire/search.rb +188 -0
  36. data/lib/tire/search/facet.rb +74 -0
  37. data/lib/tire/search/filter.rb +28 -0
  38. data/lib/tire/search/highlight.rb +37 -0
  39. data/lib/tire/search/query.rb +186 -0
  40. data/lib/tire/search/scan.rb +114 -0
  41. data/lib/tire/search/script_field.rb +23 -0
  42. data/lib/tire/search/sort.rb +25 -0
  43. data/lib/tire/tasks.rb +135 -0
  44. data/lib/tire/utils.rb +17 -0
  45. data/lib/tire/version.rb +22 -0
  46. data/test/fixtures/articles/1.json +1 -0
  47. data/test/fixtures/articles/2.json +1 -0
  48. data/test/fixtures/articles/3.json +1 -0
  49. data/test/fixtures/articles/4.json +1 -0
  50. data/test/fixtures/articles/5.json +1 -0
  51. data/test/integration/active_model_indexing_test.rb +51 -0
  52. data/test/integration/active_model_searchable_test.rb +114 -0
  53. data/test/integration/active_record_searchable_test.rb +446 -0
  54. data/test/integration/boolean_queries_test.rb +43 -0
  55. data/test/integration/count_test.rb +34 -0
  56. data/test/integration/custom_score_queries_test.rb +88 -0
  57. data/test/integration/dis_max_queries_test.rb +68 -0
  58. data/test/integration/dsl_search_test.rb +22 -0
  59. data/test/integration/explanation_test.rb +44 -0
  60. data/test/integration/facets_test.rb +259 -0
  61. data/test/integration/filtered_queries_test.rb +66 -0
  62. data/test/integration/filters_test.rb +63 -0
  63. data/test/integration/fuzzy_queries_test.rb +20 -0
  64. data/test/integration/highlight_test.rb +64 -0
  65. data/test/integration/index_aliases_test.rb +122 -0
  66. data/test/integration/index_mapping_test.rb +43 -0
  67. data/test/integration/index_store_test.rb +96 -0
  68. data/test/integration/index_update_document_test.rb +111 -0
  69. data/test/integration/mongoid_searchable_test.rb +309 -0
  70. data/test/integration/percolator_test.rb +111 -0
  71. data/test/integration/persistent_model_test.rb +130 -0
  72. data/test/integration/prefix_query_test.rb +43 -0
  73. data/test/integration/query_return_version_test.rb +70 -0
  74. data/test/integration/query_string_test.rb +52 -0
  75. data/test/integration/range_queries_test.rb +36 -0
  76. data/test/integration/reindex_test.rb +46 -0
  77. data/test/integration/results_test.rb +39 -0
  78. data/test/integration/scan_test.rb +56 -0
  79. data/test/integration/script_fields_test.rb +38 -0
  80. data/test/integration/sort_test.rb +36 -0
  81. data/test/integration/text_query_test.rb +39 -0
  82. data/test/models/active_model_article.rb +31 -0
  83. data/test/models/active_model_article_with_callbacks.rb +49 -0
  84. data/test/models/active_model_article_with_custom_document_type.rb +7 -0
  85. data/test/models/active_model_article_with_custom_index_name.rb +7 -0
  86. data/test/models/active_record_models.rb +122 -0
  87. data/test/models/article.rb +15 -0
  88. data/test/models/mongoid_models.rb +97 -0
  89. data/test/models/persistent_article.rb +11 -0
  90. data/test/models/persistent_article_in_namespace.rb +12 -0
  91. data/test/models/persistent_article_with_casting.rb +28 -0
  92. data/test/models/persistent_article_with_defaults.rb +11 -0
  93. data/test/models/persistent_articles_with_custom_index_name.rb +10 -0
  94. data/test/models/supermodel_article.rb +17 -0
  95. data/test/models/validated_model.rb +11 -0
  96. data/test/test_helper.rb +93 -0
  97. data/test/unit/active_model_lint_test.rb +17 -0
  98. data/test/unit/configuration_test.rb +74 -0
  99. data/test/unit/http_client_test.rb +76 -0
  100. data/test/unit/http_response_test.rb +49 -0
  101. data/test/unit/index_alias_test.rb +275 -0
  102. data/test/unit/index_test.rb +894 -0
  103. data/test/unit/logger_test.rb +125 -0
  104. data/test/unit/model_callbacks_test.rb +116 -0
  105. data/test/unit/model_import_test.rb +71 -0
  106. data/test/unit/model_persistence_test.rb +528 -0
  107. data/test/unit/model_search_test.rb +913 -0
  108. data/test/unit/results_collection_test.rb +281 -0
  109. data/test/unit/results_item_test.rb +162 -0
  110. data/test/unit/rubyext_test.rb +66 -0
  111. data/test/unit/search_facet_test.rb +153 -0
  112. data/test/unit/search_filter_test.rb +42 -0
  113. data/test/unit/search_highlight_test.rb +46 -0
  114. data/test/unit/search_query_test.rb +301 -0
  115. data/test/unit/search_scan_test.rb +113 -0
  116. data/test/unit/search_script_field_test.rb +26 -0
  117. data/test/unit/search_sort_test.rb +50 -0
  118. data/test/unit/search_test.rb +499 -0
  119. data/test/unit/tire_test.rb +126 -0
  120. data/tire.gemspec +90 -0
  121. metadata +549 -0
@@ -0,0 +1,111 @@
1
+ require 'test_helper'
2
+
3
+ module Tire
4
+
5
+ class IndexUpdateDocumentIntegrationTest < Test::Unit::TestCase
6
+ include Test::Integration
7
+
8
+ context "Updating a document" do
9
+
10
+ setup do
11
+ Tire.index 'articles-with-tags' do
12
+ delete
13
+ create
14
+
15
+ store :type => 'article', :id => 1, :title => 'One', :tags => ['foo'], :views => 0
16
+ store :type => 'article', :id => 2, :title => 'Two', :tags => ['foo', 'bar'], :views => 10
17
+ store :type => 'article', :id => 3, :title => 'Three', :tags => ['foobar']
18
+
19
+ refresh
20
+ end
21
+ end
22
+
23
+ teardown { Tire.index('articles-with-tags').delete }
24
+
25
+ should "increment a counter" do
26
+ Tire.index('articles-with-tags') { update( 'article', '1', :script => "ctx._source.views += 1" ) and refresh }
27
+
28
+ document = Tire.search('articles-with-tags') { query { string 'title:one' } }.results.first
29
+ assert_equal 1, document.views, document.inspect
30
+
31
+ Tire.index('articles-with-tags') { update( 'article', '2', :script => "ctx._source.views += 1" ) and refresh }
32
+
33
+ document = Tire.search('articles-with-tags') { query { string 'title:two' } }.results.first
34
+ assert_equal 11, document.views, document.inspect
35
+ end
36
+
37
+ should "add a tag to document" do
38
+ Tire.index('articles-with-tags') do
39
+ update 'article', '1', :script => "ctx._source.tags += tag",
40
+ :params => { :tag => 'new' }
41
+ refresh
42
+ end
43
+
44
+ document = Tire.search('articles-with-tags') { query { string 'title:one' } }.results.first
45
+ assert_equal ['foo', 'new'], document.tags, document.inspect
46
+ end
47
+
48
+ should "remove a tag from document" do
49
+ Tire.index('articles-with-tags') do
50
+ update 'article', '1', :script => "ctx._source.tags = tags",
51
+ :params => { :tags => [] }
52
+ refresh
53
+ end
54
+
55
+ document = Tire.index('articles-with-tags').retrieve 'article', '1'
56
+ assert_equal [], document.tags, document.inspect
57
+ end
58
+
59
+ should "remove the entire document if specific condition is met" do
60
+ Tire.index('articles-with-tags') do
61
+ # Remove document when it contains tag 'foobar'
62
+ update 'article', '3', :script => "ctx._source.tags.contains(tag) ? ctx.op = 'delete' : 'none'",
63
+ :params => { :tag => 'foobar' }
64
+ refresh
65
+ end
66
+
67
+ assert_nil Tire.index('articles-with-tags').retrieve 'article', '3'
68
+ end
69
+
70
+ should "pass the operation parameters to the API" do
71
+ Tire.index('articles-with-tags').update 'article', '2', { :script => "ctx._source.tags += tag",
72
+ :params => { :tag => 'new' }
73
+ },
74
+ {
75
+ :refresh => true
76
+ }
77
+
78
+ document = Tire.search('articles-with-tags') { query { string 'title:two' } }.results.first
79
+ assert_equal 3, document.tags.size, document.inspect
80
+ end
81
+
82
+ should "access variables from the outer scope" do
83
+ $t = self
84
+
85
+ class Updater
86
+ @tags = ['foo', 'bar', 'baz']
87
+
88
+ def self.perform_update!
89
+ $t.assert_not_nil @tags
90
+
91
+ Tire.index('articles-with-tags') do |index|
92
+ $t.assert_not_nil @tags
93
+
94
+ index.update 'article', '3', :script => "ctx._source.tags = tags",
95
+ :params => { :tags => @tags }
96
+ index.refresh
97
+ end
98
+ end
99
+ end
100
+
101
+ Updater.perform_update!
102
+
103
+ document = Tire.search('articles-with-tags') { query { string 'title:three' } }.results.first
104
+ assert_equal 3, document.tags.size, document.inspect
105
+ end
106
+
107
+ end
108
+
109
+ end
110
+
111
+ end
@@ -0,0 +1,309 @@
1
+ require 'test_helper'
2
+ require File.expand_path('../../models/mongoid_models', __FILE__)
3
+
4
+ begin
5
+ require "mongo"
6
+ Mongo::Connection.new("localhost", 27017)
7
+
8
+ ENV["MONGODB_IS_AVAILABLE"] = 'true'
9
+ rescue Mongo::ConnectionFailure => e
10
+ ENV["MONGODB_IS_AVAILABLE"] = nil
11
+ end
12
+
13
+ if ENV["MONGODB_IS_AVAILABLE"]
14
+ module Tire
15
+
16
+ class MongoidSearchableIntegrationTest < Test::Unit::TestCase
17
+ include Test::Integration
18
+
19
+ def setup
20
+ super
21
+ Mongoid.configure do |config|
22
+ config.master = Mongo::Connection.new.db("tire_mongoid_integration_test")
23
+ end
24
+ end
25
+
26
+ context "Mongoid integration" do
27
+
28
+ setup do
29
+ MongoidArticle.destroy_all
30
+ Tire.index('mongoid_articles').delete
31
+
32
+ load File.expand_path('../../models/mongoid_models.rb', __FILE__)
33
+ end
34
+ teardown do
35
+ MongoidArticle.destroy_all
36
+ Tire.index('mongoid_articles').delete
37
+ end
38
+
39
+ should "configure mapping" do
40
+ assert_equal 'snowball', MongoidArticle.mapping[:title][:analyzer]
41
+ assert_equal 10, MongoidArticle.mapping[:title][:boost]
42
+
43
+ assert_equal 'snowball', MongoidArticle.tire.index.mapping['mongoid_article']['properties']['title']['analyzer']
44
+ end
45
+
46
+ should "save document into index on save and find it" do
47
+ a = MongoidArticle.new :title => 'Test'
48
+ a.save!
49
+ id = a.id
50
+
51
+ a.index.refresh
52
+
53
+ results = MongoidArticle.tire.search 'test'
54
+
55
+ assert results.any?
56
+ assert_equal 1, results.count
57
+
58
+ assert_instance_of Results::Item, results.first
59
+ assert_not_nil results.first.id
60
+ assert_equal id.to_s, results.first.id.to_s
61
+ assert results.first.persisted?, "Record should be persisted"
62
+ assert_not_nil results.first._score
63
+ assert_equal 'Test', results.first.title
64
+ end
65
+
66
+ context "with eager loading" do
67
+ setup do
68
+ MongoidArticle.destroy_all
69
+
70
+ @first_article = MongoidArticle.create! :title => "Test 1"
71
+ @second_article = MongoidArticle.create! :title => "Test 2"
72
+ @third_article = MongoidArticle.create! :title => "Test 3"
73
+ @fourth_article = MongoidArticle.create! :title => "Test 4"
74
+ @fifth_article = MongoidArticle.create! :title => "Test 5"
75
+
76
+ MongoidArticle.tire.index.refresh
77
+ end
78
+
79
+ should "load records on query search" do
80
+ results = MongoidArticle.tire.search '"Test 1"', :load => true
81
+
82
+ assert results.any?
83
+ assert_equal MongoidArticle.all.first, results.first
84
+ end
85
+
86
+ should "load records on block search" do
87
+ results = MongoidArticle.tire.search :load => true do
88
+ query { string '"Test 1"' }
89
+ end
90
+
91
+ assert_equal MongoidArticle.all.first, results.first
92
+ end
93
+
94
+ should "load records with options on query search" do
95
+ assert_equal MongoidArticle.find([@first_article[:_id]], :include => 'comments').first,
96
+ MongoidArticle.tire.search('"Test 1"',
97
+ :load => { :include => 'comments' }).results.first
98
+ end
99
+
100
+ should "return empty collection for nonmatching query" do
101
+ assert_nothing_raised do
102
+ results = MongoidArticle.tire.search :load => true do
103
+ query { string '"Hic Sunt Leones"' }
104
+ end
105
+ assert_equal 0, results.size
106
+ assert !results.any?
107
+ end
108
+ end
109
+ end
110
+
111
+ should "remove document from index on destroy" do
112
+ a = MongoidArticle.new :title => 'Test remove...'
113
+ a.save!
114
+ assert_equal 1, MongoidArticle.count
115
+
116
+ a.destroy
117
+ assert_equal 0, MongoidArticle.all.size
118
+
119
+ a.index.refresh
120
+ results = MongoidArticle.tire.search 'test'
121
+ assert_equal 0, results.count
122
+ end
123
+
124
+ should "return documents with scores" do
125
+ MongoidArticle.create! :title => 'foo'
126
+ MongoidArticle.create! :title => 'bar'
127
+
128
+ MongoidArticle.tire.index.refresh
129
+ results = MongoidArticle.tire.search 'foo OR bar^100'
130
+ assert_equal 2, results.count
131
+
132
+ assert_equal 'bar', results.first.title
133
+ end
134
+
135
+ context "with pagination" do
136
+ setup do
137
+ 1.upto(9) { |number| MongoidArticle.create :title => "Test#{number}" }
138
+ MongoidArticle.tire.index.refresh
139
+ end
140
+
141
+ context "and parameter searches" do
142
+
143
+ should "find first page with five results" do
144
+ results = MongoidArticle.tire.search 'test*', :sort => 'title', :per_page => 5, :page => 1
145
+ assert_equal 5, results.size
146
+
147
+ assert_equal 2, results.total_pages
148
+ assert_equal 1, results.current_page
149
+ assert_equal nil, results.previous_page
150
+ assert_equal 2, results.next_page
151
+
152
+ assert_equal 'Test1', results.first.title
153
+ end
154
+
155
+ should "find next page with five results" do
156
+ results = MongoidArticle.tire.search 'test*', :sort => 'title', :per_page => 5, :page => 2
157
+ assert_equal 4, results.size
158
+
159
+ assert_equal 2, results.total_pages
160
+ assert_equal 2, results.current_page
161
+ assert_equal 1, results.previous_page
162
+ assert_equal nil, results.next_page
163
+
164
+ assert_equal 'Test6', results.first.title
165
+ end
166
+
167
+ should "find not find missing page" do
168
+ results = MongoidArticle.tire.search 'test*', :sort => 'title', :per_page => 5, :page => 3
169
+ assert_equal 0, results.size
170
+
171
+ assert_equal 2, results.total_pages
172
+ assert_equal 3, results.current_page
173
+ assert_equal 2, results.previous_page
174
+ assert_equal nil, results.next_page
175
+
176
+ assert_nil results.first
177
+ end
178
+
179
+ end
180
+
181
+ context "and block searches" do
182
+ setup { @q = 'test*' }
183
+
184
+ should "find first page with five results" do
185
+ results = MongoidArticle.tire.search do |search|
186
+ search.query { |query| query.string @q }
187
+ search.sort { by :title }
188
+ search.from 0
189
+ search.size 5
190
+ end
191
+ assert_equal 5, results.size
192
+
193
+ assert_equal 2, results.total_pages
194
+ assert_equal 1, results.current_page
195
+ assert_equal nil, results.previous_page
196
+ assert_equal 2, results.next_page
197
+
198
+ assert_equal 'Test1', results.first.title
199
+ end
200
+
201
+ should "find next page with five results" do
202
+ results = MongoidArticle.tire.search do |search|
203
+ search.query { |query| query.string @q }
204
+ search.sort { by :title }
205
+ search.from 5
206
+ search.size 5
207
+ end
208
+ assert_equal 4, results.size
209
+
210
+ assert_equal 2, results.total_pages
211
+ assert_equal 2, results.current_page
212
+ assert_equal 1, results.previous_page
213
+ assert_equal nil, results.next_page
214
+
215
+ assert_equal 'Test6', results.first.title
216
+ end
217
+
218
+ should "not find a missing page" do
219
+ results = MongoidArticle.tire.search do |search|
220
+ search.query { |query| query.string @q }
221
+ search.sort { by :title }
222
+ search.from 10
223
+ search.size 5
224
+ end
225
+ assert_equal 0, results.size
226
+
227
+ assert_equal 2, results.total_pages
228
+ assert_equal 3, results.current_page
229
+ assert_equal 2, results.previous_page
230
+ assert_equal nil, results.next_page
231
+
232
+ assert_nil results.first
233
+ end
234
+
235
+ end
236
+
237
+ end
238
+
239
+ context "with proxy" do
240
+
241
+ should "allow access to Tire instance methods" do
242
+ a = MongoidClassWithTireMethods.create :title => 'One'
243
+ assert_equal "THIS IS MY INDEX!", a.index
244
+ assert_instance_of Tire::Index, a.tire.index
245
+ assert a.tire.index.exists?, "Index should exist"
246
+ end
247
+
248
+ should "allow access to Tire class methods" do
249
+ class ::MongoidClassWithTireMethods
250
+ include Mongoid::Document
251
+ def self.search(*)
252
+ "THIS IS MY SEARCH!"
253
+ end
254
+ end
255
+
256
+ MongoidClassWithTireMethods.create :title => 'One'
257
+ MongoidClassWithTireMethods.tire.index.refresh
258
+
259
+ assert_equal "THIS IS MY SEARCH!", MongoidClassWithTireMethods.search
260
+
261
+ results = MongoidClassWithTireMethods.tire.search 'one'
262
+
263
+ assert_equal 'One', results.first.title
264
+ end
265
+
266
+ end
267
+
268
+ context "within Rails" do
269
+
270
+ setup do
271
+ module ::Rails; end
272
+
273
+ a = MongoidArticle.new :title => 'Test'
274
+ c = a.comments.build :author => 'fool', :body => 'Works!'
275
+ s = a.stats.build :pageviews => 12, :period => '2011-08'
276
+ a.save!
277
+ c.save!
278
+ s.save!
279
+ @id = a.id.to_s
280
+
281
+ a.index.refresh
282
+ @item = MongoidArticle.tire.search('test').first
283
+ end
284
+
285
+ should "have access to indexed properties" do
286
+ assert_equal 'Test', @item.title
287
+ assert_equal 'fool', @item.comments.first.author
288
+ assert_equal 12, @item.stats.first.pageviews
289
+ end
290
+
291
+ should "load the underlying models" do
292
+ assert_instance_of Results::Item, @item
293
+ assert_instance_of MongoidArticle, @item.load
294
+ assert_equal 'Test', @item.load.title
295
+
296
+ assert_instance_of Results::Item, @item.comments.first
297
+ assert_instance_of MongoidComment, @item.comments.first.load
298
+ assert_equal 'fool', @item.comments.first.load.author
299
+ end
300
+
301
+ should "load the underlying model with options" do
302
+ assert_equal MongoidArticle.find(@id), @item.load(:include => 'comments')
303
+ end
304
+
305
+ end
306
+ end
307
+ end
308
+ end
309
+ end
@@ -0,0 +1,111 @@
1
+ require 'test_helper'
2
+
3
+ module Tire
4
+
5
+ class PercolatorIntegrationTest < Test::Unit::TestCase
6
+ include Test::Integration
7
+
8
+ context "Percolator" do
9
+ setup do
10
+ delete_registered_queries
11
+ @index = Tire.index('percolator-test')
12
+ @index.create
13
+ end
14
+ teardown do
15
+ delete_registered_queries
16
+ @index.delete
17
+ end
18
+
19
+ context "when registering a query" do
20
+ should "register query as a Hash" do
21
+ query = { :query => { :query_string => { :query => 'warning' } } }
22
+ assert @index.register_percolator_query('alert', query)
23
+ Tire.index('_percolator').refresh
24
+
25
+ percolator = Configuration.client.get("#{Configuration.url}/_percolator/percolator-test/alert")
26
+ assert percolator
27
+ end
28
+
29
+ should "register query as block" do
30
+ assert @index.register_percolator_query('alert') { string 'warning' }
31
+ Tire.index('_percolator').refresh
32
+
33
+ percolator = Configuration.client.get("#{Configuration.url}/_percolator/percolator-test/alert")
34
+ assert percolator
35
+ end
36
+
37
+ should "unregister a query" do
38
+ query = { :query => { :query_string => { :query => 'warning' } } }
39
+ assert @index.register_percolator_query('alert', query)
40
+ Tire.index('_percolator').refresh
41
+ assert Configuration.client.get("#{Configuration.url}/_percolator/percolator-test/alert")
42
+
43
+ assert @index.unregister_percolator_query('alert')
44
+ Tire.index('_percolator').refresh
45
+
46
+ assert Configuration.client.get("#{Configuration.url}/_percolator/percolator-test/alert").failure?
47
+ end
48
+
49
+ end
50
+
51
+ context "when percolating a document" do
52
+ setup do
53
+ @index.register_percolator_query('alert') { string 'warning' }
54
+ @index.register_percolator_query('gantz') { string '"y u no match"' }
55
+ @index.register_percolator_query('weather', :tags => ['weather']) { string 'severe' }
56
+ Tire.index('_percolator').refresh
57
+ end
58
+
59
+ should "return an empty array when no query matches" do
60
+ matches = @index.percolate :message => 'Situation normal'
61
+ assert_equal [], matches
62
+ end
63
+
64
+ should "return an array of matching query names" do
65
+ matches = @index.percolate :message => 'Severe weather warning'
66
+ assert_equal ['alert','weather'], matches.sort
67
+ end
68
+
69
+ should "return an array of matching query names for specific percolated queries" do
70
+ matches = @index.percolate(:message => 'Severe weather warning') { term :tags, 'weather' }
71
+ assert_equal ['weather'], matches
72
+ end
73
+ end
74
+
75
+ context "when storing document and percolating it" do
76
+ setup do
77
+ @index.register_percolator_query('alert') { string 'warning' }
78
+ @index.register_percolator_query('gantz') { string '"y u no match"' }
79
+ @index.register_percolator_query('weather', :tags => ['weather']) { string 'severe' }
80
+ Tire.index('_percolator').refresh
81
+ end
82
+
83
+ should "return an empty array when no query matches" do
84
+ response = @index.store( {:message => 'Situation normal'}, {:percolate => true} )
85
+ assert_equal [], response['matches']
86
+ end
87
+
88
+ should "return an array of matching query names" do
89
+ response = @index.store( {:message => 'Severe weather warning'}, {:percolate => true} )
90
+ assert_equal ['alert','weather'], response['matches'].sort
91
+ end
92
+
93
+ should "return an array of matching query names for specific percolated queries" do
94
+ response = @index.store( {:message => 'Severe weather warning'}, {:percolate => 'tags:weather'} )
95
+ assert_equal ['weather'], response['matches']
96
+ end
97
+ end
98
+
99
+ end
100
+
101
+ private
102
+
103
+ def delete_registered_queries
104
+ Configuration.client.get("#{Configuration.url}/_percolator/percolator-test/alert") rescue nil
105
+ Configuration.client.get("#{Configuration.url}/_percolator/percolator-test/gantz") rescue nil
106
+ Configuration.client.get("#{Configuration.url}/_percolator/percolator-test/weather") rescue nil
107
+ end
108
+
109
+ end
110
+
111
+ end