ryanb-thinking_sphinx 0.9.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. data/LICENCE +20 -0
  2. data/README +60 -0
  3. data/lib/riddle.rb +26 -0
  4. data/lib/riddle/client.rb +639 -0
  5. data/lib/riddle/client/filter.rb +44 -0
  6. data/lib/riddle/client/message.rb +65 -0
  7. data/lib/riddle/client/response.rb +84 -0
  8. data/lib/test.rb +46 -0
  9. data/lib/thinking_sphinx.rb +102 -0
  10. data/lib/thinking_sphinx/active_record.rb +141 -0
  11. data/lib/thinking_sphinx/active_record/delta.rb +97 -0
  12. data/lib/thinking_sphinx/active_record/has_many_association.rb +29 -0
  13. data/lib/thinking_sphinx/active_record/search.rb +50 -0
  14. data/lib/thinking_sphinx/association.rb +144 -0
  15. data/lib/thinking_sphinx/attribute.rb +284 -0
  16. data/lib/thinking_sphinx/configuration.rb +283 -0
  17. data/lib/thinking_sphinx/field.rb +200 -0
  18. data/lib/thinking_sphinx/index.rb +340 -0
  19. data/lib/thinking_sphinx/index/builder.rb +195 -0
  20. data/lib/thinking_sphinx/index/faux_column.rb +110 -0
  21. data/lib/thinking_sphinx/rails_additions.rb +56 -0
  22. data/lib/thinking_sphinx/search.rb +482 -0
  23. data/lib/thinking_sphinx/tasks.rb +86 -0
  24. data/spec/unit/thinking_sphinx/active_record/delta_spec.rb +207 -0
  25. data/spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb +53 -0
  26. data/spec/unit/thinking_sphinx/active_record/search_spec.rb +107 -0
  27. data/spec/unit/thinking_sphinx/active_record_spec.rb +236 -0
  28. data/spec/unit/thinking_sphinx/association_spec.rb +247 -0
  29. data/spec/unit/thinking_sphinx/attribute_spec.rb +360 -0
  30. data/spec/unit/thinking_sphinx/configuration_spec.rb +493 -0
  31. data/spec/unit/thinking_sphinx/field_spec.rb +219 -0
  32. data/spec/unit/thinking_sphinx/index/builder_spec.rb +33 -0
  33. data/spec/unit/thinking_sphinx/index/faux_column_spec.rb +68 -0
  34. data/spec/unit/thinking_sphinx/index_spec.rb +277 -0
  35. data/spec/unit/thinking_sphinx/search_spec.rb +190 -0
  36. data/spec/unit/thinking_sphinx_spec.rb +129 -0
  37. data/tasks/thinking_sphinx_tasks.rake +1 -0
  38. metadata +103 -0
@@ -0,0 +1,190 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe ThinkingSphinx::Search do
4
+ describe "search_for_id method" do
5
+ before :each do
6
+ @client = Riddle::Client.stub_instance(
7
+ :filters => [],
8
+ :filters= => true,
9
+ :id_range= => true,
10
+ :query => {
11
+ :matches => []
12
+ }
13
+ )
14
+
15
+ ThinkingSphinx::Search.stub_methods(
16
+ :client_from_options => @client,
17
+ :search_conditions => ["", []]
18
+ )
19
+ end
20
+
21
+ it "should set the client id range to focus on the given id" do
22
+ ThinkingSphinx::Search.search_for_id 42, "an_index"
23
+
24
+ @client.should have_received(:id_range=).with(42..42)
25
+ end
26
+
27
+ it "should query on the given index" do
28
+ ThinkingSphinx::Search.search_for_id 42, "an_index"
29
+
30
+ @client.should have_received(:query).with("", "an_index")
31
+ end
32
+
33
+ it "should return true if a record is returned" do
34
+ @client.stub_method(:query => {
35
+ :matches => [24]
36
+ })
37
+
38
+ ThinkingSphinx::Search.search_for_id(42, "an_index").should be_true
39
+ end
40
+
41
+ it "should return false if no records are returned" do
42
+ ThinkingSphinx::Search.search_for_id(42, "an_index").should be_false
43
+ end
44
+ end
45
+
46
+ describe "instance_from_result method" do
47
+ before :each do
48
+ Person.stub_method(:find => true)
49
+ ThinkingSphinx::Search.stub_method(:class_from_crc => Person)
50
+ end
51
+
52
+ after :each do
53
+ Person.unstub_method(:find)
54
+ ThinkingSphinx::Search.unstub_method(:class_from_crc)
55
+ end
56
+
57
+ it "should honour the :include option" do
58
+ ThinkingSphinx::Search.send(
59
+ :instance_from_result,
60
+ {:doc => 1, :attributes => {"class_crc" => 123}},
61
+ {:include => :assoc}
62
+ )
63
+
64
+ Person.should have_received(:find).with(1, :include => :assoc, :select => nil)
65
+ end
66
+
67
+ it "should honour the :select option" do
68
+ ThinkingSphinx::Search.send(
69
+ :instance_from_result,
70
+ {:doc => 1, :attributes => {"class_crc" => 123}},
71
+ {:select => :columns}
72
+ )
73
+
74
+ Person.should have_received(:find).with(1, :include => nil, :select => :columns)
75
+ end
76
+
77
+ end
78
+
79
+ describe "instances_from_results method" do
80
+ before :each do
81
+ @person_a = Person.stub_instance
82
+ @person_b = Person.stub_instance
83
+ @person_c = Person.stub_instance
84
+
85
+ @results = [
86
+ {:doc => @person_a.id},
87
+ {:doc => @person_b.id},
88
+ {:doc => @person_c.id}
89
+ ]
90
+
91
+ Person.stub_method(
92
+ :find => [@person_c, @person_a, @person_b]
93
+ )
94
+ ThinkingSphinx::Search.stub_method(:instance_from_result => true)
95
+ end
96
+
97
+ after :each do
98
+ Person.unstub_method(:find)
99
+ ThinkingSphinx::Search.unstub_method(:instance_from_result)
100
+ end
101
+
102
+ it "should pass calls to instance_from_result if no class given" do
103
+ ThinkingSphinx::Search.send(
104
+ :instances_from_results, @results
105
+ )
106
+
107
+ ThinkingSphinx::Search.should have_received(:instance_from_result).with(
108
+ {:doc => @person_a.id}, {}
109
+ )
110
+ ThinkingSphinx::Search.should have_received(:instance_from_result).with(
111
+ {:doc => @person_b.id}, {}
112
+ )
113
+ ThinkingSphinx::Search.should have_received(:instance_from_result).with(
114
+ {:doc => @person_c.id}, {}
115
+ )
116
+ end
117
+
118
+ it "should call a find on all ids for the class" do
119
+ ThinkingSphinx::Search.send(
120
+ :instances_from_results, @results, {}, Person
121
+ )
122
+
123
+ Person.should have_received(:find).with(
124
+ :all,
125
+ :conditions => {:id => [@person_a.id, @person_b.id, @person_c.id]},
126
+ :include => nil,
127
+ :select => nil
128
+ )
129
+ end
130
+
131
+ it "should honour the :include option" do
132
+ ThinkingSphinx::Search.send(
133
+ :instances_from_results, @results, {:include => :something}, Person
134
+ )
135
+
136
+ Person.should have_received(:find).with(
137
+ :all,
138
+ :conditions => {:id => [@person_a.id, @person_b.id, @person_c.id]},
139
+ :include => :something,
140
+ :select => nil
141
+ )
142
+ end
143
+
144
+ it "should honour the :select option" do
145
+ ThinkingSphinx::Search.send(
146
+ :instances_from_results, @results, {:select => :fields}, Person
147
+ )
148
+
149
+ Person.should have_received(:find).with(
150
+ :all,
151
+ :conditions => {:id => [@person_a.id, @person_b.id, @person_c.id]},
152
+ :include => nil,
153
+ :select => :fields
154
+ )
155
+ end
156
+
157
+ it "should sort the objects the same as the result set" do
158
+ ThinkingSphinx::Search.send(
159
+ :instances_from_results, @results, {:select => :fields}, Person
160
+ ).should == [@person_a, @person_b, @person_c]
161
+ end
162
+ end
163
+
164
+ describe "count method" do
165
+ before :each do
166
+ @client = Riddle::Client.stub_instance(
167
+ :filters => [],
168
+ :filters= => true,
169
+ :id_range= => true,
170
+ :sort_mode => :asc,
171
+ :limit => 5,
172
+ :offset= => 0,
173
+ :sort_mode= => true,
174
+ :query => {
175
+ :matches => [],
176
+ :total => 50
177
+ }
178
+ )
179
+
180
+ ThinkingSphinx::Search.stub_methods(
181
+ :client_from_options => @client,
182
+ :search_conditions => ["", []]
183
+ )
184
+ end
185
+
186
+ it "should return query total" do
187
+ ThinkingSphinx::Search.count(42, "an_index").should == 50
188
+ end
189
+ end
190
+ end
@@ -0,0 +1,129 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe ThinkingSphinx do
4
+ describe "indexed_models methods" do
5
+ it "should contain all the names of models that have indexes" do
6
+ ThinkingSphinx.indexed_models.should include("Person")
7
+ end
8
+ end
9
+
10
+ it "should define indexes by default" do
11
+ ThinkingSphinx.define_indexes?.should be_true
12
+ end
13
+
14
+ it "should disable index definition" do
15
+ ThinkingSphinx.define_indexes = false
16
+ ThinkingSphinx.define_indexes?.should be_false
17
+ end
18
+
19
+ it "should enable index definition" do
20
+ ThinkingSphinx.define_indexes = false
21
+ ThinkingSphinx.define_indexes?.should be_false
22
+ ThinkingSphinx.define_indexes = true
23
+ ThinkingSphinx.define_indexes?.should be_true
24
+ end
25
+
26
+ it "should index deltas by default" do
27
+ ThinkingSphinx.deltas_enabled = nil
28
+ ThinkingSphinx.deltas_enabled?.should be_true
29
+ end
30
+
31
+ it "should disable delta indexing" do
32
+ ThinkingSphinx.deltas_enabled = false
33
+ ThinkingSphinx.deltas_enabled?.should be_false
34
+ end
35
+
36
+ it "should enable delta indexing" do
37
+ ThinkingSphinx.deltas_enabled = false
38
+ ThinkingSphinx.deltas_enabled?.should be_false
39
+ ThinkingSphinx.deltas_enabled = true
40
+ ThinkingSphinx.deltas_enabled?.should be_true
41
+ end
42
+
43
+ it "should update indexes by default" do
44
+ ThinkingSphinx.updates_enabled = nil
45
+ ThinkingSphinx.updates_enabled?.should be_true
46
+ end
47
+
48
+ it "should disable index updating" do
49
+ ThinkingSphinx.updates_enabled = false
50
+ ThinkingSphinx.updates_enabled?.should be_false
51
+ end
52
+
53
+ it "should enable index updating" do
54
+ ThinkingSphinx.updates_enabled = false
55
+ ThinkingSphinx.updates_enabled?.should be_false
56
+ ThinkingSphinx.updates_enabled = true
57
+ ThinkingSphinx.updates_enabled?.should be_true
58
+ end
59
+
60
+ describe "use_group_by_shortcut? method" do
61
+ after :each do
62
+ ::ActiveRecord::Base.connection.unstub_method(:select_all)
63
+ end
64
+
65
+ it "should return true if no ONLY_FULL_GROUP_BY" do
66
+ ::ActiveRecord::Base.connection.stub_method(
67
+ :select_all => {:a => "OTHER SETTINGS"}
68
+ )
69
+
70
+ ThinkingSphinx.use_group_by_shortcut?.should be_true
71
+ end
72
+
73
+ it "should return true if NULL value" do
74
+ ::ActiveRecord::Base.connection.stub_method(
75
+ :select_all => {:a => nil}
76
+ )
77
+
78
+ ThinkingSphinx.use_group_by_shortcut?.should be_true
79
+ end
80
+
81
+ it "should return false if ONLY_FULL_GROUP_BY is set" do
82
+ ::ActiveRecord::Base.connection.stub_method(
83
+ :select_all => {:a => "OTHER SETTINGS,ONLY_FULL_GROUP_BY,blah"}
84
+ )
85
+
86
+ ThinkingSphinx.use_group_by_shortcut?.should be_false
87
+ end
88
+
89
+ it "should return false if ONLY_FULL_GROUP_BY is set in any of the values" do
90
+ ::ActiveRecord::Base.connection.stub_method(
91
+ :select_all => {
92
+ :a => "OTHER SETTINGS",
93
+ :b => "ONLY_FULL_GROUP_BY"
94
+ }
95
+ )
96
+
97
+ ThinkingSphinx.use_group_by_shortcut?.should be_false
98
+ end
99
+
100
+ describe "if not using MySQL" do
101
+ before :each do
102
+ unless ::ActiveRecord::ConnectionAdapters.const_defined?(:PostgreSQLAdapter)
103
+ pending "No PostgreSQL"
104
+ return
105
+ end
106
+ @connection = ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.stub_instance(
107
+ :select_all => true
108
+ )
109
+ ::ActiveRecord::Base.stub_method(
110
+ :connection => @connection
111
+ )
112
+ end
113
+
114
+ after :each do
115
+ ::ActiveRecord::Base.unstub_method(:connection)
116
+ end
117
+
118
+ it "should return false" do
119
+ ThinkingSphinx.use_group_by_shortcut?.should be_false
120
+ end
121
+
122
+ it "should not call select_all" do
123
+ ThinkingSphinx.use_group_by_shortcut?
124
+
125
+ @connection.should_not have_received(:select_all)
126
+ end
127
+ end
128
+ end
129
+ end
@@ -0,0 +1 @@
1
+ require 'thinking_sphinx/tasks'
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ryanb-thinking_sphinx
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.8
5
+ platform: ruby
6
+ authors:
7
+ - Pat Allan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-08-18 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: A concise and easy-to-use Ruby library that connects ActiveRecord to the Sphinx search daemon, managing configuration, indexing and searching.
17
+ email: pat@freelancing-gods.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/riddle/client/filter.rb
26
+ - lib/riddle/client/message.rb
27
+ - lib/riddle/client/response.rb
28
+ - lib/riddle/client.rb
29
+ - lib/riddle.rb
30
+ - lib/test.rb
31
+ - lib/thinking_sphinx/active_record/delta.rb
32
+ - lib/thinking_sphinx/active_record/has_many_association.rb
33
+ - lib/thinking_sphinx/active_record/search.rb
34
+ - lib/thinking_sphinx/active_record.rb
35
+ - lib/thinking_sphinx/association.rb
36
+ - lib/thinking_sphinx/attribute.rb
37
+ - lib/thinking_sphinx/configuration.rb
38
+ - lib/thinking_sphinx/field.rb
39
+ - lib/thinking_sphinx/index/builder.rb
40
+ - lib/thinking_sphinx/index/faux_column.rb
41
+ - lib/thinking_sphinx/index.rb
42
+ - lib/thinking_sphinx/rails_additions.rb
43
+ - lib/thinking_sphinx/search.rb
44
+ - lib/thinking_sphinx/tasks.rb
45
+ - lib/thinking_sphinx.rb
46
+ - LICENCE
47
+ - README
48
+ - tasks/thinking_sphinx_tasks.rake
49
+ - spec/unit/thinking_sphinx/active_record/delta_spec.rb
50
+ - spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
51
+ - spec/unit/thinking_sphinx/active_record/search_spec.rb
52
+ - spec/unit/thinking_sphinx/active_record_spec.rb
53
+ - spec/unit/thinking_sphinx/association_spec.rb
54
+ - spec/unit/thinking_sphinx/attribute_spec.rb
55
+ - spec/unit/thinking_sphinx/configuration_spec.rb
56
+ - spec/unit/thinking_sphinx/field_spec.rb
57
+ - spec/unit/thinking_sphinx/index/builder_spec.rb
58
+ - spec/unit/thinking_sphinx/index/faux_column_spec.rb
59
+ - spec/unit/thinking_sphinx/index_spec.rb
60
+ - spec/unit/thinking_sphinx/search_spec.rb
61
+ - spec/unit/thinking_sphinx_spec.rb
62
+ has_rdoc: true
63
+ homepage: http://ts.freelancing-gods.com
64
+ post_install_message:
65
+ rdoc_options:
66
+ - --title
67
+ - Thinking Sphinx -- Rails/Merb Sphinx Plugin
68
+ - --line-numbers
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ version:
83
+ requirements: []
84
+
85
+ rubyforge_project: thinking-sphinx
86
+ rubygems_version: 1.2.0
87
+ signing_key:
88
+ specification_version: 2
89
+ summary: A concise and easy-to-use Ruby library that connects ActiveRecord to the Sphinx search daemon, managing configuration, indexing and searching.
90
+ test_files:
91
+ - spec/unit/thinking_sphinx/active_record/delta_spec.rb
92
+ - spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
93
+ - spec/unit/thinking_sphinx/active_record/search_spec.rb
94
+ - spec/unit/thinking_sphinx/active_record_spec.rb
95
+ - spec/unit/thinking_sphinx/association_spec.rb
96
+ - spec/unit/thinking_sphinx/attribute_spec.rb
97
+ - spec/unit/thinking_sphinx/configuration_spec.rb
98
+ - spec/unit/thinking_sphinx/field_spec.rb
99
+ - spec/unit/thinking_sphinx/index/builder_spec.rb
100
+ - spec/unit/thinking_sphinx/index/faux_column_spec.rb
101
+ - spec/unit/thinking_sphinx/index_spec.rb
102
+ - spec/unit/thinking_sphinx/search_spec.rb
103
+ - spec/unit/thinking_sphinx_spec.rb