thinking-sphinx 1.4.6 → 1.4.7

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 (39) hide show
  1. data/README.textile +6 -1
  2. data/features/searching_by_model.feature +24 -30
  3. data/features/thinking_sphinx/db/.gitignore +1 -0
  4. data/features/thinking_sphinx/db/fixtures/post_keywords.txt +1 -0
  5. data/lib/cucumber/thinking_sphinx/internal_world.rb +26 -26
  6. data/lib/thinking_sphinx.rb +17 -26
  7. data/lib/thinking_sphinx/active_record.rb +69 -74
  8. data/lib/thinking_sphinx/active_record/attribute_updates.rb +11 -10
  9. data/lib/thinking_sphinx/active_record/has_many_association.rb +2 -1
  10. data/lib/thinking_sphinx/adapters/abstract_adapter.rb +11 -11
  11. data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +34 -20
  12. data/lib/thinking_sphinx/association.rb +12 -7
  13. data/lib/thinking_sphinx/attribute.rb +64 -61
  14. data/lib/thinking_sphinx/configuration.rb +32 -36
  15. data/lib/thinking_sphinx/context.rb +3 -2
  16. data/lib/thinking_sphinx/deploy/capistrano.rb +7 -9
  17. data/lib/thinking_sphinx/search.rb +201 -178
  18. data/lib/thinking_sphinx/source/sql.rb +1 -1
  19. data/lib/thinking_sphinx/tasks.rb +21 -19
  20. data/lib/thinking_sphinx/version.rb +3 -0
  21. data/spec/fixtures/data.sql +32 -0
  22. data/spec/fixtures/database.yml.default +3 -0
  23. data/spec/fixtures/models.rb +161 -0
  24. data/spec/fixtures/structure.sql +146 -0
  25. data/spec/spec_helper.rb +57 -0
  26. data/spec/sphinx_helper.rb +61 -0
  27. data/spec/thinking_sphinx/active_record/delta_spec.rb +24 -24
  28. data/spec/thinking_sphinx/active_record/has_many_association_spec.rb +22 -0
  29. data/spec/thinking_sphinx/active_record/scopes_spec.rb +25 -25
  30. data/spec/thinking_sphinx/active_record_spec.rb +110 -109
  31. data/spec/thinking_sphinx/adapters/abstract_adapter_spec.rb +38 -38
  32. data/spec/thinking_sphinx/association_spec.rb +20 -2
  33. data/spec/thinking_sphinx/context_spec.rb +61 -64
  34. data/spec/thinking_sphinx/search_spec.rb +7 -0
  35. data/spec/thinking_sphinx_spec.rb +47 -46
  36. metadata +50 -98
  37. data/VERSION +0 -1
  38. data/tasks/distribution.rb +0 -34
  39. data/tasks/testing.rb +0 -80
@@ -122,7 +122,7 @@ GROUP BY #{ sql_group_clause }
122
122
 
123
123
  adapter.case(adapter.convert_nulls(
124
124
  adapter.quote_with_table(@model.inheritance_column)),
125
- types_to_crcs, @model.to_crc32)
125
+ types, @model.to_crc32)
126
126
  else
127
127
  @model.to_crc32.to_s
128
128
  end
@@ -16,36 +16,36 @@ namespace :thinking_sphinx do
16
16
  Sinatra::Application.environment = ENV['RACK_ENV']
17
17
  end
18
18
  end
19
-
19
+
20
20
  desc "Output the current Thinking Sphinx version"
21
21
  task :version => :app_env do
22
- puts "Thinking Sphinx v" + ThinkingSphinx.version
22
+ puts "Thinking Sphinx v" + ThinkingSphinx::Version
23
23
  end
24
-
24
+
25
25
  desc "Stop if running, then start a Sphinx searchd daemon using Thinking Sphinx's settings"
26
26
  task :running_start => :app_env do
27
27
  Rake::Task["thinking_sphinx:stop"].invoke if sphinx_running?
28
28
  Rake::Task["thinking_sphinx:start"].invoke
29
29
  end
30
-
30
+
31
31
  desc "Start a Sphinx searchd daemon using Thinking Sphinx's settings"
32
32
  task :start => :app_env do
33
33
  config = ThinkingSphinx::Configuration.instance
34
-
34
+
35
35
  FileUtils.mkdir_p config.searchd_file_path
36
36
  raise RuntimeError, "searchd is already running." if sphinx_running?
37
-
37
+
38
38
  Dir["#{config.searchd_file_path}/*.spl"].each { |file| File.delete(file) }
39
-
39
+
40
40
  config.controller.start
41
-
41
+
42
42
  if sphinx_running?
43
43
  puts "Started successfully (pid #{sphinx_pid})."
44
44
  else
45
45
  puts "Failed to start searchd daemon. Check #{config.searchd_log_file}"
46
46
  end
47
47
  end
48
-
48
+
49
49
  desc "Stop Sphinx using Thinking Sphinx's settings"
50
50
  task :stop => :app_env do
51
51
  unless sphinx_running?
@@ -54,26 +54,26 @@ namespace :thinking_sphinx do
54
54
  config = ThinkingSphinx::Configuration.instance
55
55
  pid = sphinx_pid
56
56
  config.controller.stop
57
-
57
+
58
58
  # Ensure searchd is stopped, but don't try too hard
59
- Timeout.timeout(5) do
59
+ Timeout.timeout(config.stop_timeout) do
60
60
  sleep(1) until config.controller.stop
61
61
  end
62
-
62
+
63
63
  puts "Stopped search daemon (pid #{pid})."
64
64
  end
65
65
  end
66
-
66
+
67
67
  desc "Restart Sphinx"
68
68
  task :restart => [:app_env, :stop, :start]
69
-
69
+
70
70
  desc "Generate the Sphinx configuration file using Thinking Sphinx's settings"
71
71
  task :configure => :app_env do
72
72
  config = ThinkingSphinx::Configuration.instance
73
73
  puts "Generating Configuration to #{config.config_file}"
74
74
  config.build
75
75
  end
76
-
76
+
77
77
  desc "Index data for Sphinx using Thinking Sphinx's settings"
78
78
  task :index => :app_env do
79
79
  config = ThinkingSphinx::Configuration.instance
@@ -81,18 +81,20 @@ namespace :thinking_sphinx do
81
81
  puts "Generating Configuration to #{config.config_file}"
82
82
  config.build
83
83
  end
84
-
84
+
85
85
  FileUtils.mkdir_p config.searchd_file_path
86
86
  config.controller.index :verbose => true
87
87
  end
88
-
88
+
89
89
  desc "Reindex Sphinx without regenerating the configuration file"
90
90
  task :reindex => :app_env do
91
91
  config = ThinkingSphinx::Configuration.instance
92
92
  FileUtils.mkdir_p config.searchd_file_path
93
- puts config.controller.index
93
+ output = config.controller.index
94
+ puts output
95
+ config.touch_reindex_file(output)
94
96
  end
95
-
97
+
96
98
  desc "Stop Sphinx (if it's running), rebuild the indexes, and start Sphinx"
97
99
  task :rebuild => :app_env do
98
100
  Rake::Task["thinking_sphinx:stop"].invoke if sphinx_running?
@@ -0,0 +1,3 @@
1
+ module ThinkingSphinx
2
+ Version = '1.4.7'
3
+ end
@@ -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, 'FootballTeam');
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,3 @@
1
+ username: root
2
+ password:
3
+ host: localhost
@@ -0,0 +1,161 @@
1
+ class Tag < ActiveRecord::Base
2
+ belongs_to :person
3
+ belongs_to :football_team
4
+ belongs_to :cricket_team
5
+ end
6
+
7
+ class FootballTeam < ActiveRecord::Base
8
+ has_many :tags
9
+ has_many :people, :through => :tags
10
+ end
11
+
12
+ class CricketTeam < ActiveRecord::Base
13
+ has_many :people, :foreign_key => :team_id
14
+
15
+ define_index do
16
+ indexes :name
17
+ has "SELECT cricket_team_id, id FROM tags", :source => :query, :as => :tags
18
+ end
19
+ end
20
+
21
+ class Contact < ActiveRecord::Base
22
+ belongs_to :person
23
+ end
24
+
25
+ class Friendship < ActiveRecord::Base
26
+ belongs_to :person
27
+ belongs_to :friend, :class_name => "Person", :foreign_key => :friend_id
28
+
29
+ define_index do
30
+ indexes "'something'", :as => :something
31
+ has person_id, friend_id
32
+
33
+ set_property :latitude_attr => :person_id
34
+ set_property :longitude_attr => :person_id
35
+ end
36
+
37
+ sphinx_scope(:reverse) {
38
+ {:order => "@weight ASC"}
39
+ }
40
+ end
41
+
42
+ class Link < ActiveRecord::Base
43
+ has_and_belongs_to_many :people
44
+ end
45
+
46
+ class Person < ActiveRecord::Base
47
+ belongs_to :team, :polymorphic => :true
48
+ belongs_to :source, :polymorphic => :true
49
+ has_many :contacts
50
+
51
+ has_many :friendships
52
+ has_many :friends, :through => :friendships
53
+
54
+ has_many :tags
55
+ has_many :football_teams, :through => :tags
56
+
57
+ has_and_belongs_to_many :links
58
+
59
+ define_index do
60
+ indexes [first_name, middle_initial, last_name], :as => :name
61
+ indexes team.name, :as => :team_name
62
+ indexes contacts.phone_number, :as => :phone_numbers
63
+ indexes city, :prefixes => true, :facet => true
64
+ indexes state, :infixes => true, :facet => true
65
+
66
+ has [first_name, middle_initial, last_name], :as => :name_sort
67
+ has team.name, :as => :team_name_sort
68
+
69
+ has [:id, :team_id], :as => :ids
70
+ has team(:id), :as => :team_id
71
+ has football_teams(:id), :as => :football_team_id
72
+
73
+ has contacts.phone_number, :as => :phone_number_sort
74
+ has contacts(:id), :as => :contact_ids
75
+
76
+ has birthday, :facet => true
77
+
78
+ has friendships.person_id, :as => :friendly_ids
79
+
80
+ has :id, :as => :latitude
81
+ has :id, :as => :longitude
82
+
83
+ set_property :delta => true
84
+ end
85
+ end
86
+
87
+ class Parent < Person
88
+ end
89
+
90
+ module Admin
91
+ class Person < ::Person
92
+ end
93
+ end
94
+
95
+ class Child < Person
96
+ belongs_to :parent
97
+ define_index do
98
+ indexes [parent.first_name, parent.middle_initial, parent.last_name], :as => :parent_name
99
+ end
100
+ end
101
+
102
+ class Alpha < ActiveRecord::Base
103
+ has_many :betas
104
+ has_many :thetas
105
+
106
+ define_index do
107
+ indexes :name, :sortable => true
108
+
109
+ has :id, :as => :lat
110
+ has :id, :as => :lng
111
+
112
+ set_property :field_weights => {"name" => 10}
113
+ end
114
+
115
+ def big_name
116
+ name.upcase
117
+ end
118
+
119
+ def sphinx_attributes
120
+ :existing
121
+ end
122
+ end
123
+
124
+ class Beta < ActiveRecord::Base
125
+ has_many :gammas
126
+
127
+ define_index do
128
+ indexes :name, :sortable => true
129
+
130
+ has :id, :as => :lat
131
+ has :id, :as => :lon
132
+
133
+ set_property :delta => true
134
+ end
135
+
136
+ def excerpts
137
+ false
138
+ end
139
+
140
+ def matching_fields
141
+ :foo
142
+ end
143
+ end
144
+
145
+ class Gamma < ActiveRecord::Base
146
+ #
147
+ end
148
+
149
+ class Theta < ActiveRecord::Base
150
+ #
151
+ end
152
+
153
+ class Search < ActiveRecord::Base
154
+ #
155
+ end
156
+
157
+ class BigFoo < ActiveRecord::Base
158
+ define_index do
159
+ indexes name
160
+ end
161
+ end
@@ -0,0 +1,146 @@
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
+ `source_id` int(11) NULL,
20
+ `source_type` varchar(50) NULL,
21
+ `delta` tinyint(1) NOT NULL DEFAULT 0,
22
+ PRIMARY KEY (`id`)
23
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
24
+
25
+ DROP TABLE IF EXISTS `friendships`;
26
+
27
+ CREATE TABLE `friendships` (
28
+ `id` int(11) NOT NULL auto_increment,
29
+ `person_id` int(11) NOT NULL,
30
+ `friend_id` int(11) NOT NULL,
31
+ `created_at` datetime NOT NULL,
32
+ `created_on` date NULL,
33
+ `updated_at` datetime NOT NULL,
34
+ PRIMARY KEY (`id`)
35
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
36
+
37
+ DROP TABLE IF EXISTS `football_teams`;
38
+
39
+ CREATE TABLE `football_teams` (
40
+ `id` int(11) NOT NULL auto_increment,
41
+ `name` varchar(50) NOT NULL,
42
+ `state` varchar(50) NOT NULL,
43
+ `league` varchar(50) NOT NULL,
44
+ PRIMARY KEY (`id`)
45
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
46
+
47
+ DROP TABLE IF EXISTS `cricket_teams`;
48
+
49
+ CREATE TABLE `cricket_teams` (
50
+ `id` int(11) NOT NULL auto_increment,
51
+ `name` varchar(50) NOT NULL,
52
+ `state` varchar(50) NOT NULL,
53
+ PRIMARY KEY (`id`)
54
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
55
+
56
+ DROP TABLE IF EXISTS `contacts`;
57
+
58
+ CREATE TABLE `contacts` (
59
+ `id` int(11) NOT NULL auto_increment,
60
+ `phone_number` varchar(50) NOT NULL,
61
+ `person_id` int(11) NOT NULL,
62
+ PRIMARY KEY (`id`)
63
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
64
+
65
+ DROP TABLE IF EXISTS `alphas`;
66
+
67
+ CREATE TABLE `alphas` (
68
+ `id` int(11) NOT NULL auto_increment,
69
+ `name` varchar(50) NOT NULL,
70
+ `value` int(11),
71
+ `cost` decimal(10,6),
72
+ PRIMARY KEY (`id`)
73
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
74
+
75
+ DROP TABLE IF EXISTS `betas`;
76
+
77
+ CREATE TABLE `betas` (
78
+ `id` int(11) NOT NULL auto_increment,
79
+ `name` varchar(50) NOT NULL,
80
+ `alpha_id` int(11),
81
+ `delta` tinyint(1) NOT NULL DEFAULT 0,
82
+ PRIMARY KEY (`id`)
83
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
84
+
85
+ DROP TABLE IF EXISTS `gammas`;
86
+
87
+ CREATE TABLE `gammas` (
88
+ `id` int(11) NOT NULL auto_increment,
89
+ `name` varchar(50) NOT NULL,
90
+ `value` int(11),
91
+ `beta_id` int(11),
92
+ PRIMARY KEY (`id`)
93
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
94
+
95
+ DROP TABLE IF EXISTS `thetas`;
96
+
97
+ CREATE TABLE `thetas` (
98
+ `id` int(11) NOT NULL auto_increment,
99
+ `name` varchar(50) NOT NULL,
100
+ `value` int(11),
101
+ `alpha_id` int(11),
102
+ PRIMARY KEY (`id`)
103
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
104
+
105
+ DROP TABLE IF EXISTS `searches`;
106
+
107
+ CREATE TABLE `searches` (
108
+ `id` int(11) NOT NULL auto_increment,
109
+ `name` varchar(50) NOT NULL,
110
+ PRIMARY KEY (`id`)
111
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
112
+
113
+ DROP TABLE IF EXISTS `tags`;
114
+
115
+ CREATE TABLE `tags` (
116
+ `id` int(11) NOT NULL auto_increment,
117
+ `person_id` int(11) NOT NULL,
118
+ `football_team_id` int(11) NOT NULL,
119
+ `cricket_team_id` int(11) NOT NULL,
120
+ `name` varchar(50) NOT NULL,
121
+ PRIMARY KEY (`id`)
122
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
123
+
124
+ DROP TABLE IF EXISTS `links`;
125
+
126
+ CREATE TABLE `links` (
127
+ `id` int(11) NOT NULL auto_increment,
128
+ `url` varchar(50) NOT NULL,
129
+ `description` varchar(200),
130
+ PRIMARY KEY (`id`)
131
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
132
+
133
+ DROP TABLE IF EXISTS `links_people`;
134
+
135
+ CREATE TABLE `links_people` (
136
+ `link_id` int(11) NOT NULL,
137
+ `person_id` int(11) NOT NULL
138
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
139
+
140
+ DROP TABLE IF EXISTS `big_foos`;
141
+
142
+ CREATE TABLE `big_foos` (
143
+ `id` bigint NOT NULL auto_increment,
144
+ `name` varchar(50) NOT NULL,
145
+ PRIMARY KEY (`id`)
146
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;