Skip to content

Commit a6ddf07

Browse files
committed
Rails 3.1 support
1 parent 2753038 commit a6ddf07

18 files changed

+193
-172
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ db/*.sqlite3
33
log/*.log
44
tmp/
55
db
6+
log/development.sphinx.pid

Gemfile

+7-8
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,20 @@ source 'http://rubygems.org'
22

33
ruby '1.9.3'
44

5-
gem 'rails', '3.0.20'
5+
gem 'rails', '~> 3.1.3'
66

7-
#============= WARNING FROM mysql2 =============
8-
#This version of mysql2 (0.3.13) doesn't ship with the ActiveRecord adapter.
9-
#In Rails version 3.1.0 and up, the mysql2 ActiveRecord adapter is included with rails.
10-
#If you want to use the mysql2 gem with Rails <= 3.0.x, please use the latest mysql2 in the 0.2.x series.
11-
gem 'mysql2', '~> 0.2.0'
7+
gem 'mysql2', '~> 0.3.0'
128

139
gem 'sanitize'
1410

1511
gem 'csspool', '4.0.0'
1612

1713
gem 'public_suffix'
18-
gem 'thinking-sphinx', '~> 2.0.14'
19-
gem 'ts-delayed-delta', '~> 1.1.2'
14+
gem 'thinking-sphinx', '~> 3.0.0'
15+
gem 'ts-delayed-delta', '~> 2.0.0'
16+
gem 'delayed_job', '~> 4.0.0'
17+
gem 'delayed_job_active_record', '~> 4.0.0'
18+
2019
gem 'will_paginate', '~> 3.0'
2120

2221
gem 'ruby-openid'

Gemfile.lock

+79-59
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,109 @@
11
GEM
22
remote: http://rubygems.org/
33
specs:
4-
abstract (1.0.0)
5-
actionmailer (3.0.20)
6-
actionpack (= 3.0.20)
7-
mail (~> 2.2.19)
8-
actionpack (3.0.20)
9-
activemodel (= 3.0.20)
10-
activesupport (= 3.0.20)
11-
builder (~> 2.1.2)
12-
erubis (~> 2.6.6)
13-
i18n (~> 0.5.0)
14-
rack (~> 1.2.5)
15-
rack-mount (~> 0.6.14)
16-
rack-test (~> 0.5.7)
17-
tzinfo (~> 0.3.23)
18-
activemodel (3.0.20)
19-
activesupport (= 3.0.20)
20-
builder (~> 2.1.2)
21-
i18n (~> 0.5.0)
22-
activerecord (3.0.20)
23-
activemodel (= 3.0.20)
24-
activesupport (= 3.0.20)
25-
arel (~> 2.0.10)
26-
tzinfo (~> 0.3.23)
27-
activeresource (3.0.20)
28-
activemodel (= 3.0.20)
29-
activesupport (= 3.0.20)
30-
activesupport (3.0.20)
31-
arel (2.0.10)
32-
builder (2.1.2)
4+
actionmailer (3.1.12)
5+
actionpack (= 3.1.12)
6+
mail (~> 2.4.4)
7+
actionpack (3.1.12)
8+
activemodel (= 3.1.12)
9+
activesupport (= 3.1.12)
10+
builder (~> 3.0.0)
11+
erubis (~> 2.7.0)
12+
i18n (~> 0.6)
13+
rack (~> 1.3.6)
14+
rack-cache (~> 1.2)
15+
rack-mount (~> 0.8.2)
16+
rack-test (~> 0.6.1)
17+
sprockets (~> 2.0.4)
18+
activemodel (3.1.12)
19+
activesupport (= 3.1.12)
20+
builder (~> 3.0.0)
21+
i18n (~> 0.6)
22+
activerecord (3.1.12)
23+
activemodel (= 3.1.12)
24+
activesupport (= 3.1.12)
25+
arel (~> 2.2.3)
26+
tzinfo (~> 0.3.29)
27+
activeresource (3.1.12)
28+
activemodel (= 3.1.12)
29+
activesupport (= 3.1.12)
30+
activesupport (3.1.12)
31+
multi_json (~> 1.0)
32+
arel (2.2.3)
33+
builder (3.0.4)
3334
csspool (4.0.0)
3435
delayed_job (4.0.0)
3536
activesupport (>= 3.0, < 4.1)
36-
erubis (2.6.6)
37-
abstract (>= 1.0.0)
38-
i18n (0.5.0)
37+
delayed_job_active_record (4.0.0)
38+
activerecord (>= 3.0, < 4.1)
39+
delayed_job (>= 3.0, < 4.1)
40+
erubis (2.7.0)
41+
hike (1.2.3)
42+
i18n (0.6.5)
43+
innertube (1.1.0)
3944
json (1.8.1)
40-
mail (2.2.20)
41-
activesupport (>= 2.3.6)
45+
mail (2.4.4)
4246
i18n (>= 0.4.0)
4347
mime-types (~> 1.16)
4448
treetop (~> 1.4.8)
49+
middleware (0.1.0)
4550
mime-types (1.25)
4651
mini_portile (0.5.1)
47-
mysql2 (0.2.20)
52+
multi_json (1.8.2)
53+
mysql2 (0.3.13)
4854
nokogiri (1.6.0)
4955
mini_portile (~> 0.5.0)
5056
polyglot (0.3.3)
5157
public_suffix (1.3.1)
52-
rack (1.2.8)
53-
rack-mount (0.6.14)
58+
rack (1.3.10)
59+
rack-cache (1.2)
60+
rack (>= 0.4)
61+
rack-mount (0.8.3)
5462
rack (>= 1.0.0)
55-
rack-test (0.5.7)
63+
rack-ssl (1.3.3)
64+
rack
65+
rack-test (0.6.2)
5666
rack (>= 1.0)
57-
rails (3.0.20)
58-
actionmailer (= 3.0.20)
59-
actionpack (= 3.0.20)
60-
activerecord (= 3.0.20)
61-
activeresource (= 3.0.20)
62-
activesupport (= 3.0.20)
67+
rails (3.1.12)
68+
actionmailer (= 3.1.12)
69+
actionpack (= 3.1.12)
70+
activerecord (= 3.1.12)
71+
activeresource (= 3.1.12)
72+
activesupport (= 3.1.12)
6373
bundler (~> 1.0)
64-
railties (= 3.0.20)
65-
railties (3.0.20)
66-
actionpack (= 3.0.20)
67-
activesupport (= 3.0.20)
74+
railties (= 3.1.12)
75+
railties (3.1.12)
76+
actionpack (= 3.1.12)
77+
activesupport (= 3.1.12)
78+
rack-ssl (~> 1.3.2)
6879
rake (>= 0.8.7)
6980
rdoc (~> 3.4)
70-
thor (~> 0.14.4)
81+
thor (~> 0.14.6)
7182
rake (10.1.0)
7283
rdoc (3.12.2)
7384
json (~> 1.4)
7485
riddle (1.5.9)
7586
ruby-openid (2.3.0)
7687
sanitize (2.0.6)
7788
nokogiri (>= 1.4.4)
78-
thinking-sphinx (2.0.14)
79-
activerecord (>= 3.0.3)
89+
sprockets (2.0.4)
90+
hike (~> 1.2)
91+
rack (~> 1.0)
92+
tilt (~> 1.1, != 1.3.0)
93+
thinking-sphinx (3.0.6)
94+
activerecord (>= 3.1.0)
8095
builder (>= 2.1.2)
81-
riddle (>= 1.5.3)
96+
innertube (>= 1.0.2)
97+
middleware (>= 0.1.0)
98+
riddle (>= 1.5.9)
8299
thor (0.14.6)
100+
tilt (1.4.1)
83101
treetop (1.4.15)
84102
polyglot
85103
polyglot (>= 0.3.1)
86-
ts-delayed-delta (1.1.3)
87-
delayed_job (>= 2.0.4)
88-
thinking-sphinx (>= 1.3.6)
104+
ts-delayed-delta (2.0.0)
105+
delayed_job
106+
thinking-sphinx
89107
tzinfo (0.3.38)
90108
will_paginate (3.0.5)
91109

@@ -94,11 +112,13 @@ PLATFORMS
94112

95113
DEPENDENCIES
96114
csspool (= 4.0.0)
97-
mysql2 (~> 0.2.0)
115+
delayed_job (~> 4.0.0)
116+
delayed_job_active_record (~> 4.0.0)
117+
mysql2 (~> 0.3.0)
98118
public_suffix
99-
rails (= 3.0.20)
119+
rails (~> 3.1.3)
100120
ruby-openid
101121
sanitize
102-
thinking-sphinx (~> 2.0.14)
103-
ts-delayed-delta (~> 1.1.2)
122+
thinking-sphinx (~> 3.0.0)
123+
ts-delayed-delta (~> 2.0.0)
104124
will_paginate (~> 3.0)

app/controllers/application_controller.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ def consumer
7070
return @consumer
7171
end
7272

73-
$sorts_map = {'name' => 'short_description', 'total_installs' => 'total_install_count', 'installs_this_week' => 'weekly_install_count', 'created_date' => 'created', 'updated_date' => 'updated', 'popularity' => 'popularity_score', 'relevance' => '@relevance, popularity_score'}
73+
$sorts_map = {'name' => 'short_description', 'total_installs' => 'total_install_count', 'installs_this_week' => 'weekly_install_count', 'created_date' => 'created', 'updated_date' => 'updated', 'popularity' => 'popularity_score', 'relevance' => 'myweight, popularity_score'}
7474

75-
$new_sorts_map = {'name' => 'name DIR', 'total_installs' => 'total_install_count DIR', 'installs_this_week' => 'weekly_install_count DIR', 'created_date' => 'created DIR', 'updated_date' => 'updated DIR', 'popularity' => 'popularity DIR', 'relevance' => '@relevance DIR, popularity DIR'}
75+
$new_sorts_map = {'name' => 'name DIR', 'total_installs' => 'total_install_count DIR', 'installs_this_week' => 'weekly_install_count DIR', 'created_date' => 'created DIR', 'updated_date' => 'updated DIR', 'popularity' => 'popularity DIR', 'relevance' => 'myweight DIR, popularity DIR'}
7676

7777

7878
private

app/controllers/styles_controller.rb

+25-39
Original file line numberDiff line numberDiff line change
@@ -443,39 +443,27 @@ def browse
443443
new_search_conditions[:category] = category
444444
elsif category == 'appnone'
445445
#condition += " AND category = 'app' AND subcategory IS NULL"
446-
#@use_new_search = false
447446
new_search_conditions[:category] = 'app'
448447
new_search_conditions[:subcategory] = 'none'
449448
elsif category == 'sitenone'
450449
#condition += " AND category = 'site' AND subcategory IS NULL"
451-
#@use_new_search = false
452450
new_search_conditions[:category] = 'site'
453451
new_search_conditions[:subcategory] = 'none'
454452
elsif category == 'globalnone'
455453
#condition += " AND category = 'global' AND subcategory IS NULL"
456-
#@use_new_search = false
457454
new_search_conditions[:category] = 'global'
458455
new_search_conditions[:subcategory] = 'none'
459456
else
460457
@bc_category = 'site'
461458
category = Style.get_subcategory_for_domain(category)
462459
@bc_subcategory = category
463-
#condition += " AND subcategory = '#{Style.connection.quote_string(category)}'"
464460
new_search_conditions[:subcategory] = Riddle.escape(category)
465461
end
466-
#options[:conditions] = condition
467462

468-
#if @use_new_search
469-
if !$new_sorts_map.keys.include?(params[:sort])
470-
params[:sort] = nil
471-
end
472-
sort = $new_sorts_map[params[:sort] || 'relevance']
473-
#else
474-
# if !$sorts_map.keys.include?(params[:sort])
475-
# params[:sort] = nil
476-
# end
477-
# sort = $sorts_map[params[:sort] || 'relevance']
478-
#end
463+
if !$new_sorts_map.keys.include?(params[:sort])
464+
params[:sort] = nil
465+
end
466+
sort = $new_sorts_map[params[:sort] || 'relevance']
479467

480468
sort_direction = params[:sort_direction].nil? ? 'desc' : params[:sort_direction].downcase
481469
if sort_direction != 'desc'
@@ -490,35 +478,33 @@ def browse
490478
params[:per_page] = nil
491479
end
492480

493-
#if @use_new_search
494-
# relevant is irrelevant when there are no terms
495-
if keywords.nil? and sort == '@relevance DIR, popularity DIR'
496-
new_sort = $new_sorts_map['popularity']
497-
else
498-
new_sort = sort
499-
end
500-
begin
501-
@styles = Style.search keywords, :match_mode => :extended, :page => params[:page], :order => new_sort.gsub('DIR', sort_direction.upcase), :per_page => options[:per_page], :conditions => new_search_conditions, :populate => true
502-
@no_ads = @styles.empty?
503-
rescue ThinkingSphinx::SphinxError
504-
# back to the main listing
505-
redirect_to :controller => 'styles', :action => 'browse', :category => nil, :search_terms => nil
506-
return
507-
rescue Riddle::OutOfBoundsError
508-
# same url, minus the page param
509-
redirect_to :controller => 'styles', :action => 'browse', :search_terms => params[:search_terms], :category => params[:category], :format => params[:format], :sort => params[:sort], :sort_direction => params[:sort_direction]
510-
return
511-
end
512-
#else
513-
# @styles = Style.paginate(:all, options)
514-
#end
481+
# weight is irrelevant when there are no terms
482+
if keywords.nil? and sort == 'myweight DIR, popularity DIR'
483+
new_sort = $new_sorts_map['popularity']
484+
else
485+
new_sort = sort
486+
end
487+
begin
488+
@styles = Style.search keywords, :match_mode => :extended, :page => params[:page], :order => new_sort.gsub('DIR', sort_direction.upcase), :per_page => options[:per_page], :conditions => new_search_conditions, :populate => true, :select => 'weight() myweight'
489+
@no_ads = @styles.empty?
490+
#rescue ThinkingSphinx::SphinxError => e
491+
# back to the main listing, unless we're already there
492+
# raise e if params[:category].nil? and params[:search_terms].nil? and params[:page].nil? and params[:order].nil? and params[:sort].nil? and params[:sort_direction].nil?
493+
# redirect_to :controller => 'styles', :action => 'browse', :category => nil, :search_terms => nil
494+
# return
495+
rescue Riddle::OutOfBoundsError
496+
# same url, minus the page param
497+
redirect_to :controller => 'styles', :action => 'browse', :search_terms => params[:search_terms], :category => params[:category], :format => params[:format], :sort => params[:sort], :sort_direction => params[:sort_direction]
498+
return
499+
end
500+
515501
if search_terms.nil?
516502
if !category.nil?
517503
c = category
518504
c = 'app' if c == 'appnone'
519505
@page_title = "#{c.capitalize} themes and skins"
520506
@meta_description = "A listing of #{c.capitalize} user styles."
521-
elsif sort == '@relevance DIR, popularity DIR' and sort_direction == 'desc'
507+
elsif sort == 'myweight DIR, popularity DIR' and sort_direction == 'desc'
522508
@page_title = 'Top themes and skins'
523509
@meta_description = "A listing of the top user styles that you can customize your browser with."
524510
elsif sort == 'updated DIR' and sort_direction == 'desc'

app/indices/style_index.rb

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
ThinkingSphinx::Index.define :style, :with => :active_record, :delta => ThinkingSphinx::Deltas::DelayedDelta do
2+
3+
# fields
4+
indexes short_description, :as => :name, :sortable => true
5+
indexes long_description, :as => :description
6+
indexes additional_info
7+
indexes category
8+
indexes 'IF(ISNULL(subcategory), "none", subcategory)', :as => :subcategory
9+
indexes user.name, :as => :author
10+
11+
# attributes
12+
has :popularity_score, :as => :popularity
13+
has :created, :updated, :total_install_count, :weekly_install_count, :rating
14+
15+
where 'obsolete = 0'
16+
17+
set_property :field_weights => {
18+
:subcategory => 10,
19+
:name => 5,
20+
:author => 5,
21+
:description => 2,
22+
:additional_info => 1
23+
}
24+
25+
end

0 commit comments

Comments
 (0)