dbldots_oedipus 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/.gitignore +10 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +20 -0
  5. data/README.md +435 -0
  6. data/Rakefile +26 -0
  7. data/ext/oedipus/extconf.rb +72 -0
  8. data/ext/oedipus/lexing.c +96 -0
  9. data/ext/oedipus/lexing.h +20 -0
  10. data/ext/oedipus/oedipus.c +339 -0
  11. data/ext/oedipus/oedipus.h +58 -0
  12. data/lib/oedipus.rb +40 -0
  13. data/lib/oedipus/comparison.rb +88 -0
  14. data/lib/oedipus/comparison/between.rb +21 -0
  15. data/lib/oedipus/comparison/equal.rb +21 -0
  16. data/lib/oedipus/comparison/gt.rb +21 -0
  17. data/lib/oedipus/comparison/gte.rb +21 -0
  18. data/lib/oedipus/comparison/in.rb +21 -0
  19. data/lib/oedipus/comparison/lt.rb +21 -0
  20. data/lib/oedipus/comparison/lte.rb +21 -0
  21. data/lib/oedipus/comparison/not.rb +25 -0
  22. data/lib/oedipus/comparison/not_equal.rb +21 -0
  23. data/lib/oedipus/comparison/not_in.rb +21 -0
  24. data/lib/oedipus/comparison/outside.rb +21 -0
  25. data/lib/oedipus/comparison/shortcuts.rb +144 -0
  26. data/lib/oedipus/connection.rb +124 -0
  27. data/lib/oedipus/connection/pool.rb +133 -0
  28. data/lib/oedipus/connection/registry.rb +56 -0
  29. data/lib/oedipus/connection_error.rb +14 -0
  30. data/lib/oedipus/index.rb +320 -0
  31. data/lib/oedipus/query_builder.rb +185 -0
  32. data/lib/oedipus/rspec/test_rig.rb +132 -0
  33. data/lib/oedipus/version.rb +12 -0
  34. data/oedipus.gemspec +42 -0
  35. data/spec/data/.gitkeep +0 -0
  36. data/spec/integration/connection/registry_spec.rb +50 -0
  37. data/spec/integration/connection_spec.rb +156 -0
  38. data/spec/integration/index_spec.rb +442 -0
  39. data/spec/spec_helper.rb +16 -0
  40. data/spec/unit/comparison/between_spec.rb +36 -0
  41. data/spec/unit/comparison/equal_spec.rb +22 -0
  42. data/spec/unit/comparison/gt_spec.rb +22 -0
  43. data/spec/unit/comparison/gte_spec.rb +22 -0
  44. data/spec/unit/comparison/in_spec.rb +22 -0
  45. data/spec/unit/comparison/lt_spec.rb +22 -0
  46. data/spec/unit/comparison/lte_spec.rb +22 -0
  47. data/spec/unit/comparison/not_equal_spec.rb +22 -0
  48. data/spec/unit/comparison/not_in_spec.rb +22 -0
  49. data/spec/unit/comparison/not_spec.rb +37 -0
  50. data/spec/unit/comparison/outside_spec.rb +36 -0
  51. data/spec/unit/comparison/shortcuts_spec.rb +125 -0
  52. data/spec/unit/comparison_spec.rb +109 -0
  53. data/spec/unit/query_builder_spec.rb +205 -0
  54. metadata +164 -0
@@ -0,0 +1,205 @@
1
+ # encoding: utf-8
2
+
3
+ ##
4
+ # Oedipus Sphinx 2 Search.
5
+ # Copyright © 2012 Chris Corbyn.
6
+ #
7
+ # See LICENSE file for details.
8
+ ##
9
+
10
+ require "spec_helper"
11
+
12
+ describe Oedipus::QueryBuilder do
13
+ let(:builder) { Oedipus::QueryBuilder.new(:posts) }
14
+
15
+ describe "#select" do
16
+ context "with a fulltext search" do
17
+ it "uses MATCH()" do
18
+ sql = builder.select("dogs AND cats", {})
19
+ sql[0].should =~ /SELECT .* FROM posts WHERE MATCH\(\?\)/
20
+ sql.slice(1..-1).should == ["dogs AND cats"]
21
+ end
22
+ end
23
+
24
+ context "without conditions" do
25
+ it "does not add a where clause" do
26
+ builder.select("", {})[0].should_not =~ /WHERE/
27
+ end
28
+ end
29
+
30
+ context "with equal attribute filters" do
31
+ it "uses the '=' operator" do
32
+ sql = builder.select("dogs", author_id: 7)
33
+ sql[0].should =~ /SELECT .* FROM posts WHERE .* author_id = \?/
34
+ sql.slice(1..-1).should == ["dogs", 7]
35
+ end
36
+ end
37
+
38
+ context "with not equal attribute filters" do
39
+ it "uses the '!=' operator" do
40
+ sql = builder.select("dogs", author_id: Oedipus.not(7))
41
+ sql[0].should =~ /SELECT .* FROM posts WHERE .* author_id != \?/
42
+ sql.slice(1..-1).should == ["dogs", 7]
43
+ end
44
+ end
45
+
46
+ context "with inclusive range-filtered attribute filters" do
47
+ it "uses the BETWEEN operator" do
48
+ sql = builder.select("cats", views: 10..20)
49
+ sql[0].should =~ /SELECT .* FROM posts WHERE .* views BETWEEN \? AND \?/
50
+ sql.slice(1..-1).should == ["cats", 10, 20]
51
+ end
52
+ end
53
+
54
+ context "with exclusive range-filtered attribute filters" do
55
+ it "uses the BETWEEN operator" do
56
+ sql = builder.select("cats", views: 10...20)
57
+ sql[0].should =~ /SELECT .* FROM posts WHERE .* views BETWEEN \? AND \?/
58
+ sql.slice(1..-1).should == ["cats", 10, 19]
59
+ end
60
+ end
61
+
62
+ context "with a greater than or equal comparison" do
63
+ it "uses the >= operator" do
64
+ sql = builder.select("cats", views: 50..(1/0.0))
65
+ sql[0].should =~ /SELECT .* FROM posts WHERE .* views >= \?/
66
+ sql.slice(1..-1).should == ["cats", 50]
67
+ end
68
+ end
69
+
70
+ context "with a greater than comparison" do
71
+ it "uses the > operator" do
72
+ sql = builder.select("cats", views: 50...(1/0.0))
73
+ sql[0].should =~ /SELECT .* FROM posts WHERE .* views > \?/
74
+ sql.slice(1..-1).should == ["cats", 50]
75
+ end
76
+ end
77
+
78
+ context "with a less than or equal comparison" do
79
+ it "uses the <= operator" do
80
+ sql = builder.select("cats", views: -(1/0.0)..50)
81
+ sql[0].should =~ /SELECT .* FROM posts WHERE .* views <= \?/
82
+ sql.slice(1..-1).should == ["cats", 50]
83
+ end
84
+ end
85
+
86
+ context "with a less than comparison" do
87
+ it "uses the < operator" do
88
+ sql = builder.select("cats", views: -(1/0.0)...50)
89
+ sql[0].should =~ /SELECT .* FROM posts WHERE .* views < \?/
90
+ sql.slice(1..-1).should == ["cats", 50]
91
+ end
92
+ end
93
+
94
+ context "with a negated range comparison" do
95
+ it "uses the NOT BETWEEN operator" do
96
+ sql = builder.select("cats", views: Oedipus.not(50..100))
97
+ sql[0].should =~ /SELECT .* FROM posts WHERE .* views NOT BETWEEN \? AND \?/
98
+ sql.slice(1..-1).should == ["cats", 50, 100]
99
+ end
100
+ end
101
+
102
+ context "with an attributed filtered by collection" do
103
+ it "uses the IN operator" do
104
+ sql = builder.select("cats", author_id: [7, 11])
105
+ sql[0].should =~ /SELECT .* FROM posts WHERE .* author_id IN \(\?, \?\)/
106
+ sql.slice(1..-1).should == ["cats", 7, 11]
107
+ end
108
+ end
109
+
110
+ context "with an attributed filtered by negated collection" do
111
+ it "uses the NOT IN operator" do
112
+ sql = builder.select("cats", author_id: Oedipus.not([7, 11]))
113
+ sql[0].should =~ /SELECT .* FROM posts WHERE .* author_id NOT IN \(\?, \?\)/
114
+ sql.slice(1..-1).should == ["cats", 7, 11]
115
+ end
116
+ end
117
+
118
+ context "with explicit attributes" do
119
+ it "puts the attributes in the select clause" do
120
+ sql = builder.select("cats", attrs: [:*, "FOO() AS f"])
121
+ sql[0].should =~ /SELECT \*, FOO\(\) AS f FROM posts/
122
+ end
123
+ end
124
+
125
+ context "with a limit" do
126
+ it "applies a LIMIT with an offset of 0" do
127
+ sql = builder.select("dogs", limit: 50)
128
+ sql[0].should =~ /SELECT .* FROM posts WHERE .* LIMIT 0, 50/
129
+ end
130
+
131
+ it "is not considered an attribute" do
132
+ sql = builder.select("dogs", limit: 50)
133
+ sql.slice(1..-1).should == ["dogs"]
134
+ end
135
+ end
136
+
137
+ context "with an offset" do
138
+ it "applies a LIMIT with an offset" do
139
+ sql = builder.select("dogs", limit: 50, offset: 200)
140
+ sql[0].should =~ /SELECT .* FROM posts WHERE .* LIMIT 200, 50/
141
+ end
142
+
143
+ it "is not considered an attribute" do
144
+ sql = builder.select("dogs", limit: 50, offset: 200)
145
+ sql.slice(1..-1).should == ["dogs"]
146
+ end
147
+ end
148
+
149
+ context "with an order clause" do
150
+ it "applies an ORDER BY" do
151
+ sql = builder.select("cats", order: {views: :desc})
152
+ sql[0].should =~ /SELECT .* FROM posts WHERE .* ORDER BY views DESC/
153
+ end
154
+
155
+ it "defaults to ASC" do
156
+ sql = builder.select("cats", order: :views)
157
+ sql[0].should =~ /SELECT .* FROM posts WHERE .* ORDER BY views ASC/
158
+ end
159
+
160
+ it "supports multiple orders" do
161
+ sql = builder.select("cats", order: {views: :asc, author_id: :desc})
162
+ sql[0].should =~ /SELECT .* FROM posts WHERE .* ORDER BY views ASC, author_id DESC/
163
+ end
164
+
165
+ context "by relevance" do
166
+ it "injects a weight() attribute" do
167
+ sql = builder.select("cats", order: {relevance: :desc})
168
+ sql[0].should =~ /SELECT \*, WEIGHT\(\) AS relevance FROM posts WHERE .* ORDER BY relevance DESC/
169
+ end
170
+ end
171
+ end
172
+ end
173
+
174
+ describe "#insert" do
175
+ it "includes the ID and the attributes" do
176
+ builder.insert(3, title: "example", views: 9).should == ["INSERT INTO posts (id, title, views) VALUES (?, ?, ?)", 3, "example", 9]
177
+ end
178
+ end
179
+
180
+ describe "#update" do
181
+ it "includes the ID in the WHERE clause" do
182
+ sql = builder.update(3, title: "example", views: 9)
183
+ sql[0].should =~ /UPDATE posts SET .* WHERE id = \?/
184
+ sql.last.should == 3
185
+ end
186
+
187
+ it "includes the changed attributes" do
188
+ sql = builder.update(3, title: "example", views: 9)
189
+ sql[0].should =~ /UPDATE posts SET title = \?, views = \?/
190
+ sql.slice(1..-1).should == ["example", 9, 3]
191
+ end
192
+ end
193
+
194
+ describe "#replace" do
195
+ it "includes the ID and the attributes" do
196
+ builder.replace(3, title: "example", views: 9).should == ["REPLACE INTO posts (id, title, views) VALUES (?, ?, ?)", 3, "example", 9]
197
+ end
198
+ end
199
+
200
+ describe "#delete" do
201
+ it "includes the ID" do
202
+ builder.delete(3).should == ["DELETE FROM posts WHERE id = ?", 3]
203
+ end
204
+ end
205
+ end
metadata ADDED
@@ -0,0 +1,164 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dbldots_oedipus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.16
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - d11wtq
9
+ - dbldots
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-04-13 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: rake-compiler
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :development
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ description: ! "== Sphinx 2 Comes to Ruby\n\nOedipus brings full support for Sphinx
48
+ 2 to Ruby:\n\n - real-time indexes (insert, replace, update, delete)\n - faceted
49
+ search (variations on a base query)\n - multi-queries (multiple queries executed
50
+ in a batch)\n - full attribute filtering support\n\nIt works with 'stable' versions
51
+ of Sphinx 2 (>= 2.0.2). All\nfeatures are implemented entirely through the SphinxQL
52
+ interface.\n\n-- dbldots: --\nthis gem release in general shouldn't be used. it
53
+ fixes an issue\non mac os x where multi queries are broken.\n\nthis gem will be
54
+ deleted as soon as the bug is fixed in the\noriginal version.\n"
55
+ email:
56
+ - dbldots@gmail.com
57
+ executables: []
58
+ extensions:
59
+ - ext/oedipus/extconf.rb
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .rspec
64
+ - Gemfile
65
+ - LICENSE
66
+ - README.md
67
+ - Rakefile
68
+ - ext/oedipus/extconf.rb
69
+ - ext/oedipus/lexing.c
70
+ - ext/oedipus/lexing.h
71
+ - ext/oedipus/oedipus.c
72
+ - ext/oedipus/oedipus.h
73
+ - lib/oedipus.rb
74
+ - lib/oedipus/comparison.rb
75
+ - lib/oedipus/comparison/between.rb
76
+ - lib/oedipus/comparison/equal.rb
77
+ - lib/oedipus/comparison/gt.rb
78
+ - lib/oedipus/comparison/gte.rb
79
+ - lib/oedipus/comparison/in.rb
80
+ - lib/oedipus/comparison/lt.rb
81
+ - lib/oedipus/comparison/lte.rb
82
+ - lib/oedipus/comparison/not.rb
83
+ - lib/oedipus/comparison/not_equal.rb
84
+ - lib/oedipus/comparison/not_in.rb
85
+ - lib/oedipus/comparison/outside.rb
86
+ - lib/oedipus/comparison/shortcuts.rb
87
+ - lib/oedipus/connection.rb
88
+ - lib/oedipus/connection/pool.rb
89
+ - lib/oedipus/connection/registry.rb
90
+ - lib/oedipus/connection_error.rb
91
+ - lib/oedipus/index.rb
92
+ - lib/oedipus/query_builder.rb
93
+ - lib/oedipus/rspec/test_rig.rb
94
+ - lib/oedipus/version.rb
95
+ - oedipus.gemspec
96
+ - spec/data/.gitkeep
97
+ - spec/integration/connection/registry_spec.rb
98
+ - spec/integration/connection_spec.rb
99
+ - spec/integration/index_spec.rb
100
+ - spec/spec_helper.rb
101
+ - spec/unit/comparison/between_spec.rb
102
+ - spec/unit/comparison/equal_spec.rb
103
+ - spec/unit/comparison/gt_spec.rb
104
+ - spec/unit/comparison/gte_spec.rb
105
+ - spec/unit/comparison/in_spec.rb
106
+ - spec/unit/comparison/lt_spec.rb
107
+ - spec/unit/comparison/lte_spec.rb
108
+ - spec/unit/comparison/not_equal_spec.rb
109
+ - spec/unit/comparison/not_in_spec.rb
110
+ - spec/unit/comparison/not_spec.rb
111
+ - spec/unit/comparison/outside_spec.rb
112
+ - spec/unit/comparison/shortcuts_spec.rb
113
+ - spec/unit/comparison_spec.rb
114
+ - spec/unit/query_builder_spec.rb
115
+ homepage: https://github.com/d11wtq/oedipus
116
+ licenses: []
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ segments:
128
+ - 0
129
+ hash: -2726580249340346399
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ! '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ segments:
137
+ - 0
138
+ hash: -2726580249340346399
139
+ requirements: []
140
+ rubyforge_project: dbldots_oedipus
141
+ rubygems_version: 1.8.25
142
+ signing_key:
143
+ specification_version: 3
144
+ summary: Sphinx 2 Search Client for Ruby
145
+ test_files:
146
+ - spec/data/.gitkeep
147
+ - spec/integration/connection/registry_spec.rb
148
+ - spec/integration/connection_spec.rb
149
+ - spec/integration/index_spec.rb
150
+ - spec/spec_helper.rb
151
+ - spec/unit/comparison/between_spec.rb
152
+ - spec/unit/comparison/equal_spec.rb
153
+ - spec/unit/comparison/gt_spec.rb
154
+ - spec/unit/comparison/gte_spec.rb
155
+ - spec/unit/comparison/in_spec.rb
156
+ - spec/unit/comparison/lt_spec.rb
157
+ - spec/unit/comparison/lte_spec.rb
158
+ - spec/unit/comparison/not_equal_spec.rb
159
+ - spec/unit/comparison/not_in_spec.rb
160
+ - spec/unit/comparison/not_spec.rb
161
+ - spec/unit/comparison/outside_spec.rb
162
+ - spec/unit/comparison/shortcuts_spec.rb
163
+ - spec/unit/comparison_spec.rb
164
+ - spec/unit/query_builder_spec.rb