sherpa99-thinking-sphinx 1.1.4
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.
- data/LICENCE +20 -0
- data/README +107 -0
- data/README.textile +107 -0
- data/Rakefile +4 -0
- data/contribute.rb +328 -0
- data/cucumber.yml +1 -0
- data/features/a.rb +17 -0
- data/features/attribute_transformation.feature +22 -0
- data/features/datetime_deltas.feature +55 -0
- data/features/delayed_delta_indexing.feature +37 -0
- data/features/deleting_instances.feature +52 -0
- data/features/facets.feature +26 -0
- data/features/handling_edits.feature +67 -0
- data/features/retry_stale_indexes.feature +24 -0
- data/features/searching_across_models.feature +20 -0
- data/features/searching_by_model.feature +118 -0
- data/features/searching_with_find_arguments.feature +56 -0
- data/features/sphinx_detection.feature +16 -0
- data/features/step_definitions/alpha_steps.rb +3 -0
- data/features/step_definitions/beta_steps.rb +11 -0
- data/features/step_definitions/cat_steps.rb +3 -0
- data/features/step_definitions/common_steps.rb +154 -0
- data/features/step_definitions/datetime_delta_steps.rb +11 -0
- data/features/step_definitions/delayed_delta_indexing_steps.rb +7 -0
- data/features/step_definitions/facet_steps.rb +30 -0
- data/features/step_definitions/find_arguments_steps.rb +36 -0
- data/features/step_definitions/gamma_steps.rb +15 -0
- data/features/step_definitions/search_steps.rb +66 -0
- data/features/step_definitions/sphinx_steps.rb +23 -0
- data/features/support/db/active_record.rb +40 -0
- data/features/support/db/database.example.yml +4 -0
- data/features/support/db/migrations/create_alphas.rb +18 -0
- data/features/support/db/migrations/create_animals.rb +9 -0
- data/features/support/db/migrations/create_betas.rb +15 -0
- data/features/support/db/migrations/create_boxes.rb +13 -0
- data/features/support/db/migrations/create_comments.rb +13 -0
- data/features/support/db/migrations/create_delayed_betas.rb +28 -0
- data/features/support/db/migrations/create_developers.rb +39 -0
- data/features/support/db/migrations/create_gammas.rb +14 -0
- data/features/support/db/migrations/create_people.rb +1014 -0
- data/features/support/db/migrations/create_posts.rb +6 -0
- data/features/support/db/migrations/create_thetas.rb +16 -0
- data/features/support/db/mysql.rb +4 -0
- data/features/support/db/postgresql.rb +4 -0
- data/features/support/env.rb +6 -0
- data/features/support/models/alpha.rb +9 -0
- data/features/support/models/animal.rb +5 -0
- data/features/support/models/beta.rb +7 -0
- data/features/support/models/box.rb +8 -0
- data/features/support/models/cat.rb +3 -0
- data/features/support/models/comment.rb +3 -0
- data/features/support/models/delayed_beta.rb +7 -0
- data/features/support/models/developer.rb +8 -0
- data/features/support/models/gamma.rb +5 -0
- data/features/support/models/person.rb +8 -0
- data/features/support/models/post.rb +8 -0
- data/features/support/models/theta.rb +7 -0
- data/features/support/post_database.rb +37 -0
- data/features/support/z.rb +19 -0
- data/ginger_scenarios.rb +24 -0
- data/init.rb +12 -0
- data/lib/thinking_sphinx.rb +144 -0
- data/lib/thinking_sphinx/active_record.rb +245 -0
- data/lib/thinking_sphinx/active_record/delta.rb +74 -0
- data/lib/thinking_sphinx/active_record/has_many_association.rb +29 -0
- data/lib/thinking_sphinx/active_record/search.rb +57 -0
- data/lib/thinking_sphinx/adapters/abstract_adapter.rb +34 -0
- data/lib/thinking_sphinx/adapters/mysql_adapter.rb +53 -0
- data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +129 -0
- data/lib/thinking_sphinx/association.rb +144 -0
- data/lib/thinking_sphinx/attribute.rb +258 -0
- data/lib/thinking_sphinx/collection.rb +142 -0
- data/lib/thinking_sphinx/configuration.rb +236 -0
- data/lib/thinking_sphinx/core/string.rb +22 -0
- data/lib/thinking_sphinx/deltas.rb +22 -0
- data/lib/thinking_sphinx/deltas/datetime_delta.rb +50 -0
- data/lib/thinking_sphinx/deltas/default_delta.rb +65 -0
- data/lib/thinking_sphinx/deltas/delayed_delta.rb +25 -0
- data/lib/thinking_sphinx/deltas/delayed_delta/delta_job.rb +24 -0
- data/lib/thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job.rb +27 -0
- data/lib/thinking_sphinx/deltas/delayed_delta/job.rb +26 -0
- data/lib/thinking_sphinx/facet.rb +58 -0
- data/lib/thinking_sphinx/facet_collection.rb +44 -0
- data/lib/thinking_sphinx/field.rb +172 -0
- data/lib/thinking_sphinx/index.rb +414 -0
- data/lib/thinking_sphinx/index/builder.rb +233 -0
- data/lib/thinking_sphinx/index/faux_column.rb +110 -0
- data/lib/thinking_sphinx/rails_additions.rb +133 -0
- data/lib/thinking_sphinx/search.rb +638 -0
- data/lib/thinking_sphinx/tasks.rb +128 -0
- data/rails/init.rb +6 -0
- data/spec/fixtures/data.sql +32 -0
- data/spec/fixtures/database.yml.default +3 -0
- data/spec/fixtures/models.rb +81 -0
- data/spec/fixtures/structure.sql +84 -0
- data/spec/spec_helper.rb +54 -0
- data/spec/sphinx_helper.rb +109 -0
- data/spec/unit/thinking_sphinx/active_record/delta_spec.rb +136 -0
- data/spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb +53 -0
- data/spec/unit/thinking_sphinx/active_record/search_spec.rb +107 -0
- data/spec/unit/thinking_sphinx/active_record_spec.rb +256 -0
- data/spec/unit/thinking_sphinx/association_spec.rb +247 -0
- data/spec/unit/thinking_sphinx/attribute_spec.rb +212 -0
- data/spec/unit/thinking_sphinx/collection_spec.rb +14 -0
- data/spec/unit/thinking_sphinx/configuration_spec.rb +136 -0
- data/spec/unit/thinking_sphinx/core/string_spec.rb +9 -0
- data/spec/unit/thinking_sphinx/field_spec.rb +145 -0
- data/spec/unit/thinking_sphinx/index/builder_spec.rb +5 -0
- data/spec/unit/thinking_sphinx/index/faux_column_spec.rb +30 -0
- data/spec/unit/thinking_sphinx/index_spec.rb +54 -0
- data/spec/unit/thinking_sphinx/search_spec.rb +59 -0
- data/spec/unit/thinking_sphinx_spec.rb +129 -0
- data/tasks/distribution.rb +48 -0
- data/tasks/rails.rake +1 -0
- data/tasks/testing.rb +86 -0
- data/thinking-sphinx.gemspec +232 -0
- data/vendor/after_commit/LICENSE +20 -0
- data/vendor/after_commit/README +16 -0
- data/vendor/after_commit/Rakefile +22 -0
- data/vendor/after_commit/init.rb +5 -0
- data/vendor/after_commit/lib/after_commit.rb +42 -0
- data/vendor/after_commit/lib/after_commit/active_record.rb +91 -0
- data/vendor/after_commit/lib/after_commit/connection_adapters.rb +103 -0
- data/vendor/after_commit/test/after_commit_test.rb +53 -0
- data/vendor/delayed_job/lib/delayed/job.rb +251 -0
- data/vendor/delayed_job/lib/delayed/message_sending.rb +7 -0
- data/vendor/delayed_job/lib/delayed/performable_method.rb +55 -0
- data/vendor/delayed_job/lib/delayed/worker.rb +54 -0
- data/vendor/riddle/lib/riddle.rb +30 -0
- data/vendor/riddle/lib/riddle/client.rb +619 -0
- data/vendor/riddle/lib/riddle/client/filter.rb +53 -0
- data/vendor/riddle/lib/riddle/client/message.rb +65 -0
- data/vendor/riddle/lib/riddle/client/response.rb +84 -0
- data/vendor/riddle/lib/riddle/configuration.rb +33 -0
- data/vendor/riddle/lib/riddle/configuration/distributed_index.rb +48 -0
- data/vendor/riddle/lib/riddle/configuration/index.rb +142 -0
- data/vendor/riddle/lib/riddle/configuration/indexer.rb +19 -0
- data/vendor/riddle/lib/riddle/configuration/remote_index.rb +17 -0
- data/vendor/riddle/lib/riddle/configuration/searchd.rb +25 -0
- data/vendor/riddle/lib/riddle/configuration/section.rb +37 -0
- data/vendor/riddle/lib/riddle/configuration/source.rb +23 -0
- data/vendor/riddle/lib/riddle/configuration/sql_source.rb +34 -0
- data/vendor/riddle/lib/riddle/configuration/xml_source.rb +28 -0
- data/vendor/riddle/lib/riddle/controller.rb +44 -0
- metadata +248 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
require 'fileutils'
|
|
2
|
+
|
|
3
|
+
namespace :thinking_sphinx do
|
|
4
|
+
task :app_env do
|
|
5
|
+
Rake::Task[:environment].invoke if defined?(RAILS_ROOT)
|
|
6
|
+
Rake::Task[:merb_env].invoke if defined?(Merb)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
desc "Stop if running, then start a Sphinx searchd daemon using Thinking Sphinx's settings"
|
|
10
|
+
task :running_start => :app_env do
|
|
11
|
+
Rake::Task["thinking_sphinx:stop"].invoke if sphinx_running?
|
|
12
|
+
Rake::Task["thinking_sphinx:start"].invoke
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
desc "Start a Sphinx searchd daemon using Thinking Sphinx's settings"
|
|
16
|
+
task :start => :app_env do
|
|
17
|
+
config = ThinkingSphinx::Configuration.instance
|
|
18
|
+
|
|
19
|
+
FileUtils.mkdir_p config.searchd_file_path
|
|
20
|
+
raise RuntimeError, "searchd is already running." if sphinx_running?
|
|
21
|
+
|
|
22
|
+
Dir["#{config.searchd_file_path}/*.spl"].each { |file| File.delete(file) }
|
|
23
|
+
|
|
24
|
+
cmd = "#{config.bin_path}searchd --pidfile --config #{config.config_file}"
|
|
25
|
+
puts cmd
|
|
26
|
+
system cmd
|
|
27
|
+
|
|
28
|
+
sleep(2)
|
|
29
|
+
|
|
30
|
+
if sphinx_running?
|
|
31
|
+
puts "Started successfully (pid #{sphinx_pid})."
|
|
32
|
+
else
|
|
33
|
+
puts "Failed to start searchd daemon. Check #{config.searchd_log_file}."
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
desc "Stop Sphinx using Thinking Sphinx's settings"
|
|
38
|
+
task :stop => :app_env do
|
|
39
|
+
raise RuntimeError, "searchd is not running." unless sphinx_running?
|
|
40
|
+
config = ThinkingSphinx::Configuration.instance
|
|
41
|
+
pid = sphinx_pid
|
|
42
|
+
system "searchd --stop --config #{config.config_file}"
|
|
43
|
+
puts "Stopped search daemon (pid #{pid})."
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
desc "Restart Sphinx"
|
|
47
|
+
task :restart => [:app_env, :stop, :start]
|
|
48
|
+
|
|
49
|
+
desc "Generate the Sphinx configuration file using Thinking Sphinx's settings"
|
|
50
|
+
task :configure => :app_env do
|
|
51
|
+
config = ThinkingSphinx::Configuration.instance
|
|
52
|
+
puts "Generating Configuration to #{config.config_file}"
|
|
53
|
+
config.build
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
desc "Index data for Sphinx using Thinking Sphinx's settings"
|
|
57
|
+
task :index => :app_env do
|
|
58
|
+
ThinkingSphinx::Deltas::Job.cancel_thinking_sphinx_jobs
|
|
59
|
+
|
|
60
|
+
config = ThinkingSphinx::Configuration.instance
|
|
61
|
+
unless ENV["INDEX_ONLY"] == "true"
|
|
62
|
+
puts "Generating Configuration to #{config.config_file}"
|
|
63
|
+
config.build
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
FileUtils.mkdir_p config.searchd_file_path
|
|
67
|
+
cmd = "#{config.bin_path}indexer --config #{config.config_file} --all"
|
|
68
|
+
cmd << " --rotate" if sphinx_running?
|
|
69
|
+
puts cmd
|
|
70
|
+
system cmd
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
namespace :index do
|
|
74
|
+
task :delta => :app_env do
|
|
75
|
+
ThinkingSphinx.indexed_models.select { |model|
|
|
76
|
+
model.constantize.sphinx_indexes.any? { |index| index.delta? }
|
|
77
|
+
}.each do |model|
|
|
78
|
+
model.constantize.sphinx_indexes.select { |index|
|
|
79
|
+
index.delta? && index.delta_object.respond_to?(:delayed_index)
|
|
80
|
+
}.each { |index|
|
|
81
|
+
index.delta_object.delayed_index(index.model)
|
|
82
|
+
}
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
desc "Process stored delta index requests"
|
|
88
|
+
task :delayed_delta => :app_env do
|
|
89
|
+
require 'delayed/worker'
|
|
90
|
+
|
|
91
|
+
Delayed::Worker.new(
|
|
92
|
+
:min_priority => ENV['MIN_PRIORITY'],
|
|
93
|
+
:max_priority => ENV['MAX_PRIORITY']
|
|
94
|
+
).start
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
namespace :ts do
|
|
99
|
+
desc "Stop if running, then start a Sphinx searchd daemon using Thinking Sphinx's settings"
|
|
100
|
+
task :run => "thinking_sphinx:running_start"
|
|
101
|
+
desc "Start a Sphinx searchd daemon using Thinking Sphinx's settings"
|
|
102
|
+
task :start => "thinking_sphinx:start"
|
|
103
|
+
desc "Stop Sphinx using Thinking Sphinx's settings"
|
|
104
|
+
task :stop => "thinking_sphinx:stop"
|
|
105
|
+
desc "Index data for Sphinx using Thinking Sphinx's settings"
|
|
106
|
+
task :in => "thinking_sphinx:index"
|
|
107
|
+
namespace :in do
|
|
108
|
+
desc "Index Thinking Sphinx datetime delta indexes"
|
|
109
|
+
task :delta => "thinking_sphinx:index:delta"
|
|
110
|
+
end
|
|
111
|
+
task :index => "thinking_sphinx:index"
|
|
112
|
+
desc "Restart Sphinx"
|
|
113
|
+
task :restart => "thinking_sphinx:restart"
|
|
114
|
+
desc "Generate the Sphinx configuration file using Thinking Sphinx's settings"
|
|
115
|
+
task :conf => "thinking_sphinx:configure"
|
|
116
|
+
desc "Generate the Sphinx configuration file using Thinking Sphinx's settings"
|
|
117
|
+
task :config => "thinking_sphinx:configure"
|
|
118
|
+
desc "Process stored delta index requests"
|
|
119
|
+
task :dd => "thinking_sphinx:delayed_delta"
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def sphinx_pid
|
|
123
|
+
ThinkingSphinx.sphinx_pid
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def sphinx_running?
|
|
127
|
+
ThinkingSphinx.sphinx_running?
|
|
128
|
+
end
|
data/rails/init.rb
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
insert into `people` (gender, first_name, middle_initial, last_name, street_address, city, state, postcode, email, birthday, team_id, team_type) values('female','Ellie','K','Ford','38 Mills Street','Eagle Farm Bc','QLD','4009','Ellie.K.Ford@mailinator.com','1970/1/23 00:00:00', 3, 'CricketTeam');
|
|
2
|
+
insert into `people` (gender, first_name, middle_initial, last_name, street_address, city, state, postcode, email, birthday, team_id, team_type) values('female','Aaliyah','E','Allen','71 Murphy Street','Wyola West','WA','6407','Aaliyah.E.Allen@dodgit.com','1980/3/23 00:00:00', 3, 'CricketTeam');
|
|
3
|
+
insert into `people` (gender, first_name, middle_initial, last_name, street_address, city, state, postcode, email, birthday, team_id, team_type) values('male','Callum','C','Miah','89 Dalgarno Street','Bullawa Creek','NSW','2390','Callum.C.Miah@trashymail.com','1973/3/25 00:00:00', 3, 'CricketTeam');
|
|
4
|
+
insert into `people` (gender, first_name, middle_initial, last_name, street_address, city, state, postcode, email, birthday, team_id, team_type) values('male','Finley','L','Buckley','18 Queen Street','Manly Vale','NSW','2093','Finley.L.Buckley@spambob.com','1962/11/20 00:00:00', 3, 'CricketTeam');
|
|
5
|
+
insert into `people` (gender, first_name, middle_initial, last_name, street_address, city, state, postcode, email, birthday, team_id, team_type) values('female','Poppy','A','Hilton','36 Nerrigundah Drive','Nyora','VIC','3987','Poppy.A.Hilton@dodgit.com','1972/10/30 00:00:00', 3, 'CricketTeam');
|
|
6
|
+
insert into `people` (gender, first_name, middle_initial, last_name, street_address, city, state, postcode, email, birthday, team_id, team_type) values('female','Eloise','Z','Kennedy','18 Mt Berryman Road','Lilydale','QLD','4344','Eloise.Z.Kennedy@spambob.com','1973/9/28 00:00:00', 3, 'CricketTeam');
|
|
7
|
+
insert into `people` (gender, first_name, middle_initial, last_name, street_address, city, state, postcode, email, birthday, team_id, team_type) values('female','Shannon','L','Manning','60 Ocean Pde','Greenvale','QLD','4816','Shannon.L.Manning@dodgit.com','1956/6/13 00:00:00', 3, 'CricketTeam');
|
|
8
|
+
insert into `people` (gender, first_name, middle_initial, last_name, street_address, city, state, postcode, email, birthday, team_id, team_type) values('male','Oscar','C','Lawson','43 Feather Street','Battery Hill','QLD','4551','Oscar.C.Lawson@spambob.com','1979/10/17 00:00:00', 3, 'CricketTeam');
|
|
9
|
+
insert into `people` (gender, first_name, middle_initial, last_name, street_address, city, state, postcode, email, birthday, team_id, team_type) values('female','Sofia','K','Bray','26 Clifton Street','Pental Island','VIC','3586','Sofia.K.Bray@mailinator.com','1970/5/10 00:00:00', 3, 'CricketTeam');
|
|
10
|
+
insert into `people` (gender, first_name, middle_initial, last_name, street_address, city, state, postcode, email, birthday, team_id, team_type) values('male','Andrew','N','Byrne','35 Cecil Street','Monash Park','NSW','2111','Andrew.N.Byrne@spambob.com','1983/2/16 00:00:00', 3, 'CricketTeam');
|
|
11
|
+
|
|
12
|
+
insert into `alphas` (name) values ('one');
|
|
13
|
+
insert into `alphas` (name) values ('two');
|
|
14
|
+
insert into `alphas` (name) values ('three');
|
|
15
|
+
insert into `alphas` (name) values ('four');
|
|
16
|
+
insert into `alphas` (name) values ('five');
|
|
17
|
+
insert into `alphas` (name) values ('six');
|
|
18
|
+
insert into `alphas` (name) values ('seven');
|
|
19
|
+
insert into `alphas` (name) values ('eight');
|
|
20
|
+
insert into `alphas` (name) values ('nine');
|
|
21
|
+
insert into `alphas` (name) values ('ten');
|
|
22
|
+
|
|
23
|
+
insert into `betas` (name) values ('one');
|
|
24
|
+
insert into `betas` (name) values ('two');
|
|
25
|
+
insert into `betas` (name) values ('three');
|
|
26
|
+
insert into `betas` (name) values ('four');
|
|
27
|
+
insert into `betas` (name) values ('five');
|
|
28
|
+
insert into `betas` (name) values ('six');
|
|
29
|
+
insert into `betas` (name) values ('seven');
|
|
30
|
+
insert into `betas` (name) values ('eight');
|
|
31
|
+
insert into `betas` (name) values ('nine');
|
|
32
|
+
insert into `betas` (name) values ('ten');
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
class Person < ActiveRecord::Base
|
|
2
|
+
belongs_to :team, :polymorphic => :true
|
|
3
|
+
has_many :contacts
|
|
4
|
+
|
|
5
|
+
has_many :friendships
|
|
6
|
+
has_many :friends, :through => :friendships
|
|
7
|
+
|
|
8
|
+
define_index do
|
|
9
|
+
indexes [first_name, middle_initial, last_name], :as => :name
|
|
10
|
+
indexes team.name, :as => :team_name
|
|
11
|
+
indexes contacts.phone_number, :as => :phone_numbers
|
|
12
|
+
indexes city, :prefixes => true
|
|
13
|
+
indexes state, :infixes => true
|
|
14
|
+
|
|
15
|
+
has [first_name, middle_initial, last_name], :as => :name_sort
|
|
16
|
+
has team.name, :as => :team_name_sort
|
|
17
|
+
|
|
18
|
+
has [:id, :team_id], :as => :ids
|
|
19
|
+
has team(:id), :as => :team_id
|
|
20
|
+
|
|
21
|
+
has contacts.phone_number, :as => :phone_number_sort
|
|
22
|
+
has contacts(:id), :as => :contact_ids
|
|
23
|
+
|
|
24
|
+
has birthday
|
|
25
|
+
|
|
26
|
+
has friendships.person_id, :as => :friendly_ids
|
|
27
|
+
|
|
28
|
+
set_property :delta => true
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
class Parent < Person
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
class Child < Person
|
|
36
|
+
belongs_to :parent
|
|
37
|
+
define_index do
|
|
38
|
+
indexes [parent.first_name, parent.middle_initial, parent.last_name], :as => :parent_name
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
class Contact < ActiveRecord::Base
|
|
43
|
+
belongs_to :person
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
class FootballTeam < ActiveRecord::Base
|
|
47
|
+
#
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
class CricketTeam < ActiveRecord::Base
|
|
51
|
+
#
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
class Friendship < ActiveRecord::Base
|
|
55
|
+
belongs_to :person
|
|
56
|
+
belongs_to :friend, :class_name => "Person", :foreign_key => :friend_id
|
|
57
|
+
|
|
58
|
+
define_index do
|
|
59
|
+
has person_id, friend_id
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
class Alpha < ActiveRecord::Base
|
|
64
|
+
define_index do
|
|
65
|
+
indexes :name, :sortable => true
|
|
66
|
+
|
|
67
|
+
set_property :field_weights => {"name" => 10}
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
class Beta < ActiveRecord::Base
|
|
72
|
+
define_index do
|
|
73
|
+
indexes :name, :sortable => true
|
|
74
|
+
|
|
75
|
+
set_property :delta => true
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
class Search < ActiveRecord::Base
|
|
80
|
+
#
|
|
81
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
DROP TABLE IF EXISTS `people`;
|
|
2
|
+
|
|
3
|
+
CREATE TABLE `people` (
|
|
4
|
+
`id` int(11) NOT NULL auto_increment,
|
|
5
|
+
`first_name` varchar(50) NULL,
|
|
6
|
+
`middle_initial` varchar(10) NULL,
|
|
7
|
+
`last_name` varchar(50) NULL,
|
|
8
|
+
`gender` varchar(10) NULL,
|
|
9
|
+
`street_address` varchar(200) NULL,
|
|
10
|
+
`city` varchar(100) NULL,
|
|
11
|
+
`state` varchar(100) NULL,
|
|
12
|
+
`postcode` varchar(10) NULL,
|
|
13
|
+
`email` varchar(100) NULL,
|
|
14
|
+
`birthday` datetime NULL,
|
|
15
|
+
`team_id` int(11) NULL,
|
|
16
|
+
`team_type` varchar(50) NULL,
|
|
17
|
+
`type` varchar(50) NULL,
|
|
18
|
+
`parent_id` varchar(50) NULL,
|
|
19
|
+
`delta` tinyint(1) NOT NULL DEFAULT 0,
|
|
20
|
+
PRIMARY KEY (`id`)
|
|
21
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
22
|
+
|
|
23
|
+
DROP TABLE IF EXISTS `friendships`;
|
|
24
|
+
|
|
25
|
+
CREATE TABLE `friendships` (
|
|
26
|
+
`id` int(11) NOT NULL auto_increment,
|
|
27
|
+
`person_id` int(11) NOT NULL,
|
|
28
|
+
`friend_id` int(11) NOT NULL,
|
|
29
|
+
`created_at` datetime NOT NULL,
|
|
30
|
+
`updated_at` datetime NOT NULL,
|
|
31
|
+
PRIMARY KEY (`id`)
|
|
32
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
33
|
+
|
|
34
|
+
DROP TABLE IF EXISTS `football_teams`;
|
|
35
|
+
|
|
36
|
+
CREATE TABLE `football_teams` (
|
|
37
|
+
`id` int(11) NOT NULL auto_increment,
|
|
38
|
+
`name` varchar(50) NOT NULL,
|
|
39
|
+
`state` varchar(50) NOT NULL,
|
|
40
|
+
PRIMARY KEY (`id`)
|
|
41
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
42
|
+
|
|
43
|
+
DROP TABLE IF EXISTS `cricket_teams`;
|
|
44
|
+
|
|
45
|
+
CREATE TABLE `cricket_teams` (
|
|
46
|
+
`id` int(11) NOT NULL auto_increment,
|
|
47
|
+
`name` varchar(50) NOT NULL,
|
|
48
|
+
`state` varchar(50) NOT NULL,
|
|
49
|
+
PRIMARY KEY (`id`)
|
|
50
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
51
|
+
|
|
52
|
+
DROP TABLE IF EXISTS `contacts`;
|
|
53
|
+
|
|
54
|
+
CREATE TABLE `contacts` (
|
|
55
|
+
`id` int(11) NOT NULL auto_increment,
|
|
56
|
+
`phone_number` varchar(50) NOT NULL,
|
|
57
|
+
`person_id` int(11) NOT NULL,
|
|
58
|
+
PRIMARY KEY (`id`)
|
|
59
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
60
|
+
|
|
61
|
+
DROP TABLE IF EXISTS `alphas`;
|
|
62
|
+
|
|
63
|
+
CREATE TABLE `alphas` (
|
|
64
|
+
`id` int(11) NOT NULL auto_increment,
|
|
65
|
+
`name` varchar(50) NOT NULL,
|
|
66
|
+
PRIMARY KEY (`id`)
|
|
67
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
68
|
+
|
|
69
|
+
DROP TABLE IF EXISTS `betas`;
|
|
70
|
+
|
|
71
|
+
CREATE TABLE `betas` (
|
|
72
|
+
`id` int(11) NOT NULL auto_increment,
|
|
73
|
+
`name` varchar(50) NOT NULL,
|
|
74
|
+
`delta` tinyint(1) NOT NULL DEFAULT 0,
|
|
75
|
+
PRIMARY KEY (`id`)
|
|
76
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
77
|
+
|
|
78
|
+
DROP TABLE IF EXISTS `searches`;
|
|
79
|
+
|
|
80
|
+
CREATE TABLE `searches` (
|
|
81
|
+
`id` int(11) NOT NULL auto_increment,
|
|
82
|
+
`name` varchar(50) NOT NULL,
|
|
83
|
+
PRIMARY KEY (`id`)
|
|
84
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
$:.unshift File.dirname(__FILE__) + '/../lib'
|
|
2
|
+
|
|
3
|
+
require 'rubygems'
|
|
4
|
+
require 'fileutils'
|
|
5
|
+
require 'ginger'
|
|
6
|
+
require 'not_a_mock'
|
|
7
|
+
require 'will_paginate'
|
|
8
|
+
|
|
9
|
+
require 'lib/thinking_sphinx'
|
|
10
|
+
require 'spec/sphinx_helper'
|
|
11
|
+
|
|
12
|
+
ActiveRecord::Base.logger = Logger.new(StringIO.new)
|
|
13
|
+
|
|
14
|
+
Spec::Runner.configure do |config|
|
|
15
|
+
%w( tmp tmp/config tmp/log tmp/db ).each do |path|
|
|
16
|
+
FileUtils.mkdir_p "#{Dir.pwd}/#{path}"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
Kernel.const_set :RAILS_ROOT, "#{Dir.pwd}/tmp" unless defined?(RAILS_ROOT)
|
|
20
|
+
|
|
21
|
+
sphinx = SphinxHelper.new
|
|
22
|
+
sphinx.setup_mysql
|
|
23
|
+
|
|
24
|
+
require 'spec/fixtures/models'
|
|
25
|
+
|
|
26
|
+
config.before :all do
|
|
27
|
+
%w( tmp tmp/config tmp/log tmp/db ).each do |path|
|
|
28
|
+
FileUtils.mkdir_p "#{Dir.pwd}/#{path}"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
ThinkingSphinx.updates_enabled = true
|
|
32
|
+
ThinkingSphinx.deltas_enabled = true
|
|
33
|
+
ThinkingSphinx.suppress_delta_output = true
|
|
34
|
+
|
|
35
|
+
ThinkingSphinx::Configuration.instance.reset
|
|
36
|
+
ThinkingSphinx::Configuration.instance.database_yml_file = "spec/fixtures/sphinx/database.yml"
|
|
37
|
+
|
|
38
|
+
# Ensure after_commit plugin is loaded correctly
|
|
39
|
+
Object.subclasses_of(ActiveRecord::ConnectionAdapters::AbstractAdapter).each { |klass|
|
|
40
|
+
unless klass.ancestors.include?(AfterCommit::ConnectionAdapters)
|
|
41
|
+
klass.send(:include, AfterCommit::ConnectionAdapters)
|
|
42
|
+
end
|
|
43
|
+
}
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
config.after :each do
|
|
47
|
+
NotAMock::CallRecorder.instance.reset
|
|
48
|
+
NotAMock::Stubber.instance.reset
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
config.after :all do
|
|
52
|
+
FileUtils.rm_r "#{Dir.pwd}/tmp" rescue nil
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
require 'active_record'
|
|
2
|
+
require 'active_record/connection_adapters/mysql_adapter'
|
|
3
|
+
begin
|
|
4
|
+
require 'active_record/connection_adapters/postgresql_adapter'
|
|
5
|
+
rescue LoadError
|
|
6
|
+
# No postgres? no prob...
|
|
7
|
+
end
|
|
8
|
+
require 'yaml'
|
|
9
|
+
|
|
10
|
+
class SphinxHelper
|
|
11
|
+
attr_accessor :host, :username, :password
|
|
12
|
+
attr_reader :path
|
|
13
|
+
|
|
14
|
+
def initialize
|
|
15
|
+
@host = "localhost"
|
|
16
|
+
@username = "thinking_sphinx"
|
|
17
|
+
@password = ""
|
|
18
|
+
|
|
19
|
+
if File.exist?("spec/fixtures/database.yml")
|
|
20
|
+
config = YAML.load(File.open("spec/fixtures/database.yml"))
|
|
21
|
+
@host = config["host"]
|
|
22
|
+
@username = config["username"]
|
|
23
|
+
@password = config["password"]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
@path = File.expand_path(File.dirname(__FILE__))
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def setup_mysql
|
|
30
|
+
ActiveRecord::Base.establish_connection(
|
|
31
|
+
:adapter => 'mysql',
|
|
32
|
+
:database => 'thinking_sphinx',
|
|
33
|
+
:username => @username,
|
|
34
|
+
:password => @password,
|
|
35
|
+
:host => @host
|
|
36
|
+
)
|
|
37
|
+
ActiveRecord::Base.logger = Logger.new(File.open("tmp/activerecord.log", "a"))
|
|
38
|
+
|
|
39
|
+
structure = File.open("spec/fixtures/structure.sql") { |f| f.read.chomp }
|
|
40
|
+
structure.split(';').each { |table|
|
|
41
|
+
ActiveRecord::Base.connection.execute table
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
File.open("spec/fixtures/data.sql") { |f|
|
|
45
|
+
while line = f.gets
|
|
46
|
+
ActiveRecord::Base.connection.execute line unless line.blank?
|
|
47
|
+
end
|
|
48
|
+
}
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def setup_sphinx
|
|
52
|
+
@configuration = ThinkingSphinx::Configuration.instance.reset
|
|
53
|
+
File.open("spec/fixtures/sphinx/database.yml", "w") do |file|
|
|
54
|
+
YAML.dump({@configuration.environment => {
|
|
55
|
+
:adapter => 'mysql',
|
|
56
|
+
:host => @host,
|
|
57
|
+
:database => "thinking_sphinx",
|
|
58
|
+
:username => @username,
|
|
59
|
+
:password => @password
|
|
60
|
+
}}, file)
|
|
61
|
+
end
|
|
62
|
+
FileUtils.mkdir_p(@configuration.searchd_file_path)
|
|
63
|
+
|
|
64
|
+
@configuration.database_yml_file = "spec/fixtures/sphinx/database.yml"
|
|
65
|
+
@configuration.build
|
|
66
|
+
|
|
67
|
+
index
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def reset
|
|
71
|
+
setup_mysql
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def index
|
|
75
|
+
cmd = "indexer --config #{@configuration.config_file} --all"
|
|
76
|
+
cmd << " --rotate" if running?
|
|
77
|
+
`#{cmd}`
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def start
|
|
81
|
+
return if running?
|
|
82
|
+
|
|
83
|
+
cmd = "searchd --config #{@configuration.config_file}"
|
|
84
|
+
`#{cmd}`
|
|
85
|
+
|
|
86
|
+
sleep(1)
|
|
87
|
+
|
|
88
|
+
unless running?
|
|
89
|
+
puts "Failed to start searchd daemon. Check #{@configuration.searchd_log_file}."
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def stop
|
|
94
|
+
return unless running?
|
|
95
|
+
`kill #{pid}`
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def pid
|
|
99
|
+
if File.exists?("#{@configuration.pid_file}")
|
|
100
|
+
`cat #{@configuration.pid_file}`[/\d+/]
|
|
101
|
+
else
|
|
102
|
+
nil
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def running?
|
|
107
|
+
pid && `ps #{pid} | wc -l`.to_i > 1
|
|
108
|
+
end
|
|
109
|
+
end
|