thinking-sphinx 2.0.5 → 2.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/README.textile +7 -1
  2. data/features/searching_by_model.feature +24 -30
  3. data/features/step_definitions/common_steps.rb +5 -5
  4. data/features/thinking_sphinx/db/.gitignore +1 -0
  5. data/features/thinking_sphinx/db/fixtures/post_keywords.txt +1 -0
  6. data/spec/fixtures/data.sql +32 -0
  7. data/spec/fixtures/database.yml.default +3 -0
  8. data/spec/fixtures/models.rb +161 -0
  9. data/spec/fixtures/structure.sql +146 -0
  10. data/spec/spec_helper.rb +62 -0
  11. data/spec/sphinx_helper.rb +61 -0
  12. data/spec/support/rails.rb +18 -0
  13. data/spec/thinking_sphinx/active_record/delta_spec.rb +24 -24
  14. data/spec/thinking_sphinx/active_record/has_many_association_spec.rb +27 -0
  15. data/spec/thinking_sphinx/active_record/scopes_spec.rb +25 -25
  16. data/spec/thinking_sphinx/active_record_spec.rb +108 -107
  17. data/spec/thinking_sphinx/adapters/abstract_adapter_spec.rb +38 -38
  18. data/spec/thinking_sphinx/association_spec.rb +69 -35
  19. data/spec/thinking_sphinx/context_spec.rb +61 -64
  20. data/spec/thinking_sphinx/search_spec.rb +7 -0
  21. data/spec/thinking_sphinx_spec.rb +47 -46
  22. metadata +49 -141
  23. data/VERSION +0 -1
  24. data/lib/cucumber/thinking_sphinx/external_world.rb +0 -12
  25. data/lib/cucumber/thinking_sphinx/internal_world.rb +0 -127
  26. data/lib/cucumber/thinking_sphinx/sql_logger.rb +0 -20
  27. data/lib/thinking-sphinx.rb +0 -1
  28. data/lib/thinking_sphinx.rb +0 -301
  29. data/lib/thinking_sphinx/action_controller.rb +0 -31
  30. data/lib/thinking_sphinx/active_record.rb +0 -384
  31. data/lib/thinking_sphinx/active_record/attribute_updates.rb +0 -52
  32. data/lib/thinking_sphinx/active_record/delta.rb +0 -65
  33. data/lib/thinking_sphinx/active_record/has_many_association.rb +0 -36
  34. data/lib/thinking_sphinx/active_record/has_many_association_with_scopes.rb +0 -21
  35. data/lib/thinking_sphinx/active_record/log_subscriber.rb +0 -61
  36. data/lib/thinking_sphinx/active_record/scopes.rb +0 -93
  37. data/lib/thinking_sphinx/adapters/abstract_adapter.rb +0 -87
  38. data/lib/thinking_sphinx/adapters/mysql_adapter.rb +0 -62
  39. data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +0 -157
  40. data/lib/thinking_sphinx/association.rb +0 -219
  41. data/lib/thinking_sphinx/attribute.rb +0 -396
  42. data/lib/thinking_sphinx/auto_version.rb +0 -38
  43. data/lib/thinking_sphinx/bundled_search.rb +0 -44
  44. data/lib/thinking_sphinx/class_facet.rb +0 -20
  45. data/lib/thinking_sphinx/configuration.rb +0 -339
  46. data/lib/thinking_sphinx/context.rb +0 -76
  47. data/lib/thinking_sphinx/core/string.rb +0 -15
  48. data/lib/thinking_sphinx/deltas.rb +0 -28
  49. data/lib/thinking_sphinx/deltas/default_delta.rb +0 -62
  50. data/lib/thinking_sphinx/deploy/capistrano.rb +0 -101
  51. data/lib/thinking_sphinx/excerpter.rb +0 -23
  52. data/lib/thinking_sphinx/facet.rb +0 -128
  53. data/lib/thinking_sphinx/facet_search.rb +0 -170
  54. data/lib/thinking_sphinx/field.rb +0 -98
  55. data/lib/thinking_sphinx/index.rb +0 -157
  56. data/lib/thinking_sphinx/index/builder.rb +0 -312
  57. data/lib/thinking_sphinx/index/faux_column.rb +0 -118
  58. data/lib/thinking_sphinx/join.rb +0 -37
  59. data/lib/thinking_sphinx/property.rb +0 -185
  60. data/lib/thinking_sphinx/railtie.rb +0 -46
  61. data/lib/thinking_sphinx/search.rb +0 -972
  62. data/lib/thinking_sphinx/search_methods.rb +0 -439
  63. data/lib/thinking_sphinx/sinatra.rb +0 -7
  64. data/lib/thinking_sphinx/source.rb +0 -194
  65. data/lib/thinking_sphinx/source/internal_properties.rb +0 -51
  66. data/lib/thinking_sphinx/source/sql.rb +0 -157
  67. data/lib/thinking_sphinx/tasks.rb +0 -130
  68. data/lib/thinking_sphinx/test.rb +0 -55
  69. data/tasks/distribution.rb +0 -33
  70. data/tasks/testing.rb +0 -80
data/README.textile CHANGED
@@ -126,7 +126,6 @@ Since I first released this library, there's been quite a few people who have su
126
126
  * Andrei Bocan
127
127
  * László Bácsi
128
128
  * Peter Wagenet
129
- * Max Lapshin
130
129
  * Martin Emde
131
130
  * David Wennergren
132
131
  * Mark Lane
@@ -210,3 +209,10 @@ Since I first released this library, there's been quite a few people who have su
210
209
  * Alex Chee
211
210
  * Florent Piteau
212
211
  * Bruno Santschi
212
+ * Lars Weiler
213
+ * Andrey Deryabin
214
+ * Andrew White
215
+ * Rémi Prévost
216
+ * Justin Tanner
217
+ * Josh Goebel
218
+ * Jonathan Viney
@@ -2,19 +2,19 @@ Feature: Searching on a single model
2
2
  In order to use Thinking Sphinx's core functionality
3
3
  A developer
4
4
  Should be able to search on a single model
5
-
5
+
6
6
  Scenario: Searching using a basic query
7
7
  Given Sphinx is running
8
8
  And I am searching on people
9
9
  When I search for James
10
10
  Then I should get 3 results
11
-
11
+
12
12
  Scenario: Searching on a specific field
13
13
  Given Sphinx is running
14
14
  And I am searching on people
15
15
  When I search for James on first_name
16
16
  Then I should get 2 results
17
-
17
+
18
18
  Scenario: Searching on multiple fields
19
19
  Given Sphinx is running
20
20
  And I am searching on people
@@ -25,32 +25,32 @@ Feature: Searching on a single model
25
25
  Scenario: Searching on association content
26
26
  Given Sphinx is running
27
27
  And I am searching on posts
28
-
28
+
29
29
  When I search for "Waffles"
30
30
  Then I should get 1 result
31
31
 
32
32
  When I search for "Turtle"
33
33
  Then I should get 1 result
34
-
34
+
35
35
  Scenario: Searching with a filter
36
36
  Given Sphinx is running
37
37
  And I am searching on alphas
38
38
  When I filter by 1 on value
39
39
  Then I should get 1 result
40
-
40
+
41
41
  Scenario: Searching with multiple filters
42
42
  Given Sphinx is running
43
43
  And I am searching on boxes
44
44
  When I filter by 2 on width
45
45
  And I filter by 2 on length
46
46
  Then I should get 1 result
47
-
47
+
48
48
  Scenario: Searching with a ranged time filter
49
49
  Given Sphinx is running
50
50
  And I am searching on people
51
51
  When I filter by birthday between 1975 and 1976
52
52
  Then I should get 16 results
53
-
53
+
54
54
  Scenario: Searching to filter multiple values on an MVA
55
55
  Given Sphinx is running
56
56
  And I am searching on boxes
@@ -59,31 +59,25 @@ Feature: Searching on a single model
59
59
  When I clear existing filters
60
60
  And I filter by both 11 and 12 on dimensions
61
61
  Then I should get 1 result
62
-
62
+
63
63
  Scenario: Filtering on timestamp MVAs
64
64
  Given Sphinx is running
65
65
  And I am searching on posts
66
66
  When I filter by 2001-01-01 on comments_created_at
67
67
  Then I should get 1 result
68
-
69
- Scenario: Filtering on a wordcount attribute
70
- Given Sphinx is running
71
- And I am searching on developers
72
- When I filter between 0 and 1 on state_wordcount
73
- Then I should get 5 results
74
-
68
+
75
69
  Scenario: Searching by NULL/0 values in MVAs
76
70
  Given Sphinx is running
77
71
  And I am searching on boxes
78
72
  When I filter by 0 on dimensions
79
73
  Then I should get 1 result
80
-
74
+
81
75
  Given Sphinx is running
82
76
  And I am searching on developers
83
77
  When I clear existing filters
84
78
  And I filter by 0 on tag_ids
85
79
  Then I should get 1 result
86
-
80
+
87
81
  Scenario: Searching on a MVA configured as ranged_query
88
82
  Given Sphinx is running
89
83
  And I am searching on posts
@@ -95,59 +89,59 @@ Feature: Searching on a single model
95
89
  When I clear existing filters
96
90
  And I filter by 10 on comment_ids
97
91
  Then I should get 0 results
98
-
92
+
99
93
  Scenario: Searching with ordering by attribute
100
94
  Given Sphinx is running
101
95
  And I am searching on alphas
102
96
  When I order by value
103
97
  Then I should get 10 results
104
98
  And the value of each result should indicate order
105
-
99
+
106
100
  Scenario: Intepreting Sphinx Internal Identifiers
107
101
  Given Sphinx is running
108
102
  And I am searching on people
109
103
  Then I should get 20 results
110
104
  And each result id should match the corresponding sphinx internal id
111
-
105
+
112
106
  Scenario: Retrieving weightings
113
107
  Given Sphinx is running
114
108
  And I am searching on people
115
109
  When I search for "Ellie Ford"
116
110
  And I set match mode to any
117
111
  Then I can iterate by result and weighting
118
-
112
+
119
113
  Scenario: Retrieving group counts
120
114
  Given Sphinx is running
121
115
  And I am searching on people
122
116
  When I group results by the birthday attribute
123
117
  Then I can iterate by result and count
124
-
118
+
125
119
  Scenario: Retrieving group values
126
120
  Given Sphinx is running
127
121
  And I am searching on people
128
122
  When I group results by the birthday attribute
129
123
  Then I can iterate by result and group
130
-
124
+
131
125
  Scenario: Retrieving both group values and counts
132
126
  Given Sphinx is running
133
127
  And I am searching on people
134
128
  When I group results by the birthday attribute
135
129
  Then I can iterate by result and group and count
136
-
130
+
137
131
  Scenario: Searching for ids
138
132
  Given Sphinx is running
139
133
  And I am searching on people
140
134
  When I search for Ellie
141
135
  And I am searching for ids
142
136
  Then I should have an array of integers
143
-
137
+
144
138
  Scenario: Search results should match Sphinx's order
145
139
  Given Sphinx is running
146
140
  And I am searching on people
147
141
  When I search for Ellie
148
142
  And I order by "sphinx_internal_id DESC"
149
143
  Then searching for ids should match the record ids of the normal search results
150
-
144
+
151
145
  Scenario: Retrieving total result count when total is less than a page
152
146
  Given Sphinx is running
153
147
  And I am searching on people
@@ -160,7 +154,7 @@ Feature: Searching on a single model
160
154
  And I am searching on people
161
155
  When I am retrieving the result count
162
156
  Then I should get a value of 1000
163
-
157
+
164
158
  Scenario: Searching with Unicode Characters
165
159
  Given Sphinx is running
166
160
  And I am searching on people
@@ -172,10 +166,10 @@ Feature: Searching on a single model
172
166
  And I am searching on posts
173
167
  When I search for "Shakespeare"
174
168
  Then I should get 1 result
175
-
169
+
176
170
  Scenario: Searching on content from file field
177
171
  Given Sphinx is running
178
172
  And I am searching on posts
179
173
  When I search for "foo bar baz"
180
174
  Then I should get 1 result
181
-
175
+
@@ -1,6 +1,6 @@
1
1
  Before do
2
2
  $queries_executed = []
3
-
3
+
4
4
  @model = nil
5
5
  @method = :search
6
6
  @query = ""
@@ -10,7 +10,7 @@ Before do
10
10
  @with_all = {}
11
11
  @options = {}
12
12
  @results = nil
13
-
13
+
14
14
  Given "updates are enabled"
15
15
  end
16
16
 
@@ -73,7 +73,7 @@ end
73
73
 
74
74
  When /^I filter by (\d\d\d\d)\-(\d\d)\-(\d\d) on (\w+)$/ do |y, m, d, attribute|
75
75
  @results = nil
76
- @with[attribute.to_sym] = Time.local(y.to_i, m.to_i, d.to_i).to_i
76
+ @with[attribute.to_sym] = Time.gm(y.to_i, m.to_i, d.to_i).to_i
77
77
  end
78
78
 
79
79
  When /^I filter by (\d+) and (\d+) on (\w+)$/ do |value_one, value_two, attribute|
@@ -150,7 +150,7 @@ Then /^the (\w+) of each result should indicate order$/ do |attribute|
150
150
  unless prev.nil?
151
151
  current.send(attribute.to_sym).should >= prev.send(attribute.to_sym)
152
152
  end
153
-
153
+
154
154
  current
155
155
  end
156
156
  end
@@ -166,7 +166,7 @@ Then /^I can iterate by result and (\w+)$/ do |attribute|
166
166
  attr_value.should be_kind_of(Integer)
167
167
  end
168
168
  }
169
-
169
+
170
170
  results.send("each_with_#{attribute}", &iteration)
171
171
  end
172
172
 
@@ -0,0 +1 @@
1
+ database.yml
@@ -0,0 +1 @@
1
+ foo bar baz
@@ -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, :class_name => 'Beta'
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