oedipus 0.0.1.pre1 → 0.0.1.pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/.gitignore +2 -0
  2. data/README.md +235 -44
  3. data/Rakefile +25 -0
  4. data/ext/oedipus/extconf.rb +72 -0
  5. data/ext/oedipus/oedipus.c +239 -0
  6. data/ext/oedipus/oedipus.h +50 -0
  7. data/lib/oedipus/comparison/between.rb +26 -0
  8. data/lib/oedipus/comparison/equal.rb +21 -0
  9. data/lib/oedipus/comparison/gt.rb +21 -0
  10. data/lib/oedipus/comparison/gte.rb +21 -0
  11. data/lib/oedipus/comparison/in.rb +21 -0
  12. data/lib/oedipus/comparison/lt.rb +21 -0
  13. data/lib/oedipus/comparison/lte.rb +21 -0
  14. data/lib/oedipus/comparison/not.rb +25 -0
  15. data/lib/oedipus/comparison/not_equal.rb +21 -0
  16. data/lib/oedipus/comparison/not_in.rb +21 -0
  17. data/lib/oedipus/comparison/outside.rb +26 -0
  18. data/lib/oedipus/comparison/shortcuts.rb +144 -0
  19. data/lib/oedipus/comparison.rb +88 -0
  20. data/lib/oedipus/connection.rb +91 -13
  21. data/lib/oedipus/connection_error.rb +14 -0
  22. data/lib/oedipus/index.rb +189 -46
  23. data/lib/oedipus/query_builder.rb +97 -4
  24. data/lib/oedipus/version.rb +1 -1
  25. data/lib/oedipus.rb +24 -7
  26. data/oedipus.gemspec +4 -5
  27. data/spec/integration/connection_spec.rb +58 -0
  28. data/spec/integration/index_spec.rb +353 -0
  29. data/spec/spec_helper.rb +2 -23
  30. data/spec/support/test_harness.rb +30 -9
  31. data/spec/unit/comparison/between_spec.rb +36 -0
  32. data/spec/unit/comparison/equal_spec.rb +22 -0
  33. data/spec/unit/comparison/gt_spec.rb +22 -0
  34. data/spec/unit/comparison/gte_spec.rb +22 -0
  35. data/spec/unit/comparison/in_spec.rb +22 -0
  36. data/spec/unit/comparison/lt_spec.rb +22 -0
  37. data/spec/unit/comparison/lte_spec.rb +22 -0
  38. data/spec/unit/comparison/not_equal_spec.rb +22 -0
  39. data/spec/unit/comparison/not_in_spec.rb +22 -0
  40. data/spec/unit/comparison/not_spec.rb +37 -0
  41. data/spec/unit/comparison/outside_spec.rb +36 -0
  42. data/spec/unit/comparison/shortcuts_spec.rb +125 -0
  43. data/spec/unit/comparison_spec.rb +109 -0
  44. data/spec/unit/query_builder_spec.rb +150 -0
  45. metadata +68 -19
  46. data/lib/oedipus/mysql/client.rb +0 -136
  47. data/spec/unit/connection_spec.rb +0 -36
  48. data/spec/unit/index_spec.rb +0 -85
@@ -1,36 +0,0 @@
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::Connection do
13
- let(:conn) { Oedipus::Connection.new(searchd_host) }
14
-
15
- describe "#initialize" do
16
- context "on successful connection" do
17
- it "returns the connection" do
18
- Oedipus::Connection.new(searchd_host).should be_a_kind_of(Oedipus::Connection)
19
- end
20
- end
21
-
22
- context "on failed connection" do
23
- it "raises an error" do
24
- expect {
25
- Oedipus::Connection.new(:host => "127.0.0.1", :port => 45346138)
26
- }.to raise_error
27
- end
28
- end
29
- end
30
-
31
- describe "#[]" do
32
- it "returns an index" do
33
- conn[:posts_rt].should be_a_kind_of(Oedipus::Index)
34
- end
35
- end
36
- end
@@ -1,85 +0,0 @@
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::Index do
13
- let(:conn) { Oedipus::Connection.new(searchd_host) }
14
- let(:index) { Oedipus::Index.new(:posts_rt, conn) }
15
-
16
- describe "#insert" do
17
- context "with valid data" do
18
- it "returns the inserted attributes as a Hash" do
19
- index.insert(
20
- 10,
21
- title: "Badgers",
22
- body: "They live in setts, do badgers.",
23
- views: 721,
24
- user_id: 7
25
- ).should == { id: 10, views: 721, user_id: 7, status: "" }
26
- end
27
- end
28
-
29
- context "with invalid data" do
30
- it "raises an error" do
31
- expect {
32
- index.insert(
33
- 10,
34
- bad_field: "Invalid",
35
- body: "They live in setts, do badgers.",
36
- views: 721,
37
- user_id: 7
38
- )
39
- }.to raise_error
40
- end
41
- end
42
- end
43
-
44
- describe "#search" do
45
- before(:each) do
46
- index.insert(1, title: "Badgers and foxes", views: 150)
47
- index.insert(2, title: "Rabbits and hares", views: 87)
48
- index.insert(3, title: "Badgers in the wild", views: 41)
49
- index.insert(4, title: "Badgers for all!", views: 3003)
50
- end
51
-
52
- context "by fulltext matching" do
53
- it "indicates the number of records found" do
54
- index.search("badgers")[:total_found].should == 3
55
- end
56
-
57
- it "includes the matches records" do
58
- index.search("badgers")[:records].should == [
59
- { id: 1, views: 150, user_id: 0, status: "" },
60
- { id: 3, views: 41, user_id: 0, status: "" },
61
- { id: 4, views: 3003, user_id: 0, status: "" }
62
- ]
63
- end
64
- end
65
-
66
- context "with limits" do
67
- it "still indicates the number of records found" do
68
- index.search("badgers", limit: 2)[:total_found].should == 3
69
- end
70
-
71
- it "returns the limited subset of the results" do
72
- index.search("badgers", limit: 2)[:records].should == [
73
- { id: 1, views: 150, user_id: 0, status: "" },
74
- { id: 3, views: 41, user_id: 0, status: "" }
75
- ]
76
- end
77
-
78
- it "can use an offset" do
79
- index.search("badgers", limit: 1, offset: 1)[:records].should == [
80
- { id: 3, views: 41, user_id: 0, status: "" }
81
- ]
82
- end
83
- end
84
- end
85
- end