skalee-thinking-sphinx 1.3.14.1
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.textile +201 -0
- data/Rakefile +3 -0
- data/VERSION +1 -0
- data/contribute.rb +385 -0
- data/cucumber.yml +1 -0
- data/features/abstract_inheritance.feature +10 -0
- data/features/alternate_primary_key.feature +27 -0
- data/features/attribute_transformation.feature +22 -0
- data/features/attribute_updates.feature +51 -0
- data/features/deleting_instances.feature +67 -0
- data/features/direct_attributes.feature +11 -0
- data/features/excerpts.feature +13 -0
- data/features/extensible_delta_indexing.feature +9 -0
- data/features/facets.feature +82 -0
- data/features/facets_across_model.feature +29 -0
- data/features/handling_edits.feature +92 -0
- data/features/retry_stale_indexes.feature +24 -0
- data/features/searching_across_models.feature +20 -0
- data/features/searching_by_index.feature +40 -0
- data/features/searching_by_model.feature +175 -0
- data/features/searching_with_find_arguments.feature +56 -0
- data/features/sphinx_detection.feature +25 -0
- data/features/sphinx_scopes.feature +42 -0
- data/features/step_definitions/alpha_steps.rb +16 -0
- data/features/step_definitions/beta_steps.rb +7 -0
- data/features/step_definitions/common_steps.rb +188 -0
- data/features/step_definitions/extensible_delta_indexing_steps.rb +7 -0
- data/features/step_definitions/facet_steps.rb +96 -0
- data/features/step_definitions/find_arguments_steps.rb +36 -0
- data/features/step_definitions/gamma_steps.rb +15 -0
- data/features/step_definitions/scope_steps.rb +15 -0
- data/features/step_definitions/search_steps.rb +89 -0
- data/features/step_definitions/sphinx_steps.rb +35 -0
- data/features/sti_searching.feature +19 -0
- data/features/support/database.example.yml +3 -0
- data/features/support/db/.gitignore +1 -0
- data/features/support/db/fixtures/alphas.rb +10 -0
- data/features/support/db/fixtures/authors.rb +1 -0
- data/features/support/db/fixtures/betas.rb +10 -0
- data/features/support/db/fixtures/boxes.rb +9 -0
- data/features/support/db/fixtures/categories.rb +1 -0
- data/features/support/db/fixtures/cats.rb +3 -0
- data/features/support/db/fixtures/comments.rb +24 -0
- data/features/support/db/fixtures/developers.rb +29 -0
- data/features/support/db/fixtures/dogs.rb +3 -0
- data/features/support/db/fixtures/extensible_betas.rb +10 -0
- data/features/support/db/fixtures/foxes.rb +3 -0
- data/features/support/db/fixtures/gammas.rb +10 -0
- data/features/support/db/fixtures/music.rb +4 -0
- data/features/support/db/fixtures/people.rb +1001 -0
- data/features/support/db/fixtures/posts.rb +6 -0
- data/features/support/db/fixtures/robots.rb +14 -0
- data/features/support/db/fixtures/tags.rb +27 -0
- data/features/support/db/migrations/create_alphas.rb +8 -0
- data/features/support/db/migrations/create_animals.rb +5 -0
- data/features/support/db/migrations/create_authors.rb +3 -0
- data/features/support/db/migrations/create_authors_posts.rb +6 -0
- data/features/support/db/migrations/create_betas.rb +5 -0
- data/features/support/db/migrations/create_boxes.rb +5 -0
- data/features/support/db/migrations/create_categories.rb +3 -0
- data/features/support/db/migrations/create_comments.rb +10 -0
- data/features/support/db/migrations/create_developers.rb +9 -0
- data/features/support/db/migrations/create_extensible_betas.rb +5 -0
- data/features/support/db/migrations/create_gammas.rb +3 -0
- data/features/support/db/migrations/create_genres.rb +3 -0
- data/features/support/db/migrations/create_music.rb +6 -0
- data/features/support/db/migrations/create_people.rb +13 -0
- data/features/support/db/migrations/create_posts.rb +5 -0
- data/features/support/db/migrations/create_robots.rb +4 -0
- data/features/support/db/migrations/create_taggings.rb +5 -0
- data/features/support/db/migrations/create_tags.rb +4 -0
- data/features/support/env.rb +21 -0
- data/features/support/lib/generic_delta_handler.rb +8 -0
- data/features/support/models/alpha.rb +22 -0
- data/features/support/models/animal.rb +5 -0
- data/features/support/models/author.rb +3 -0
- data/features/support/models/beta.rb +8 -0
- data/features/support/models/box.rb +8 -0
- data/features/support/models/cat.rb +3 -0
- data/features/support/models/category.rb +4 -0
- data/features/support/models/comment.rb +10 -0
- data/features/support/models/developer.rb +16 -0
- data/features/support/models/dog.rb +3 -0
- data/features/support/models/extensible_beta.rb +9 -0
- data/features/support/models/fox.rb +5 -0
- data/features/support/models/gamma.rb +5 -0
- data/features/support/models/genre.rb +3 -0
- data/features/support/models/medium.rb +5 -0
- data/features/support/models/music.rb +8 -0
- data/features/support/models/person.rb +23 -0
- data/features/support/models/post.rb +21 -0
- data/features/support/models/robot.rb +12 -0
- data/features/support/models/tag.rb +3 -0
- data/features/support/models/tagging.rb +4 -0
- data/ginger_scenarios.rb +28 -0
- data/init.rb +5 -0
- data/install.rb +5 -0
- data/lib/cucumber/thinking_sphinx/external_world.rb +8 -0
- data/lib/cucumber/thinking_sphinx/internal_world.rb +126 -0
- data/lib/cucumber/thinking_sphinx/sql_logger.rb +20 -0
- data/lib/thinking_sphinx/active_record/attribute_updates.rb +19 -0
- data/lib/thinking_sphinx/active_record/delta.rb +47 -0
- data/lib/thinking_sphinx/active_record/has_many_association.rb +29 -0
- data/lib/thinking_sphinx/active_record/scopes.rb +75 -0
- data/lib/thinking_sphinx/active_record.rb +348 -0
- data/lib/thinking_sphinx/adapters/abstract_adapter.rb +42 -0
- data/lib/thinking_sphinx/adapters/mysql_adapter.rb +54 -0
- data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +143 -0
- data/lib/thinking_sphinx/association.rb +164 -0
- data/lib/thinking_sphinx/attribute.rb +362 -0
- data/lib/thinking_sphinx/auto_version.rb +22 -0
- data/lib/thinking_sphinx/class_facet.rb +15 -0
- data/lib/thinking_sphinx/configuration.rb +300 -0
- data/lib/thinking_sphinx/context.rb +68 -0
- data/lib/thinking_sphinx/core/array.rb +7 -0
- data/lib/thinking_sphinx/core/string.rb +15 -0
- data/lib/thinking_sphinx/deltas/default_delta.rb +62 -0
- data/lib/thinking_sphinx/deltas.rb +28 -0
- data/lib/thinking_sphinx/deploy/capistrano.rb +100 -0
- data/lib/thinking_sphinx/excerpter.rb +22 -0
- data/lib/thinking_sphinx/facet.rb +125 -0
- data/lib/thinking_sphinx/facet_search.rb +136 -0
- data/lib/thinking_sphinx/field.rb +82 -0
- data/lib/thinking_sphinx/index/builder.rb +296 -0
- data/lib/thinking_sphinx/index/faux_column.rb +110 -0
- data/lib/thinking_sphinx/index.rb +157 -0
- data/lib/thinking_sphinx/property.rb +162 -0
- data/lib/thinking_sphinx/rails_additions.rb +150 -0
- data/lib/thinking_sphinx/search.rb +769 -0
- data/lib/thinking_sphinx/search_methods.rb +439 -0
- data/lib/thinking_sphinx/source/internal_properties.rb +46 -0
- data/lib/thinking_sphinx/source/sql.rb +130 -0
- data/lib/thinking_sphinx/source.rb +153 -0
- data/lib/thinking_sphinx/tasks.rb +131 -0
- data/lib/thinking_sphinx/test.rb +52 -0
- data/lib/thinking_sphinx.rb +225 -0
- data/rails/init.rb +16 -0
- data/recipes/thinking_sphinx.rb +3 -0
- data/spec/fixtures/data.sql +32 -0
- data/spec/fixtures/database.yml.default +3 -0
- data/spec/fixtures/models.rb +145 -0
- data/spec/fixtures/structure.sql +125 -0
- data/spec/spec_helper.rb +60 -0
- data/spec/sphinx_helper.rb +81 -0
- data/spec/thinking_sphinx/active_record/delta_spec.rb +128 -0
- data/spec/thinking_sphinx/active_record/has_many_association_spec.rb +55 -0
- data/spec/thinking_sphinx/active_record/scopes_spec.rb +177 -0
- data/spec/thinking_sphinx/active_record_spec.rb +622 -0
- data/spec/thinking_sphinx/association_spec.rb +239 -0
- data/spec/thinking_sphinx/attribute_spec.rb +570 -0
- data/spec/thinking_sphinx/auto_version_spec.rb +39 -0
- data/spec/thinking_sphinx/configuration_spec.rb +234 -0
- data/spec/thinking_sphinx/context_spec.rb +119 -0
- data/spec/thinking_sphinx/core/array_spec.rb +9 -0
- data/spec/thinking_sphinx/core/string_spec.rb +9 -0
- data/spec/thinking_sphinx/excerpter_spec.rb +57 -0
- data/spec/thinking_sphinx/facet_search_spec.rb +176 -0
- data/spec/thinking_sphinx/facet_spec.rb +333 -0
- data/spec/thinking_sphinx/field_spec.rb +154 -0
- data/spec/thinking_sphinx/index/builder_spec.rb +479 -0
- data/spec/thinking_sphinx/index/faux_column_spec.rb +30 -0
- data/spec/thinking_sphinx/index_spec.rb +183 -0
- data/spec/thinking_sphinx/rails_additions_spec.rb +203 -0
- data/spec/thinking_sphinx/search_methods_spec.rb +152 -0
- data/spec/thinking_sphinx/search_spec.rb +1181 -0
- data/spec/thinking_sphinx/source_spec.rb +235 -0
- data/spec/thinking_sphinx_spec.rb +204 -0
- data/tasks/distribution.rb +41 -0
- data/tasks/rails.rake +1 -0
- data/tasks/testing.rb +72 -0
- data/vendor/after_commit/.gitignore +1 -0
- data/vendor/after_commit/lib/after_commit/active_record.rb +122 -0
- data/vendor/after_commit/lib/after_commit/connection_adapters.rb +168 -0
- data/vendor/after_commit/lib/after_commit/test_bypass.rb +30 -0
- data/vendor/after_commit/lib/after_commit.rb +70 -0
- data/vendor/riddle/lib/riddle/0.9.8.rb +1 -0
- data/vendor/riddle/lib/riddle/0.9.9/client/filter.rb +22 -0
- data/vendor/riddle/lib/riddle/0.9.9/client.rb +49 -0
- data/vendor/riddle/lib/riddle/0.9.9/configuration/searchd.rb +28 -0
- data/vendor/riddle/lib/riddle/0.9.9.rb +7 -0
- data/vendor/riddle/lib/riddle/auto_version.rb +11 -0
- data/vendor/riddle/lib/riddle/client/filter.rb +62 -0
- data/vendor/riddle/lib/riddle/client/message.rb +70 -0
- data/vendor/riddle/lib/riddle/client/response.rb +94 -0
- data/vendor/riddle/lib/riddle/client.rb +745 -0
- data/vendor/riddle/lib/riddle/configuration/distributed_index.rb +49 -0
- data/vendor/riddle/lib/riddle/configuration/index.rb +149 -0
- data/vendor/riddle/lib/riddle/configuration/indexer.rb +20 -0
- data/vendor/riddle/lib/riddle/configuration/remote_index.rb +17 -0
- data/vendor/riddle/lib/riddle/configuration/searchd.rb +28 -0
- data/vendor/riddle/lib/riddle/configuration/section.rb +43 -0
- data/vendor/riddle/lib/riddle/configuration/source.rb +23 -0
- data/vendor/riddle/lib/riddle/configuration/sql_source.rb +53 -0
- data/vendor/riddle/lib/riddle/configuration/xml_source.rb +29 -0
- data/vendor/riddle/lib/riddle/configuration.rb +33 -0
- data/vendor/riddle/lib/riddle/controller.rb +78 -0
- data/vendor/riddle/lib/riddle.rb +51 -0
- metadata +312 -0
@@ -0,0 +1,145 @@
|
|
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
|
+
end
|
10
|
+
|
11
|
+
class CricketTeam < ActiveRecord::Base
|
12
|
+
define_index do
|
13
|
+
indexes :name
|
14
|
+
has "SELECT cricket_team_id, id FROM tags", :source => :query, :as => :tags
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class Contact < ActiveRecord::Base
|
19
|
+
belongs_to :person
|
20
|
+
end
|
21
|
+
|
22
|
+
class Friendship < ActiveRecord::Base
|
23
|
+
belongs_to :person
|
24
|
+
belongs_to :friend, :class_name => "Person", :foreign_key => :friend_id
|
25
|
+
|
26
|
+
define_index do
|
27
|
+
indexes "'something'", :as => :something
|
28
|
+
has person_id, friend_id
|
29
|
+
|
30
|
+
set_property :latitude_attr => :person_id
|
31
|
+
set_property :longitude_attr => :person_id
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class Link < ActiveRecord::Base
|
36
|
+
has_and_belongs_to_many :people
|
37
|
+
end
|
38
|
+
|
39
|
+
class Person < ActiveRecord::Base
|
40
|
+
belongs_to :team, :polymorphic => :true
|
41
|
+
has_many :contacts
|
42
|
+
|
43
|
+
has_many :friendships
|
44
|
+
has_many :friends, :through => :friendships
|
45
|
+
|
46
|
+
has_many :tags
|
47
|
+
has_many :football_teams, :through => :tags
|
48
|
+
|
49
|
+
has_and_belongs_to_many :links
|
50
|
+
|
51
|
+
define_index do
|
52
|
+
indexes [first_name, middle_initial, last_name], :as => :name
|
53
|
+
indexes team.name, :as => :team_name
|
54
|
+
indexes contacts.phone_number, :as => :phone_numbers
|
55
|
+
indexes city, :prefixes => true, :facet => true
|
56
|
+
indexes state, :infixes => true, :facet => true
|
57
|
+
|
58
|
+
has [first_name, middle_initial, last_name], :as => :name_sort
|
59
|
+
has team.name, :as => :team_name_sort
|
60
|
+
|
61
|
+
has [:id, :team_id], :as => :ids
|
62
|
+
has team(:id), :as => :team_id
|
63
|
+
|
64
|
+
has contacts.phone_number, :as => :phone_number_sort
|
65
|
+
has contacts(:id), :as => :contact_ids
|
66
|
+
|
67
|
+
has birthday, :facet => true
|
68
|
+
|
69
|
+
has friendships.person_id, :as => :friendly_ids
|
70
|
+
|
71
|
+
has :id, :as => :latitude
|
72
|
+
has :id, :as => :longitude
|
73
|
+
|
74
|
+
set_property :delta => true
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
class Parent < Person
|
79
|
+
end
|
80
|
+
|
81
|
+
module Admin
|
82
|
+
class Person < ::Person
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
class Child < Person
|
87
|
+
belongs_to :parent
|
88
|
+
define_index do
|
89
|
+
indexes [parent.first_name, parent.middle_initial, parent.last_name], :as => :parent_name
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
class Alpha < ActiveRecord::Base
|
94
|
+
has_many :betas
|
95
|
+
|
96
|
+
define_index do
|
97
|
+
indexes :name, :sortable => true
|
98
|
+
|
99
|
+
has :id, :as => :lat
|
100
|
+
has :id, :as => :lng
|
101
|
+
|
102
|
+
set_property :field_weights => {"name" => 10}
|
103
|
+
end
|
104
|
+
|
105
|
+
def big_name
|
106
|
+
name.upcase
|
107
|
+
end
|
108
|
+
|
109
|
+
def string_to_escape
|
110
|
+
'test "escaping" <characters>'
|
111
|
+
end
|
112
|
+
|
113
|
+
def sphinx_attributes
|
114
|
+
:existing
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
class Beta < ActiveRecord::Base
|
119
|
+
has_many :gammas
|
120
|
+
|
121
|
+
define_index do
|
122
|
+
indexes :name, :sortable => true
|
123
|
+
|
124
|
+
has :id, :as => :lat
|
125
|
+
has :id, :as => :lon
|
126
|
+
|
127
|
+
set_property :delta => true
|
128
|
+
end
|
129
|
+
|
130
|
+
def excerpts
|
131
|
+
false
|
132
|
+
end
|
133
|
+
|
134
|
+
def matching_fields
|
135
|
+
:foo
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
class Gamma < ActiveRecord::Base
|
140
|
+
#
|
141
|
+
end
|
142
|
+
|
143
|
+
class Search < ActiveRecord::Base
|
144
|
+
#
|
145
|
+
end
|
@@ -0,0 +1,125 @@
|
|
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
|
+
`created_on` date NULL,
|
31
|
+
`updated_at` datetime NOT NULL,
|
32
|
+
PRIMARY KEY (`id`)
|
33
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
34
|
+
|
35
|
+
DROP TABLE IF EXISTS `football_teams`;
|
36
|
+
|
37
|
+
CREATE TABLE `football_teams` (
|
38
|
+
`id` int(11) NOT NULL auto_increment,
|
39
|
+
`name` varchar(50) NOT NULL,
|
40
|
+
`state` varchar(50) NOT NULL,
|
41
|
+
PRIMARY KEY (`id`)
|
42
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
43
|
+
|
44
|
+
DROP TABLE IF EXISTS `cricket_teams`;
|
45
|
+
|
46
|
+
CREATE TABLE `cricket_teams` (
|
47
|
+
`id` int(11) NOT NULL auto_increment,
|
48
|
+
`name` varchar(50) NOT NULL,
|
49
|
+
`state` varchar(50) NOT NULL,
|
50
|
+
PRIMARY KEY (`id`)
|
51
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
52
|
+
|
53
|
+
DROP TABLE IF EXISTS `contacts`;
|
54
|
+
|
55
|
+
CREATE TABLE `contacts` (
|
56
|
+
`id` int(11) NOT NULL auto_increment,
|
57
|
+
`phone_number` varchar(50) NOT NULL,
|
58
|
+
`person_id` int(11) NOT NULL,
|
59
|
+
PRIMARY KEY (`id`)
|
60
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
61
|
+
|
62
|
+
DROP TABLE IF EXISTS `alphas`;
|
63
|
+
|
64
|
+
CREATE TABLE `alphas` (
|
65
|
+
`id` int(11) NOT NULL auto_increment,
|
66
|
+
`name` varchar(50) NOT NULL,
|
67
|
+
`value` int(11),
|
68
|
+
`cost` decimal(10,6),
|
69
|
+
PRIMARY KEY (`id`)
|
70
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
71
|
+
|
72
|
+
DROP TABLE IF EXISTS `betas`;
|
73
|
+
|
74
|
+
CREATE TABLE `betas` (
|
75
|
+
`id` int(11) NOT NULL auto_increment,
|
76
|
+
`name` varchar(50) NOT NULL,
|
77
|
+
`alpha_id` int(11),
|
78
|
+
`delta` tinyint(1) NOT NULL DEFAULT 0,
|
79
|
+
PRIMARY KEY (`id`)
|
80
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
81
|
+
|
82
|
+
DROP TABLE IF EXISTS `gammas`;
|
83
|
+
|
84
|
+
CREATE TABLE `gammas` (
|
85
|
+
`id` int(11) NOT NULL auto_increment,
|
86
|
+
`name` varchar(50) NOT NULL,
|
87
|
+
`value` int(11),
|
88
|
+
`beta_id` int(11),
|
89
|
+
PRIMARY KEY (`id`)
|
90
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
91
|
+
|
92
|
+
DROP TABLE IF EXISTS `searches`;
|
93
|
+
|
94
|
+
CREATE TABLE `searches` (
|
95
|
+
`id` int(11) NOT NULL auto_increment,
|
96
|
+
`name` varchar(50) NOT NULL,
|
97
|
+
PRIMARY KEY (`id`)
|
98
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
99
|
+
|
100
|
+
DROP TABLE IF EXISTS `tags`;
|
101
|
+
|
102
|
+
CREATE TABLE `tags` (
|
103
|
+
`id` int(11) NOT NULL auto_increment,
|
104
|
+
`person_id` int(11) NOT NULL,
|
105
|
+
`football_team_id` int(11) NOT NULL,
|
106
|
+
`cricket_team_id` int(11) NOT NULL,
|
107
|
+
`name` varchar(50) NOT NULL,
|
108
|
+
PRIMARY KEY (`id`)
|
109
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
110
|
+
|
111
|
+
DROP TABLE IF EXISTS `links`;
|
112
|
+
|
113
|
+
CREATE TABLE `links` (
|
114
|
+
`id` int(11) NOT NULL auto_increment,
|
115
|
+
`url` varchar(50) NOT NULL,
|
116
|
+
`description` varchar(200),
|
117
|
+
PRIMARY KEY (`id`)
|
118
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
119
|
+
|
120
|
+
DROP TABLE IF EXISTS `links_people`;
|
121
|
+
|
122
|
+
CREATE TABLE `links_people` (
|
123
|
+
`link_id` int(11) NOT NULL,
|
124
|
+
`person_id` int(11) NOT NULL
|
125
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__) + '/../lib'
|
2
|
+
Dir[File.join(File.dirname(__FILE__), '../vendor/*/lib')].each do |path|
|
3
|
+
$:.unshift path
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'fileutils'
|
8
|
+
require 'ginger'
|
9
|
+
require 'jeweler'
|
10
|
+
|
11
|
+
require "lib/thinking_sphinx"
|
12
|
+
|
13
|
+
require 'will_paginate'
|
14
|
+
|
15
|
+
require 'spec/sphinx_helper'
|
16
|
+
|
17
|
+
ActiveRecord::Base.logger = Logger.new(StringIO.new)
|
18
|
+
|
19
|
+
Spec::Runner.configure do |config|
|
20
|
+
%w( tmp tmp/config tmp/log tmp/db ).each do |path|
|
21
|
+
FileUtils.mkdir_p "#{Dir.pwd}/#{path}"
|
22
|
+
end
|
23
|
+
|
24
|
+
Kernel.const_set :RAILS_ROOT, "#{Dir.pwd}/tmp" unless defined?(RAILS_ROOT)
|
25
|
+
|
26
|
+
sphinx = SphinxHelper.new
|
27
|
+
sphinx.setup_mysql
|
28
|
+
|
29
|
+
require 'spec/fixtures/models'
|
30
|
+
ThinkingSphinx.context.define_indexes
|
31
|
+
|
32
|
+
config.before :all do
|
33
|
+
%w( tmp tmp/config tmp/log tmp/db ).each do |path|
|
34
|
+
FileUtils.mkdir_p "#{Dir.pwd}/#{path}"
|
35
|
+
end
|
36
|
+
|
37
|
+
ThinkingSphinx.updates_enabled = true
|
38
|
+
ThinkingSphinx.deltas_enabled = true
|
39
|
+
ThinkingSphinx.suppress_delta_output = true
|
40
|
+
|
41
|
+
ThinkingSphinx::Configuration.instance.reset
|
42
|
+
ThinkingSphinx::Configuration.instance.database_yml_file = "spec/fixtures/sphinx/database.yml"
|
43
|
+
end
|
44
|
+
|
45
|
+
config.after :all do
|
46
|
+
FileUtils.rm_r "#{Dir.pwd}/tmp" rescue nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def minimal_result_hashes(*instances)
|
51
|
+
instances.collect do |instance|
|
52
|
+
{
|
53
|
+
:weight => 21,
|
54
|
+
:attributes => {
|
55
|
+
'sphinx_internal_id' => instance.id,
|
56
|
+
'class_crc' => instance.class.name.to_crc32
|
57
|
+
}
|
58
|
+
}
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
prefix = defined?(JRUBY_VERSION) ? "jdbc" : ""
|
3
|
+
require "active_record/connection_adapters/#{prefix}mysql_adapter"
|
4
|
+
begin
|
5
|
+
require "active_record/connection_adapters/#{prefix}postgresql_adapter"
|
6
|
+
rescue LoadError
|
7
|
+
# No postgres? no prob...
|
8
|
+
end
|
9
|
+
require 'yaml'
|
10
|
+
|
11
|
+
class SphinxHelper
|
12
|
+
attr_accessor :host, :username, :password, :socket
|
13
|
+
attr_reader :path
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
@host = "localhost"
|
17
|
+
@username = "thinking_sphinx"
|
18
|
+
@password = ""
|
19
|
+
|
20
|
+
if File.exist?("spec/fixtures/database.yml")
|
21
|
+
config = YAML.load(File.open("spec/fixtures/database.yml"))
|
22
|
+
@host = config["host"]
|
23
|
+
@username = config["username"]
|
24
|
+
@password = config["password"]
|
25
|
+
@socket = config["socket"]
|
26
|
+
end
|
27
|
+
|
28
|
+
@path = File.expand_path(File.dirname(__FILE__))
|
29
|
+
end
|
30
|
+
|
31
|
+
def mysql_adapter
|
32
|
+
defined?(JRUBY_VERSION) ? 'jdbcmysql' : 'mysql'
|
33
|
+
end
|
34
|
+
|
35
|
+
def setup_mysql
|
36
|
+
ActiveRecord::Base.establish_connection(
|
37
|
+
:adapter => mysql_adapter,
|
38
|
+
:database => 'thinking_sphinx',
|
39
|
+
:username => @username,
|
40
|
+
:password => @password,
|
41
|
+
:host => @host,
|
42
|
+
:socket => @socket
|
43
|
+
)
|
44
|
+
ActiveRecord::Base.logger = Logger.new(File.open("tmp/activerecord.log", "a"))
|
45
|
+
|
46
|
+
structure = File.open("spec/fixtures/structure.sql") { |f| f.read.chomp }
|
47
|
+
structure.split(';').each { |table|
|
48
|
+
ActiveRecord::Base.connection.execute table
|
49
|
+
}
|
50
|
+
|
51
|
+
File.open("spec/fixtures/data.sql") { |f|
|
52
|
+
while line = f.gets
|
53
|
+
ActiveRecord::Base.connection.execute line unless line.blank?
|
54
|
+
end
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
def setup_sphinx
|
59
|
+
@configuration = ThinkingSphinx::Configuration.instance.reset
|
60
|
+
File.open("spec/fixtures/sphinx/database.yml", "w") do |file|
|
61
|
+
YAML.dump({@configuration.environment => {
|
62
|
+
:adapter => mysql_adapter,
|
63
|
+
:host => @host,
|
64
|
+
:database => "thinking_sphinx",
|
65
|
+
:username => @username,
|
66
|
+
:password => @password
|
67
|
+
}}, file)
|
68
|
+
end
|
69
|
+
FileUtils.mkdir_p(@configuration.searchd_file_path)
|
70
|
+
|
71
|
+
@configuration.database_yml_file = "spec/fixtures/sphinx/database.yml"
|
72
|
+
@configuration.build
|
73
|
+
|
74
|
+
index
|
75
|
+
end
|
76
|
+
|
77
|
+
def reset
|
78
|
+
setup_mysql
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe "ThinkingSphinx::ActiveRecord::Delta" do
|
4
|
+
it "should call the toggle_delta method after a save" do
|
5
|
+
@beta = Beta.new(:name => 'beta')
|
6
|
+
@beta.should_receive(:toggle_delta).and_return(true)
|
7
|
+
|
8
|
+
@beta.save
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should call the toggle_delta method after a save!" do
|
12
|
+
@beta = Beta.new(:name => 'beta')
|
13
|
+
@beta.should_receive(:toggle_delta).and_return(true)
|
14
|
+
|
15
|
+
@beta.save!
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "suspended_delta method" do
|
19
|
+
before :each do
|
20
|
+
ThinkingSphinx.deltas_enabled = true
|
21
|
+
Person.sphinx_indexes.first.delta_object.stub!(:` => "")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should execute the argument block with deltas disabled" do
|
25
|
+
ThinkingSphinx.should_receive(:deltas_enabled=).once.with(false)
|
26
|
+
ThinkingSphinx.should_receive(:deltas_enabled=).once.with(true)
|
27
|
+
lambda { Person.suspended_delta { raise 'i was called' } }.should(
|
28
|
+
raise_error(Exception)
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should restore deltas_enabled to its original setting" do
|
33
|
+
ThinkingSphinx.deltas_enabled = false
|
34
|
+
ThinkingSphinx.should_receive(:deltas_enabled=).twice.with(false)
|
35
|
+
Person.suspended_delta { 'no-op' }
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should restore deltas_enabled to its original setting even if there was an exception" do
|
39
|
+
ThinkingSphinx.deltas_enabled = false
|
40
|
+
ThinkingSphinx.should_receive(:deltas_enabled=).twice.with(false)
|
41
|
+
lambda { Person.suspended_delta { raise 'bad error' } }.should(
|
42
|
+
raise_error(Exception)
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should reindex by default after the code block is run" do
|
47
|
+
Person.should_receive(:index_delta)
|
48
|
+
Person.suspended_delta { 'no-op' }
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should not reindex after the code block if false is passed in" do
|
52
|
+
Person.should_not_receive(:index_delta)
|
53
|
+
Person.suspended_delta(false) { 'no-op' }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "toggle_delta method" do
|
58
|
+
it "should set the delta value to true" do
|
59
|
+
@person = Person.new
|
60
|
+
|
61
|
+
@person.delta.should be_false
|
62
|
+
@person.send(:toggle_delta)
|
63
|
+
@person.delta.should be_true
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "index_delta method" do
|
68
|
+
before :each do
|
69
|
+
ThinkingSphinx::Configuration.stub!(:environment => "spec")
|
70
|
+
ThinkingSphinx.deltas_enabled = true
|
71
|
+
ThinkingSphinx.updates_enabled = true
|
72
|
+
ThinkingSphinx.stub!(:sphinx_running? => true)
|
73
|
+
Person.delta_object.stub!(:` => "", :toggled => true)
|
74
|
+
|
75
|
+
@person = Person.new
|
76
|
+
Person.stub!(:search_for_id => false)
|
77
|
+
@person.stub!(:sphinx_document_id => 1)
|
78
|
+
|
79
|
+
@client = Riddle::Client.new
|
80
|
+
@client.stub!(:update => true)
|
81
|
+
ThinkingSphinx::Configuration.instance.stub!(:client => @client)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "shouldn't index if delta indexing is disabled" do
|
85
|
+
ThinkingSphinx.deltas_enabled = false
|
86
|
+
Person.sphinx_indexes.first.delta_object.should_not_receive(:`)
|
87
|
+
@client.should_not_receive(:update)
|
88
|
+
|
89
|
+
@person.send(:index_delta)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "shouldn't index if index updating is disabled" do
|
93
|
+
ThinkingSphinx.updates_enabled = false
|
94
|
+
Person.sphinx_indexes.first.delta_object.should_not_receive(:`)
|
95
|
+
|
96
|
+
@person.send(:index_delta)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "shouldn't index if the environment is 'test'" do
|
100
|
+
ThinkingSphinx.deltas_enabled = nil
|
101
|
+
ThinkingSphinx::Configuration.stub!(:environment => "test")
|
102
|
+
Person.sphinx_indexes.first.delta_object.should_not_receive(:`)
|
103
|
+
|
104
|
+
@person.send(:index_delta)
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should call indexer for the delta index" do
|
108
|
+
Person.sphinx_indexes.first.delta_object.should_receive(:`).with(
|
109
|
+
"#{ThinkingSphinx::Configuration.instance.bin_path}indexer --config #{ThinkingSphinx::Configuration.instance.config_file} --rotate person_delta"
|
110
|
+
)
|
111
|
+
|
112
|
+
@person.send(:index_delta)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "shouldn't update the deleted attribute if not in the index" do
|
116
|
+
@client.should_not_receive(:update)
|
117
|
+
|
118
|
+
@person.send(:index_delta)
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should update the deleted attribute if in the core index" do
|
122
|
+
Person.stub!(:search_for_id => true)
|
123
|
+
@client.should_receive(:update)
|
124
|
+
|
125
|
+
@person.send(:index_delta)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe 'ThinkingSphinx::ActiveRecord::HasManyAssociation' do
|
4
|
+
describe "search method" do
|
5
|
+
before :each do
|
6
|
+
Friendship.stub!(:search => true)
|
7
|
+
|
8
|
+
@person = Person.find(:first)
|
9
|
+
@index = Friendship.sphinx_indexes.first
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should raise an error if the required attribute doesn't exist" do
|
13
|
+
@index.stub!(:attributes => [])
|
14
|
+
|
15
|
+
lambda { @person.friendships.search "test" }.should raise_error(RuntimeError)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should add a filter for the attribute into a normal search call" do
|
19
|
+
Friendship.should_receive(:search) do |query, options|
|
20
|
+
options[:with][:person_id].should == @person.id
|
21
|
+
end
|
22
|
+
|
23
|
+
@person.friendships.search "test"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should define indexes for the reflection class" do
|
27
|
+
Friendship.should_receive(:define_indexes)
|
28
|
+
|
29
|
+
@person.friendships.search 'test'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "search method for has_many :through" do
|
34
|
+
before :each do
|
35
|
+
Person.stub!(:search => true)
|
36
|
+
|
37
|
+
@person = Person.find(:first)
|
38
|
+
@index = Person.sphinx_indexes.first
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should raise an error if the required attribute doesn't exist" do
|
42
|
+
@index.stub!(:attributes => [])
|
43
|
+
|
44
|
+
lambda { @person.friends.search "test" }.should raise_error(RuntimeError)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should add a filter for the attribute into a normal search call" do
|
48
|
+
Person.should_receive(:search).with do |query, options|
|
49
|
+
options[:with][:friendly_ids].should == @person.id
|
50
|
+
end
|
51
|
+
|
52
|
+
@person.friends.search "test"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|