tire 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/.gitignore +9 -0
  2. data/Gemfile +4 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.markdown +435 -0
  5. data/Rakefile +75 -0
  6. data/examples/dsl.rb +73 -0
  7. data/examples/rails-application-template.rb +144 -0
  8. data/examples/tire-dsl.rb +617 -0
  9. data/lib/tire.rb +35 -0
  10. data/lib/tire/client.rb +40 -0
  11. data/lib/tire/configuration.rb +29 -0
  12. data/lib/tire/dsl.rb +33 -0
  13. data/lib/tire/index.rb +209 -0
  14. data/lib/tire/logger.rb +60 -0
  15. data/lib/tire/model/callbacks.rb +23 -0
  16. data/lib/tire/model/import.rb +18 -0
  17. data/lib/tire/model/indexing.rb +50 -0
  18. data/lib/tire/model/naming.rb +30 -0
  19. data/lib/tire/model/persistence.rb +34 -0
  20. data/lib/tire/model/persistence/attributes.rb +60 -0
  21. data/lib/tire/model/persistence/finders.rb +61 -0
  22. data/lib/tire/model/persistence/storage.rb +75 -0
  23. data/lib/tire/model/search.rb +97 -0
  24. data/lib/tire/results/collection.rb +56 -0
  25. data/lib/tire/results/item.rb +39 -0
  26. data/lib/tire/results/pagination.rb +30 -0
  27. data/lib/tire/rubyext/hash.rb +3 -0
  28. data/lib/tire/rubyext/symbol.rb +11 -0
  29. data/lib/tire/search.rb +117 -0
  30. data/lib/tire/search/facet.rb +41 -0
  31. data/lib/tire/search/filter.rb +28 -0
  32. data/lib/tire/search/highlight.rb +37 -0
  33. data/lib/tire/search/query.rb +42 -0
  34. data/lib/tire/search/sort.rb +29 -0
  35. data/lib/tire/tasks.rb +88 -0
  36. data/lib/tire/version.rb +3 -0
  37. data/test/fixtures/articles/1.json +1 -0
  38. data/test/fixtures/articles/2.json +1 -0
  39. data/test/fixtures/articles/3.json +1 -0
  40. data/test/fixtures/articles/4.json +1 -0
  41. data/test/fixtures/articles/5.json +1 -0
  42. data/test/integration/active_model_searchable_test.rb +80 -0
  43. data/test/integration/active_record_searchable_test.rb +193 -0
  44. data/test/integration/facets_test.rb +65 -0
  45. data/test/integration/filters_test.rb +46 -0
  46. data/test/integration/highlight_test.rb +52 -0
  47. data/test/integration/index_mapping_test.rb +44 -0
  48. data/test/integration/index_store_test.rb +68 -0
  49. data/test/integration/persistent_model_test.rb +35 -0
  50. data/test/integration/query_string_test.rb +43 -0
  51. data/test/integration/results_test.rb +28 -0
  52. data/test/integration/sort_test.rb +36 -0
  53. data/test/models/active_model_article.rb +31 -0
  54. data/test/models/active_model_article_with_callbacks.rb +49 -0
  55. data/test/models/active_model_article_with_custom_index_name.rb +5 -0
  56. data/test/models/active_record_article.rb +12 -0
  57. data/test/models/article.rb +15 -0
  58. data/test/models/persistent_article.rb +11 -0
  59. data/test/models/persistent_articles_with_custom_index_name.rb +10 -0
  60. data/test/models/supermodel_article.rb +22 -0
  61. data/test/models/validated_model.rb +11 -0
  62. data/test/test_helper.rb +52 -0
  63. data/test/unit/active_model_lint_test.rb +17 -0
  64. data/test/unit/client_test.rb +43 -0
  65. data/test/unit/configuration_test.rb +71 -0
  66. data/test/unit/index_test.rb +390 -0
  67. data/test/unit/logger_test.rb +114 -0
  68. data/test/unit/model_callbacks_test.rb +90 -0
  69. data/test/unit/model_import_test.rb +71 -0
  70. data/test/unit/model_persistence_test.rb +400 -0
  71. data/test/unit/model_search_test.rb +289 -0
  72. data/test/unit/results_collection_test.rb +131 -0
  73. data/test/unit/results_item_test.rb +59 -0
  74. data/test/unit/rubyext_hash_test.rb +19 -0
  75. data/test/unit/search_facet_test.rb +69 -0
  76. data/test/unit/search_filter_test.rb +36 -0
  77. data/test/unit/search_highlight_test.rb +46 -0
  78. data/test/unit/search_query_test.rb +55 -0
  79. data/test/unit/search_sort_test.rb +50 -0
  80. data/test/unit/search_test.rb +204 -0
  81. data/test/unit/tire_test.rb +55 -0
  82. data/tire.gemspec +54 -0
  83. metadata +372 -0
@@ -0,0 +1,55 @@
1
+ require 'test_helper'
2
+
3
+ module Tire
4
+
5
+ class TireTest < Test::Unit::TestCase
6
+
7
+ context "Tire" do
8
+
9
+ should "have the DSL methods available" do
10
+ assert_respond_to Tire, :search
11
+ assert_respond_to Tire, :index
12
+ assert_respond_to Tire, :configure
13
+ end
14
+
15
+ context "DSL" do
16
+
17
+ should "allow searching with a block" do
18
+ Search::Search.expects(:new).returns( stub(:perform => true) )
19
+
20
+ Tire.search 'dummy' do
21
+ query 'foo'
22
+ end
23
+ end
24
+
25
+ should "allow searching with a Ruby Hash" do
26
+ Tire::Configuration.client.expects(:post).
27
+ with('http://localhost:9200/dummy/_search','{"query":{"query_string":{"query":"foo"}}}').
28
+ returns( stub(:body => '{}') )
29
+ Tire::Results::Collection.expects(:new)
30
+
31
+ Tire.search 'dummy', :query => { :query_string => { :query => 'foo' }}
32
+ end
33
+
34
+ should "allow searching with a JSON string" do
35
+ Tire::Configuration.client.expects(:post).
36
+ with('http://localhost:9200/dummy/_search','{"query":{"query_string":{"query":"foo"}}}').
37
+ returns( stub(:body => '{}') )
38
+ Tire::Results::Collection.expects(:new)
39
+
40
+ Tire.search 'dummy', '{"query":{"query_string":{"query":"foo"}}}'
41
+ end
42
+
43
+ should "raise an error when passed incorrect payload" do
44
+ assert_raise(ArgumentError) do
45
+ Tire.search 'dummy', 1
46
+ end
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -0,0 +1,54 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "tire/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "tire"
7
+ s.version = Tire::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.summary = "Ruby client for ElasticSearch"
10
+ s.homepage = "http://github.com/karmi/tire"
11
+ s.authors = [ 'Karel Minarik' ]
12
+ s.email = 'karmi@karmi.cz'
13
+
14
+ s.rubyforge_project = "tire"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+
20
+ s.require_paths = ["lib"]
21
+
22
+ s.extra_rdoc_files = [ "README.markdown", "MIT-LICENSE" ]
23
+ s.rdoc_options = [ "--charset=UTF-8" ]
24
+
25
+ s.required_rubygems_version = ">= 1.3.6"
26
+
27
+ s.add_dependency "rake", "~> 0.8.0"
28
+ s.add_dependency "bundler", "~> 1.0.0"
29
+ s.add_dependency "rest-client", "~> 1.6.0"
30
+ s.add_dependency "yajl-ruby", "> 0.8.0"
31
+ s.add_dependency "activemodel", "> 3.0.0"
32
+
33
+ s.add_development_dependency "turn"
34
+ s.add_development_dependency "shoulda"
35
+ s.add_development_dependency "mocha"
36
+ s.add_development_dependency "sdoc"
37
+ s.add_development_dependency "rcov"
38
+ s.add_development_dependency "activerecord"
39
+ s.add_development_dependency "supermodel"
40
+
41
+ s.description = <<-DESC
42
+ Tire is a Ruby client for the ElasticSearch search engine/database.
43
+
44
+ It provides Ruby-like API for fluent communication with the ElasticSearch server
45
+ and blends with ActiveModel class for convenient usage in Rails applications.
46
+
47
+ It allows to delete and create indices, define mapping for them, supports
48
+ the bulk API, and presents an easy-to-use DSL for constructing your queries.
49
+
50
+ It has full ActiveRecord/ActiveModel compatibility, allowing you to index
51
+ your models (incrementally upon saving, or in bulk), searching and
52
+ paginating the results.
53
+ DESC
54
+ end
metadata ADDED
@@ -0,0 +1,372 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tire
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Karel Minarik
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-05-01 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rake
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 63
30
+ segments:
31
+ - 0
32
+ - 8
33
+ - 0
34
+ version: 0.8.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: bundler
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 23
46
+ segments:
47
+ - 1
48
+ - 0
49
+ - 0
50
+ version: 1.0.0
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: rest-client
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 15
62
+ segments:
63
+ - 1
64
+ - 6
65
+ - 0
66
+ version: 1.6.0
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: yajl-ruby
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">"
76
+ - !ruby/object:Gem::Version
77
+ hash: 63
78
+ segments:
79
+ - 0
80
+ - 8
81
+ - 0
82
+ version: 0.8.0
83
+ type: :runtime
84
+ version_requirements: *id004
85
+ - !ruby/object:Gem::Dependency
86
+ name: activemodel
87
+ prerelease: false
88
+ requirement: &id005 !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">"
92
+ - !ruby/object:Gem::Version
93
+ hash: 7
94
+ segments:
95
+ - 3
96
+ - 0
97
+ - 0
98
+ version: 3.0.0
99
+ type: :runtime
100
+ version_requirements: *id005
101
+ - !ruby/object:Gem::Dependency
102
+ name: turn
103
+ prerelease: false
104
+ requirement: &id006 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
112
+ version: "0"
113
+ type: :development
114
+ version_requirements: *id006
115
+ - !ruby/object:Gem::Dependency
116
+ name: shoulda
117
+ prerelease: false
118
+ requirement: &id007 !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ hash: 3
124
+ segments:
125
+ - 0
126
+ version: "0"
127
+ type: :development
128
+ version_requirements: *id007
129
+ - !ruby/object:Gem::Dependency
130
+ name: mocha
131
+ prerelease: false
132
+ requirement: &id008 !ruby/object:Gem::Requirement
133
+ none: false
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ hash: 3
138
+ segments:
139
+ - 0
140
+ version: "0"
141
+ type: :development
142
+ version_requirements: *id008
143
+ - !ruby/object:Gem::Dependency
144
+ name: sdoc
145
+ prerelease: false
146
+ requirement: &id009 !ruby/object:Gem::Requirement
147
+ none: false
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ hash: 3
152
+ segments:
153
+ - 0
154
+ version: "0"
155
+ type: :development
156
+ version_requirements: *id009
157
+ - !ruby/object:Gem::Dependency
158
+ name: rcov
159
+ prerelease: false
160
+ requirement: &id010 !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ hash: 3
166
+ segments:
167
+ - 0
168
+ version: "0"
169
+ type: :development
170
+ version_requirements: *id010
171
+ - !ruby/object:Gem::Dependency
172
+ name: activerecord
173
+ prerelease: false
174
+ requirement: &id011 !ruby/object:Gem::Requirement
175
+ none: false
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ hash: 3
180
+ segments:
181
+ - 0
182
+ version: "0"
183
+ type: :development
184
+ version_requirements: *id011
185
+ - !ruby/object:Gem::Dependency
186
+ name: supermodel
187
+ prerelease: false
188
+ requirement: &id012 !ruby/object:Gem::Requirement
189
+ none: false
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ hash: 3
194
+ segments:
195
+ - 0
196
+ version: "0"
197
+ type: :development
198
+ version_requirements: *id012
199
+ description: " Tire is a Ruby client for the ElasticSearch search engine/database.\n\n It provides Ruby-like API for fluent communication with the ElasticSearch server\n and blends with ActiveModel class for convenient usage in Rails applications.\n\n It allows to delete and create indices, define mapping for them, supports\n the bulk API, and presents an easy-to-use DSL for constructing your queries.\n\n It has full ActiveRecord/ActiveModel compatibility, allowing you to index\n your models (incrementally upon saving, or in bulk), searching and\n paginating the results.\n"
200
+ email: karmi@karmi.cz
201
+ executables: []
202
+
203
+ extensions: []
204
+
205
+ extra_rdoc_files:
206
+ - README.markdown
207
+ - MIT-LICENSE
208
+ files:
209
+ - .gitignore
210
+ - Gemfile
211
+ - MIT-LICENSE
212
+ - README.markdown
213
+ - Rakefile
214
+ - examples/dsl.rb
215
+ - examples/rails-application-template.rb
216
+ - examples/tire-dsl.rb
217
+ - lib/tire.rb
218
+ - lib/tire/client.rb
219
+ - lib/tire/configuration.rb
220
+ - lib/tire/dsl.rb
221
+ - lib/tire/index.rb
222
+ - lib/tire/logger.rb
223
+ - lib/tire/model/callbacks.rb
224
+ - lib/tire/model/import.rb
225
+ - lib/tire/model/indexing.rb
226
+ - lib/tire/model/naming.rb
227
+ - lib/tire/model/persistence.rb
228
+ - lib/tire/model/persistence/attributes.rb
229
+ - lib/tire/model/persistence/finders.rb
230
+ - lib/tire/model/persistence/storage.rb
231
+ - lib/tire/model/search.rb
232
+ - lib/tire/results/collection.rb
233
+ - lib/tire/results/item.rb
234
+ - lib/tire/results/pagination.rb
235
+ - lib/tire/rubyext/hash.rb
236
+ - lib/tire/rubyext/symbol.rb
237
+ - lib/tire/search.rb
238
+ - lib/tire/search/facet.rb
239
+ - lib/tire/search/filter.rb
240
+ - lib/tire/search/highlight.rb
241
+ - lib/tire/search/query.rb
242
+ - lib/tire/search/sort.rb
243
+ - lib/tire/tasks.rb
244
+ - lib/tire/version.rb
245
+ - test/fixtures/articles/1.json
246
+ - test/fixtures/articles/2.json
247
+ - test/fixtures/articles/3.json
248
+ - test/fixtures/articles/4.json
249
+ - test/fixtures/articles/5.json
250
+ - test/integration/active_model_searchable_test.rb
251
+ - test/integration/active_record_searchable_test.rb
252
+ - test/integration/facets_test.rb
253
+ - test/integration/filters_test.rb
254
+ - test/integration/highlight_test.rb
255
+ - test/integration/index_mapping_test.rb
256
+ - test/integration/index_store_test.rb
257
+ - test/integration/persistent_model_test.rb
258
+ - test/integration/query_string_test.rb
259
+ - test/integration/results_test.rb
260
+ - test/integration/sort_test.rb
261
+ - test/models/active_model_article.rb
262
+ - test/models/active_model_article_with_callbacks.rb
263
+ - test/models/active_model_article_with_custom_index_name.rb
264
+ - test/models/active_record_article.rb
265
+ - test/models/article.rb
266
+ - test/models/persistent_article.rb
267
+ - test/models/persistent_articles_with_custom_index_name.rb
268
+ - test/models/supermodel_article.rb
269
+ - test/models/validated_model.rb
270
+ - test/test_helper.rb
271
+ - test/unit/active_model_lint_test.rb
272
+ - test/unit/client_test.rb
273
+ - test/unit/configuration_test.rb
274
+ - test/unit/index_test.rb
275
+ - test/unit/logger_test.rb
276
+ - test/unit/model_callbacks_test.rb
277
+ - test/unit/model_import_test.rb
278
+ - test/unit/model_persistence_test.rb
279
+ - test/unit/model_search_test.rb
280
+ - test/unit/results_collection_test.rb
281
+ - test/unit/results_item_test.rb
282
+ - test/unit/rubyext_hash_test.rb
283
+ - test/unit/search_facet_test.rb
284
+ - test/unit/search_filter_test.rb
285
+ - test/unit/search_highlight_test.rb
286
+ - test/unit/search_query_test.rb
287
+ - test/unit/search_sort_test.rb
288
+ - test/unit/search_test.rb
289
+ - test/unit/tire_test.rb
290
+ - tire.gemspec
291
+ has_rdoc: true
292
+ homepage: http://github.com/karmi/tire
293
+ licenses: []
294
+
295
+ post_install_message:
296
+ rdoc_options:
297
+ - --charset=UTF-8
298
+ require_paths:
299
+ - lib
300
+ required_ruby_version: !ruby/object:Gem::Requirement
301
+ none: false
302
+ requirements:
303
+ - - ">="
304
+ - !ruby/object:Gem::Version
305
+ hash: 3
306
+ segments:
307
+ - 0
308
+ version: "0"
309
+ required_rubygems_version: !ruby/object:Gem::Requirement
310
+ none: false
311
+ requirements:
312
+ - - ">="
313
+ - !ruby/object:Gem::Version
314
+ hash: 23
315
+ segments:
316
+ - 1
317
+ - 3
318
+ - 6
319
+ version: 1.3.6
320
+ requirements: []
321
+
322
+ rubyforge_project: tire
323
+ rubygems_version: 1.5.0
324
+ signing_key:
325
+ specification_version: 3
326
+ summary: Ruby client for ElasticSearch
327
+ test_files:
328
+ - test/fixtures/articles/1.json
329
+ - test/fixtures/articles/2.json
330
+ - test/fixtures/articles/3.json
331
+ - test/fixtures/articles/4.json
332
+ - test/fixtures/articles/5.json
333
+ - test/integration/active_model_searchable_test.rb
334
+ - test/integration/active_record_searchable_test.rb
335
+ - test/integration/facets_test.rb
336
+ - test/integration/filters_test.rb
337
+ - test/integration/highlight_test.rb
338
+ - test/integration/index_mapping_test.rb
339
+ - test/integration/index_store_test.rb
340
+ - test/integration/persistent_model_test.rb
341
+ - test/integration/query_string_test.rb
342
+ - test/integration/results_test.rb
343
+ - test/integration/sort_test.rb
344
+ - test/models/active_model_article.rb
345
+ - test/models/active_model_article_with_callbacks.rb
346
+ - test/models/active_model_article_with_custom_index_name.rb
347
+ - test/models/active_record_article.rb
348
+ - test/models/article.rb
349
+ - test/models/persistent_article.rb
350
+ - test/models/persistent_articles_with_custom_index_name.rb
351
+ - test/models/supermodel_article.rb
352
+ - test/models/validated_model.rb
353
+ - test/test_helper.rb
354
+ - test/unit/active_model_lint_test.rb
355
+ - test/unit/client_test.rb
356
+ - test/unit/configuration_test.rb
357
+ - test/unit/index_test.rb
358
+ - test/unit/logger_test.rb
359
+ - test/unit/model_callbacks_test.rb
360
+ - test/unit/model_import_test.rb
361
+ - test/unit/model_persistence_test.rb
362
+ - test/unit/model_search_test.rb
363
+ - test/unit/results_collection_test.rb
364
+ - test/unit/results_item_test.rb
365
+ - test/unit/rubyext_hash_test.rb
366
+ - test/unit/search_facet_test.rb
367
+ - test/unit/search_filter_test.rb
368
+ - test/unit/search_highlight_test.rb
369
+ - test/unit/search_query_test.rb
370
+ - test/unit/search_sort_test.rb
371
+ - test/unit/search_test.rb
372
+ - test/unit/tire_test.rb