supernova 0.3.13 → 0.4.13

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/Gemfile CHANGED
@@ -6,10 +6,11 @@ source "http://rubygems.org"
6
6
  # Add dependencies to develop your gem here.
7
7
  # Include everything needed to run rake, tests, features, etc.
8
8
 
9
- gem "thinking-sphinx", "2.0.3"
10
9
  gem "rsolr"
11
10
  gem "will_paginate"
12
11
  gem "json"
12
+ gem "activesupport"
13
+ gem "activerecord"
13
14
 
14
15
  group :development do
15
16
  gem "ruby-debug"
@@ -2,17 +2,18 @@ GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
4
  ZenTest (4.5.0)
5
- activemodel (3.0.8)
6
- activesupport (= 3.0.8)
5
+ activemodel (3.0.0)
6
+ activesupport (= 3.0.0)
7
7
  builder (~> 2.1.2)
8
- i18n (~> 0.5.0)
9
- activerecord (3.0.8)
10
- activemodel (= 3.0.8)
11
- activesupport (= 3.0.8)
12
- arel (~> 2.0.10)
8
+ i18n (~> 0.4.1)
9
+ activerecord (3.0.0)
10
+ activemodel (= 3.0.0)
11
+ activesupport (= 3.0.0)
12
+ arel (~> 1.0.0)
13
13
  tzinfo (~> 0.3.23)
14
- activesupport (3.0.8)
15
- arel (2.0.10)
14
+ activesupport (3.0.0)
15
+ arel (1.0.1)
16
+ activesupport (~> 3.0.0)
16
17
  autotest (4.4.6)
17
18
  ZenTest (>= 4.4.1)
18
19
  autotest-growl (0.2.9)
@@ -21,7 +22,7 @@ GEM
21
22
  diff-lcs (1.1.2)
22
23
  geokit (1.6.0)
23
24
  git (1.2.5)
24
- i18n (0.5.0)
25
+ i18n (0.4.2)
25
26
  jeweler (1.6.2)
26
27
  bundler (~> 1.0)
27
28
  git (>= 1.2.5)
@@ -31,7 +32,6 @@ GEM
31
32
  mysql2 (0.2.7)
32
33
  rake (0.9.2)
33
34
  rcov (0.9.9)
34
- riddle (1.3.3)
35
35
  rsolr (1.0.2)
36
36
  builder (>= 2.1.2)
37
37
  rspec (2.3.0)
@@ -47,16 +47,15 @@ GEM
47
47
  ruby-debug-base (~> 0.10.4.0)
48
48
  ruby-debug-base (0.10.4)
49
49
  linecache (>= 0.3)
50
- thinking-sphinx (2.0.3)
51
- activerecord (>= 3.0.3)
52
- riddle (>= 1.2.2)
53
- tzinfo (0.3.27)
50
+ tzinfo (0.3.29)
54
51
  will_paginate (2.3.15)
55
52
 
56
53
  PLATFORMS
57
54
  ruby
58
55
 
59
56
  DEPENDENCIES
57
+ activerecord
58
+ activesupport
60
59
  autotest
61
60
  autotest-growl
62
61
  bundler (~> 1.0.0)
@@ -68,5 +67,4 @@ DEPENDENCIES
68
67
  rsolr
69
68
  rspec (~> 2.3.0)
70
69
  ruby-debug
71
- thinking-sphinx (= 2.0.3)
72
70
  will_paginate
@@ -2,12 +2,7 @@
2
2
 
3
3
  == Setup
4
4
 
5
- require "supernova"
6
- require "supernova/thinking_sphinx"
7
-
8
- class Offer
9
- include Supernova::ThinkingSphinx
10
- end
5
+ will come back soon!
11
6
 
12
7
  === Anonymous Scopes
13
8
 
@@ -24,8 +19,6 @@
24
19
  === Named Scopes
25
20
 
26
21
  class Offer
27
- include Supernova::ThinkingSphinx
28
-
29
22
  named_search_scope :popular do
30
23
  order("popularity desc")
31
24
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.13
1
+ 0.4.13
@@ -41,5 +41,4 @@ require "supernova/symbol_extensions"
41
41
  require "supernova/condition"
42
42
  require "supernova/collection"
43
43
  require "supernova/criteria"
44
- require "supernova/thinking_sphinx"
45
44
  require "supernova/solr"
@@ -0,0 +1,3 @@
1
+ root = File.expand_path("..", __FILE__)
2
+ cmd = "cd /usr/local/Cellar/solr/3.1.0/libexec/example/ && java -Dsolr.data.dir=#{root}/data -Dsolr.solr.home=#{root} -Djetty.port=8985 -jar start.jar > #{File.expand_path("../log/solr.log", root)} 2>&1 &"
3
+ system(cmd)
@@ -24,7 +24,7 @@ describe "Solr" do
24
24
  after(:each) do
25
25
  Supernova::Solr.url = nil
26
26
  Supernova::Solr.instance_variable_set("@connection", nil)
27
- Offer.criteria_class = Supernova::ThinkingSphinxCriteria
27
+ Offer.criteria_class = Supernova::SolrCriteria
28
28
  end
29
29
 
30
30
  def new_criteria
@@ -7,6 +7,7 @@ require "logger"
7
7
  require "fileutils"
8
8
  require "ruby-debug"
9
9
  require "geokit"
10
+ require "active_record"
10
11
 
11
12
  if defined?(Debugger) && Debugger.respond_to?(:settings)
12
13
  Debugger.settings[:autolist] = 1
@@ -32,33 +33,13 @@ ActiveRecord::Base.establish_connection(
32
33
  )
33
34
 
34
35
  PROJECT_ROOT = Pathname.new(File.expand_path("..", File.dirname(__FILE__)))
35
- FileUtils.mkdir_p(PROJECT_ROOT.join("db/sphinx/development"))
36
36
  FileUtils.mkdir_p(PROJECT_ROOT.join("log"))
37
- FileUtils.mkdir_p(PROJECT_ROOT.join("config"))
38
-
39
- ThinkingSphinx::ActiveRecord::LogSubscriber.logger = Logger.new(
40
- open(File.expand_path("../log/active_record.log", File.dirname(__FILE__)), "a")
41
- )
42
-
43
- ActiveRecord::Base.send(:include, ThinkingSphinx::ActiveRecord)
44
37
 
45
38
  ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS offers")
46
39
  ActiveRecord::Base.connection.execute("CREATE TABLE offers (id SERIAL, text TEXT, user_id INTEGER, enabled BOOLEAN, popularity INTEGER, lat FLOAT, lng FLOAT)")
47
40
 
48
41
  class Offer < ActiveRecord::Base
49
- include Supernova::ThinkingSphinx
50
-
51
- define_index do
52
- indexes text
53
-
54
- has :user_id
55
- has :enabled
56
- has :popularity, :sort => true
57
-
58
- has "RADIANS(lat)", :as => :lat, :type => :float
59
- has "RADIANS(lng)", :as => :lng, :type => :float
60
- end
61
-
42
+ include Supernova::Solr
62
43
  named_search_scope :for_user_ids do |*ids|
63
44
  with(:user_id => ids.flatten)
64
45
  end
@@ -3,12 +3,12 @@ require 'spec_helper'
3
3
  describe Supernova do
4
4
  let(:clazz) do
5
5
  clazz = Class.new
6
- clazz.send(:include, Supernova::ThinkingSphinx)
6
+ clazz.send(:include, Supernova::Solr)
7
7
  end
8
8
 
9
9
  describe "#including" do
10
10
  it "can be includes" do
11
- Class.new.send(:include, Supernova::ThinkingSphinx)
11
+ Class.new.send(:include, Supernova::Solr)
12
12
  end
13
13
 
14
14
  it "defines a named_search_scope method" do
@@ -19,7 +19,7 @@ describe Supernova do
19
19
 
20
20
  describe "#search_scope" do
21
21
  it "returns a new criteria" do
22
- clazz.search_scope.should be_an_instance_of(Supernova::ThinkingSphinxCriteria)
22
+ clazz.search_scope.should be_an_instance_of(Supernova::SolrCriteria)
23
23
  end
24
24
 
25
25
  it "sets the correct clazz" do
@@ -40,7 +40,7 @@ describe Supernova do
40
40
  end
41
41
 
42
42
  it "returns a new criteria" do
43
- clazz.popular.should be_an_instance_of(Supernova::ThinkingSphinxCriteria)
43
+ clazz.popular.should be_an_instance_of(Supernova::SolrCriteria)
44
44
  end
45
45
 
46
46
  it "sets the clazz attribute" do
@@ -58,11 +58,11 @@ describe Supernova do
58
58
 
59
59
  describe "chaining" do
60
60
  it "calls merge with both scopes" do
61
- scope = Supernova::ThinkingSphinxCriteria.new(clazz).named_scope_class(clazz)
62
- scope.should_receive(:merge).with(instance_of(Supernova::ThinkingSphinxCriteria))
61
+ scope = Supernova::SolrCriteria.new(clazz).named_scope_class(clazz)
62
+ scope.should_receive(:merge).with(instance_of(Supernova::SolrCriteria))
63
63
  scope.popular
64
64
  end
65
- # Supernova::ThinkingSphinxCriteria.new(clazz).popular.should be_an_instance_of()
65
+ # Supernova::SolrCriteria.new(clazz).popular.should be_an_instance_of()
66
66
  end
67
67
 
68
68
  describe "with parameters" do
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{supernova}
8
- s.version = "0.3.13"
8
+ s.version = "0.4.13"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tobias Schwab"]
12
- s.date = %q{2011-06-29}
12
+ s.date = %q{2011-07-18}
13
13
  s.description = %q{Unified search scopes}
14
14
  s.email = %q{tobias.schwab@dynport.de}
15
15
  s.executables = ["start_solr"]
@@ -38,8 +38,6 @@ Gem::Specification.new do |s|
38
38
  "lib/supernova/solr_criteria.rb",
39
39
  "lib/supernova/solr_indexer.rb",
40
40
  "lib/supernova/symbol_extensions.rb",
41
- "lib/supernova/thinking_sphinx.rb",
42
- "lib/supernova/thinking_sphinx_criteria.rb",
43
41
  "solr/conf/admin-extra.html",
44
42
  "solr/conf/elevate.xml",
45
43
  "solr/conf/mapping-FoldToASCII.txt",
@@ -77,9 +75,9 @@ Gem::Specification.new do |s|
77
75
  "solr/conf/xslt/example_atom.xsl",
78
76
  "solr/conf/xslt/example_rss.xsl",
79
77
  "solr/conf/xslt/luke.xsl",
78
+ "solr/start.rb",
80
79
  "spec/database.sql",
81
80
  "spec/integration/solr_spec.rb",
82
- "spec/integration/thinking_sphinx_spec.rb",
83
81
  "spec/spec_helper.rb",
84
82
  "spec/supernova/condition_spec.rb",
85
83
  "spec/supernova/criteria_spec.rb",
@@ -88,7 +86,6 @@ Gem::Specification.new do |s|
88
86
  "spec/supernova/solr_indexer_spec.rb",
89
87
  "spec/supernova/solr_spec.rb",
90
88
  "spec/supernova/symbol_extensions_spec.rb",
91
- "spec/supernova/thinking_sphinx_criteria_spec.rb",
92
89
  "spec/supernova_spec.rb",
93
90
  "supernova.gemspec"
94
91
  ]
@@ -102,10 +99,11 @@ Gem::Specification.new do |s|
102
99
  s.specification_version = 3
103
100
 
104
101
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
105
- s.add_runtime_dependency(%q<thinking-sphinx>, ["= 2.0.3"])
106
102
  s.add_runtime_dependency(%q<rsolr>, [">= 0"])
107
103
  s.add_runtime_dependency(%q<will_paginate>, [">= 0"])
108
104
  s.add_runtime_dependency(%q<json>, [">= 0"])
105
+ s.add_runtime_dependency(%q<activesupport>, [">= 0"])
106
+ s.add_runtime_dependency(%q<activerecord>, [">= 0"])
109
107
  s.add_development_dependency(%q<ruby-debug>, [">= 0"])
110
108
  s.add_development_dependency(%q<mysql2>, ["~> 0.2.7"])
111
109
  s.add_development_dependency(%q<geokit>, [">= 0"])
@@ -116,10 +114,11 @@ Gem::Specification.new do |s|
116
114
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
117
115
  s.add_development_dependency(%q<rcov>, [">= 0"])
118
116
  else
119
- s.add_dependency(%q<thinking-sphinx>, ["= 2.0.3"])
120
117
  s.add_dependency(%q<rsolr>, [">= 0"])
121
118
  s.add_dependency(%q<will_paginate>, [">= 0"])
122
119
  s.add_dependency(%q<json>, [">= 0"])
120
+ s.add_dependency(%q<activesupport>, [">= 0"])
121
+ s.add_dependency(%q<activerecord>, [">= 0"])
123
122
  s.add_dependency(%q<ruby-debug>, [">= 0"])
124
123
  s.add_dependency(%q<mysql2>, ["~> 0.2.7"])
125
124
  s.add_dependency(%q<geokit>, [">= 0"])
@@ -131,10 +130,11 @@ Gem::Specification.new do |s|
131
130
  s.add_dependency(%q<rcov>, [">= 0"])
132
131
  end
133
132
  else
134
- s.add_dependency(%q<thinking-sphinx>, ["= 2.0.3"])
135
133
  s.add_dependency(%q<rsolr>, [">= 0"])
136
134
  s.add_dependency(%q<will_paginate>, [">= 0"])
137
135
  s.add_dependency(%q<json>, [">= 0"])
136
+ s.add_dependency(%q<activesupport>, [">= 0"])
137
+ s.add_dependency(%q<activerecord>, [">= 0"])
138
138
  s.add_dependency(%q<ruby-debug>, [">= 0"])
139
139
  s.add_dependency(%q<mysql2>, ["~> 0.2.7"])
140
140
  s.add_dependency(%q<geokit>, [">= 0"])
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: supernova
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
8
+ - 4
9
9
  - 13
10
- version: 0.3.13
10
+ version: 0.4.13
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tobias Schwab
@@ -15,22 +15,20 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-29 00:00:00 Z
18
+ date: 2011-07-18 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  requirement: &id001 !ruby/object:Gem::Requirement
22
22
  none: false
23
23
  requirements:
24
- - - "="
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- hash: 9
26
+ hash: 3
27
27
  segments:
28
- - 2
29
28
  - 0
30
- - 3
31
- version: 2.0.3
29
+ version: "0"
32
30
  version_requirements: *id001
33
- name: thinking-sphinx
31
+ name: rsolr
34
32
  prerelease: false
35
33
  type: :runtime
36
34
  - !ruby/object:Gem::Dependency
@@ -44,7 +42,7 @@ dependencies:
44
42
  - 0
45
43
  version: "0"
46
44
  version_requirements: *id002
47
- name: rsolr
45
+ name: will_paginate
48
46
  prerelease: false
49
47
  type: :runtime
50
48
  - !ruby/object:Gem::Dependency
@@ -58,7 +56,7 @@ dependencies:
58
56
  - 0
59
57
  version: "0"
60
58
  version_requirements: *id003
61
- name: will_paginate
59
+ name: json
62
60
  prerelease: false
63
61
  type: :runtime
64
62
  - !ruby/object:Gem::Dependency
@@ -72,7 +70,7 @@ dependencies:
72
70
  - 0
73
71
  version: "0"
74
72
  version_requirements: *id004
75
- name: json
73
+ name: activesupport
76
74
  prerelease: false
77
75
  type: :runtime
78
76
  - !ruby/object:Gem::Dependency
@@ -86,11 +84,25 @@ dependencies:
86
84
  - 0
87
85
  version: "0"
88
86
  version_requirements: *id005
87
+ name: activerecord
88
+ prerelease: false
89
+ type: :runtime
90
+ - !ruby/object:Gem::Dependency
91
+ requirement: &id006 !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ hash: 3
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ version_requirements: *id006
89
101
  name: ruby-debug
90
102
  prerelease: false
91
103
  type: :development
92
104
  - !ruby/object:Gem::Dependency
93
- requirement: &id006 !ruby/object:Gem::Requirement
105
+ requirement: &id007 !ruby/object:Gem::Requirement
94
106
  none: false
95
107
  requirements:
96
108
  - - ~>
@@ -101,12 +113,12 @@ dependencies:
101
113
  - 2
102
114
  - 7
103
115
  version: 0.2.7
104
- version_requirements: *id006
116
+ version_requirements: *id007
105
117
  name: mysql2
106
118
  prerelease: false
107
119
  type: :development
108
120
  - !ruby/object:Gem::Dependency
109
- requirement: &id007 !ruby/object:Gem::Requirement
121
+ requirement: &id008 !ruby/object:Gem::Requirement
110
122
  none: false
111
123
  requirements:
112
124
  - - ">="
@@ -115,12 +127,12 @@ dependencies:
115
127
  segments:
116
128
  - 0
117
129
  version: "0"
118
- version_requirements: *id007
130
+ version_requirements: *id008
119
131
  name: geokit
120
132
  prerelease: false
121
133
  type: :development
122
134
  - !ruby/object:Gem::Dependency
123
- requirement: &id008 !ruby/object:Gem::Requirement
135
+ requirement: &id009 !ruby/object:Gem::Requirement
124
136
  none: false
125
137
  requirements:
126
138
  - - ">="
@@ -129,12 +141,12 @@ dependencies:
129
141
  segments:
130
142
  - 0
131
143
  version: "0"
132
- version_requirements: *id008
144
+ version_requirements: *id009
133
145
  name: autotest
134
146
  prerelease: false
135
147
  type: :development
136
148
  - !ruby/object:Gem::Dependency
137
- requirement: &id009 !ruby/object:Gem::Requirement
149
+ requirement: &id010 !ruby/object:Gem::Requirement
138
150
  none: false
139
151
  requirements:
140
152
  - - ">="
@@ -143,12 +155,12 @@ dependencies:
143
155
  segments:
144
156
  - 0
145
157
  version: "0"
146
- version_requirements: *id009
158
+ version_requirements: *id010
147
159
  name: autotest-growl
148
160
  prerelease: false
149
161
  type: :development
150
162
  - !ruby/object:Gem::Dependency
151
- requirement: &id010 !ruby/object:Gem::Requirement
163
+ requirement: &id011 !ruby/object:Gem::Requirement
152
164
  none: false
153
165
  requirements:
154
166
  - - ~>
@@ -159,12 +171,12 @@ dependencies:
159
171
  - 3
160
172
  - 0
161
173
  version: 2.3.0
162
- version_requirements: *id010
174
+ version_requirements: *id011
163
175
  name: rspec
164
176
  prerelease: false
165
177
  type: :development
166
178
  - !ruby/object:Gem::Dependency
167
- requirement: &id011 !ruby/object:Gem::Requirement
179
+ requirement: &id012 !ruby/object:Gem::Requirement
168
180
  none: false
169
181
  requirements:
170
182
  - - ~>
@@ -175,12 +187,12 @@ dependencies:
175
187
  - 0
176
188
  - 0
177
189
  version: 1.0.0
178
- version_requirements: *id011
190
+ version_requirements: *id012
179
191
  name: bundler
180
192
  prerelease: false
181
193
  type: :development
182
194
  - !ruby/object:Gem::Dependency
183
- requirement: &id012 !ruby/object:Gem::Requirement
195
+ requirement: &id013 !ruby/object:Gem::Requirement
184
196
  none: false
185
197
  requirements:
186
198
  - - ~>
@@ -191,12 +203,12 @@ dependencies:
191
203
  - 6
192
204
  - 0
193
205
  version: 1.6.0
194
- version_requirements: *id012
206
+ version_requirements: *id013
195
207
  name: jeweler
196
208
  prerelease: false
197
209
  type: :development
198
210
  - !ruby/object:Gem::Dependency
199
- requirement: &id013 !ruby/object:Gem::Requirement
211
+ requirement: &id014 !ruby/object:Gem::Requirement
200
212
  none: false
201
213
  requirements:
202
214
  - - ">="
@@ -205,7 +217,7 @@ dependencies:
205
217
  segments:
206
218
  - 0
207
219
  version: "0"
208
- version_requirements: *id013
220
+ version_requirements: *id014
209
221
  name: rcov
210
222
  prerelease: false
211
223
  type: :development
@@ -239,8 +251,6 @@ files:
239
251
  - lib/supernova/solr_criteria.rb
240
252
  - lib/supernova/solr_indexer.rb
241
253
  - lib/supernova/symbol_extensions.rb
242
- - lib/supernova/thinking_sphinx.rb
243
- - lib/supernova/thinking_sphinx_criteria.rb
244
254
  - solr/conf/admin-extra.html
245
255
  - solr/conf/elevate.xml
246
256
  - solr/conf/mapping-FoldToASCII.txt
@@ -278,9 +288,9 @@ files:
278
288
  - solr/conf/xslt/example_atom.xsl
279
289
  - solr/conf/xslt/example_rss.xsl
280
290
  - solr/conf/xslt/luke.xsl
291
+ - solr/start.rb
281
292
  - spec/database.sql
282
293
  - spec/integration/solr_spec.rb
283
- - spec/integration/thinking_sphinx_spec.rb
284
294
  - spec/spec_helper.rb
285
295
  - spec/supernova/condition_spec.rb
286
296
  - spec/supernova/criteria_spec.rb
@@ -289,7 +299,6 @@ files:
289
299
  - spec/supernova/solr_indexer_spec.rb
290
300
  - spec/supernova/solr_spec.rb
291
301
  - spec/supernova/symbol_extensions_spec.rb
292
- - spec/supernova/thinking_sphinx_criteria_spec.rb
293
302
  - spec/supernova_spec.rb
294
303
  - supernova.gemspec
295
304
  homepage: http://github.com/dynport/supernova
@@ -1,8 +0,0 @@
1
- require "supernova/thinking_sphinx_criteria"
2
-
3
- module Supernova::ThinkingSphinx
4
- def self.included(base)
5
- base.extend(Supernova::ClassMethods)
6
- base.criteria_class = Supernova::ThinkingSphinxCriteria
7
- end
8
- end
@@ -1,49 +0,0 @@
1
- require "thinking_sphinx"
2
- require "zlib"
3
-
4
- class Supernova::ThinkingSphinxCriteria < Supernova::Criteria
5
- def self.index_statement_for(field_name, column = nil)
6
- column ||= field_name
7
- [%(CONCAT("#{field_name}_", #{column})), { :as => :"indexed_#{field_name}" }]
8
- end
9
-
10
- def normalize_with_filter(attributes)
11
- attributes.inject({}) do |hash, (key, value)|
12
- value = Zlib.crc32(value.to_s) if value.is_a?(String) || value.is_a?(Class)
13
- hash.merge!(key => value)
14
- end
15
- end
16
-
17
- def to_params
18
- sphinx_options = { :match_mode => :boolean, :with => {}, :conditions => {}, :without => {} }
19
- sphinx_options[:order] = self.search_options[:order] if self.search_options[:order]
20
- sphinx_options[:limit] = self.search_options[:limit] if self.search_options[:limit]
21
- sphinx_options[:select] = self.search_options[:select] if self.search_options[:select]
22
- sphinx_options[:group_by] = self.search_options[:group_by] if self.search_options[:group_by]
23
- sphinx_options.merge!(self.search_options[:pagination]) if self.search_options[:pagination].is_a?(Hash)
24
- sphinx_options[:classes] = self.filters[:classes] if self.filters[:classes]
25
- sphinx_options[:classes] = [self.clazz] if self.clazz
26
- sphinx_options[:conditions].merge!(self.filters[:conditions]) if self.filters[:conditions]
27
- sphinx_options[:with].merge!(normalize_with_filter(self.filters[:with])) if self.filters[:with]
28
- sphinx_options[:without].merge!(normalize_with_filter(self.filters[:without])) if self.filters[:without]
29
- sphinx_options.merge!(self.search_options[:custom_options]) if self.search_options[:custom_options]
30
- if self.search_options[:geo_center] && self.search_options[:geo_distance]
31
- sphinx_options[:geo] = [self.search_options[:geo_center][:lat].to_radians, self.search_options[:geo_center][:lng].to_radians]
32
- sphinx_options[:with]["@geodist"] = self.search_options[:geo_distance].is_a?(Range) ? self.search_options[:geo_distance] : Range.new(0.0, self.search_options[:geo_distance])
33
- end
34
- [(self.search_options[:search] || Array.new).join(" "), sphinx_options]
35
- end
36
-
37
- def execute
38
- ThinkingSphinx.search(*self.to_params)
39
- end
40
-
41
- def ids
42
- params = *self.to_params
43
- ThinkingSphinx.search_for_ids(*params)
44
- end
45
-
46
- def total_entries
47
- ids.total_entries
48
- end
49
- end
@@ -1,77 +0,0 @@
1
- require 'spec_helper'
2
- require "active_record"
3
- require "thinking_sphinx"
4
- require "mysql2"
5
- require "fileutils"
6
-
7
- describe "ThinkingSphinx" do
8
- let(:ts) { ThinkingSphinx::Configuration.instance }
9
-
10
- before(:each) do
11
- ts.build
12
- ts.controller.index
13
- ts.controller.start
14
-
15
-
16
- ThinkingSphinx.deltas_enabled = true
17
- ThinkingSphinx.updates_enabled = true
18
- ThinkingSphinx.suppress_delta_output = true
19
-
20
- Offer.connection.execute "TRUNCATE offers"
21
- root = Geokit::LatLng.new(47, 11)
22
- endpoint = root.endpoint(90, 50, :units => :kms)
23
- @offer1 = Offer.create!(:id => 1, :user_id => 1, :enabled => false, :text => "Hans Meyer", :popularity => 10, :lat => root.lat, :lng => root.lng)
24
- @offer2 = Offer.create!(:id => 2, :user_id => 2, :enabled => true, :text => "Marek Mintal", :popularity => 1, :lat => endpoint.lat, :lng => endpoint.lng)
25
- ts.controller.index
26
- sleep 0.3
27
- end
28
-
29
- it "finds the correct objects" do
30
- Offer.for_user_ids(2).to_a.to_a.should == [@offer2]
31
- Offer.for_user_ids(2, 1).to_a.to_a.sort_by(&:id) == [@offer1, @offer2]
32
- end
33
-
34
- it "correctly filters out unwanted records" do
35
- Offer.search_scope.without(:user_id => 2).to_a.to_a.sort_by(&:id).should == [@offer1]
36
- Offer.search_scope.without(:user_id => 1).to_a.to_a.sort_by(&:id).should == [@offer2]
37
- Offer.search_scope.without(:user_id => 1).without(:user_id => 2).to_a.to_a.sort_by(&:id).should == []
38
- end
39
-
40
- it "returns the corect ids" do
41
- Offer.for_user_ids(2).ids.to_a.to_a.should == [2]
42
- end
43
-
44
- it "filters by enabled" do
45
- Offer.search_scope.with(:enabled => true).to_a.to_a.should == [@offer2]
46
- Offer.search_scope.with(:enabled => false).to_a.to_a.should == [@offer1]
47
- end
48
-
49
- it "combines searches" do
50
- Offer.search_scope.with(:enabled => false).with(:user_id => 2).to_a.should be_empty
51
- end
52
-
53
- it "searches for names" do
54
- Offer.search_scope.search("Marek").map(&:id).should == [2]
55
- Offer.search_scope.search("Hans").map(&:id).should == [1]
56
- end
57
-
58
- it "sorty by popularity" do
59
- Offer.search_scope.order("popularity desc").map(&:id).should == [1, 2]
60
- end
61
-
62
- describe "geo search" do
63
- it "finds the correct offers" do
64
- Offer.search_scope.near(47, 11).within(25.kms).to_a.to_a.should == [@offer1]
65
- end
66
-
67
- it "finds more offers when radius is bigger" do
68
- Offer.search_scope.near(47, 11).within(49.kms).to_a.should_not include(@offer2)
69
- Offer.search_scope.near(47, 11).within(51.kms).to_a.should include(@offer2)
70
- end
71
-
72
- it "finds offers around other offers" do
73
- Offer.search_scope.near(@offer1).within(49.kms).to_a.to_a.should == [@offer1]
74
- Offer.search_scope.near(@offer1).within(51.kms).order("@geodist desc").to_a.to_a.should == [@offer2, @offer1]
75
- end
76
- end
77
- end
@@ -1,142 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Supernova::ThinkingSphinxCriteria" do
4
- let(:scope) { Supernova::ThinkingSphinxCriteria.new }
5
-
6
- describe "#to_params" do
7
- it "returns an array" do
8
- scope.to_params.should be_an_instance_of(Array)
9
- end
10
-
11
- it "sets the correct order query" do
12
- scope.order("title desc").to_params.at(1)[:order].should == "title desc"
13
- end
14
-
15
- it "sets the correct group_by statement" do
16
- scope.group_by("title").to_params.at(1)[:group_by].should == "title"
17
- end
18
-
19
- it "sets the match_mode to boolean" do
20
- scope.to_params.at(1)[:match_mode].should == :boolean
21
- end
22
-
23
- it "does not set the classes field by default" do
24
- scope.to_params.at(1).should_not have_key(:classes)
25
- end
26
-
27
- it "sets the classes field when classes set" do
28
- scope.for_classes(Offer).to_params.at(1)[:classes].should == [Offer]
29
- end
30
-
31
- it "sets the classes to the clazz when intialized with the class" do
32
- Supernova::ThinkingSphinxCriteria.new(Offer).to_params.at(1)[:classes].should == [Offer]
33
- end
34
-
35
- it "sets the search query when present" do
36
- scope.search("some test").to_params.at(0).should == "some test"
37
- end
38
-
39
- it "sets a set limit" do
40
- scope.limit(88).to_params.at(1)[:limit].should == 88
41
- end
42
-
43
- it "sets the correct without parameters" do
44
- scope.without(:user_id => 9).to_params.at(1)[:without].should == { :user_id => [9] }
45
- scope.without(:user_id => 9).without(:user_id => 9).without(:user_id => 1).to_params.at(1)[:without].should == { :user_id => [9, 1] }
46
- end
47
-
48
- it "calls sphinx with select fields" do
49
- scope.select(%w(id title name)).to_params.at(1)[:select].should == %w(id title name)
50
- end
51
-
52
- it "sets the correct with filters" do
53
- scope.with(:a => 1).with(:b => 2).to_params.at(1)[:with].should == {
54
- :a => 1,
55
- :b => 2
56
- }
57
- end
58
-
59
- it "uses the crc32 value of strings when used in with" do
60
- scope.with(:a => Offer).to_params.at(1)[:with].should == {
61
- :a => 3893864506, # crc32 of Offer string
62
- }
63
- end
64
-
65
- it "sets the correct geo option filter" do
66
- scope.near(53.5748, 10.0347).within(5.kms).to_params.at(1)[:geo].map(&:to_s).should == ["0.935056656097458", "0.175138554449875"]
67
- end
68
-
69
- it "merges correct with options" do
70
- scope.near(53.5748, 10.0347).within(5.kms).with(:filter => true).to_params.at(1)[:with].should == {
71
- "@geodist" => Range.new(0.0, 5_000.0),
72
- :filter => true
73
- }
74
- end
75
-
76
- it "sets the correct geo distance filter when single value given" do
77
- # @geodist
78
- scope.near(53.5748, 10.0347).within(7.kms).to_params.at(1)[:with]["@geodist"].should == Range.new(0.0, 7_000.0)
79
- end
80
-
81
- it "sets the correct geo distance filter when range given value given" do
82
- # @geodist
83
- scope.near(53.5748, 10.0347).within(7.kms..10.kms).to_params.at(1)[:with]["@geodist"].should == Range.new(7_000.0, 10_000.0)
84
- end
85
-
86
- { :page => 8, :per_page => 1 }.each do |key, value|
87
- it "sets pagination pagination #{key} to #{value}" do
88
- scope.paginate(key => value).to_params.at(1)[key].should == value
89
- end
90
- end
91
-
92
- it "adds custom options to the sphinx search" do
93
- scope.options(:star => true).to_params.at(1)[:star].should == true
94
- end
95
- end
96
-
97
- describe "#normalize_with_filter" do
98
- it "does not change booleans and integers" do
99
- range = 1..10
100
- scope.normalize_with_filter(:a => 1, :enabled => true, :range => range).should == { :a => 1, :enabled => true, :range => range }
101
- end
102
-
103
- it "uses crc32 of strings" do
104
- scope.normalize_with_filter(:a => "Test").should == { :a => 2018365746 } # crc32 of "Test"
105
- end
106
- end
107
-
108
- describe "with to_params mockes" do
109
- let(:query) { double("query") }
110
- let(:options) { double("options") }
111
- let(:sphinx_response) { double("sphinx_respons") }
112
-
113
- before(:each) do
114
- scope.stub!(:to_params).and_return([query, options])
115
- end
116
-
117
- describe "#to_a" do
118
- it "returns the sphinx search" do
119
- ThinkingSphinx.stub!(:search).and_return sphinx_response
120
- scope.to_a.should == sphinx_response
121
- end
122
-
123
- it "calls ThinkingSphinx with what to_params returns" do
124
- ThinkingSphinx.should_receive(:search).with(query, options).and_return sphinx_response
125
- scope.to_a.should == sphinx_response
126
- end
127
- end
128
-
129
- it "forwards ids to search_for_ids" do
130
- ids_response = double("id response")
131
- ThinkingSphinx.should_receive(:search_for_ids).with(query, options).and_return ids_response
132
- scope.ids
133
- end
134
-
135
- it "forwards total_entries to search_for_ids" do
136
- ids_response = double("id response")
137
- ThinkingSphinx.should_receive(:search_for_ids).with(query, options).and_return ids_response
138
- ids_response.should_receive(:total_entries).and_return 88
139
- scope.total_entries.should == 88
140
- end
141
- end
142
- end