upgrade thinking-sphinx gem
This commit is contained in:
parent
a4657cdb83
commit
709b0bff98
2
Gemfile
2
Gemfile
|
@ -31,7 +31,7 @@ gem "rdiscount"
|
||||||
|
|
||||||
gem "oauth"
|
gem "oauth"
|
||||||
|
|
||||||
gem "thinking-sphinx", "2.0.12"
|
gem "thinking-sphinx", "~> 3.0.6"
|
||||||
|
|
||||||
gem "mail"
|
gem "mail"
|
||||||
|
|
||||||
|
|
12
Gemfile.lock
12
Gemfile.lock
|
@ -38,6 +38,7 @@ GEM
|
||||||
hike (1.2.3)
|
hike (1.2.3)
|
||||||
htmlentities (4.3.1)
|
htmlentities (4.3.1)
|
||||||
i18n (0.6.9)
|
i18n (0.6.9)
|
||||||
|
innertube (1.1.0)
|
||||||
jquery-rails (3.0.4)
|
jquery-rails (3.0.4)
|
||||||
railties (>= 3.0, < 5.0)
|
railties (>= 3.0, < 5.0)
|
||||||
thor (>= 0.14, < 2.0)
|
thor (>= 0.14, < 2.0)
|
||||||
|
@ -47,6 +48,7 @@ GEM
|
||||||
mail (2.5.4)
|
mail (2.5.4)
|
||||||
mime-types (~> 1.16)
|
mime-types (~> 1.16)
|
||||||
treetop (~> 1.4.8)
|
treetop (~> 1.4.8)
|
||||||
|
middleware (0.1.0)
|
||||||
mime-types (1.25.1)
|
mime-types (1.25.1)
|
||||||
mini_portile (0.5.2)
|
mini_portile (0.5.2)
|
||||||
minitest (4.7.5)
|
minitest (4.7.5)
|
||||||
|
@ -99,10 +101,12 @@ GEM
|
||||||
activesupport (>= 3.0)
|
activesupport (>= 3.0)
|
||||||
sprockets (~> 2.8)
|
sprockets (~> 2.8)
|
||||||
sqlite3 (1.3.8)
|
sqlite3 (1.3.8)
|
||||||
thinking-sphinx (2.0.12)
|
thinking-sphinx (3.0.6)
|
||||||
activerecord (>= 3.0.3)
|
activerecord (>= 3.1.0)
|
||||||
builder (>= 2.1.2)
|
builder (>= 2.1.2)
|
||||||
riddle (>= 1.5.2)
|
innertube (>= 1.0.2)
|
||||||
|
middleware (>= 0.1.0)
|
||||||
|
riddle (>= 1.5.9)
|
||||||
thor (0.18.1)
|
thor (0.18.1)
|
||||||
thread_safe (0.1.3)
|
thread_safe (0.1.3)
|
||||||
atomic
|
atomic
|
||||||
|
@ -138,6 +142,6 @@ DEPENDENCIES
|
||||||
rdiscount
|
rdiscount
|
||||||
rspec-rails (~> 2.6)
|
rspec-rails (~> 2.6)
|
||||||
sqlite3
|
sqlite3
|
||||||
thinking-sphinx (= 2.0.12)
|
thinking-sphinx (~> 3.0.6)
|
||||||
uglifier (>= 1.3.0)
|
uglifier (>= 1.3.0)
|
||||||
unicorn
|
unicorn
|
||||||
|
|
|
@ -61,7 +61,7 @@ generated key from the output of `rake secret`:
|
||||||
* (Optional, only needed for the search engine) Install Sphinx. Build Sphinx
|
* (Optional, only needed for the search engine) Install Sphinx. Build Sphinx
|
||||||
config and start server:
|
config and start server:
|
||||||
|
|
||||||
lobsters$ rake thinking_sphinx:rebuild
|
lobsters$ rake ts:rebuild
|
||||||
|
|
||||||
* Define your site's name and default domain, which are used in various places,
|
* Define your site's name and default domain, which are used in various places,
|
||||||
in a `config/initializers/production.rb` or similar file:
|
in a `config/initializers/production.rb` or similar file:
|
||||||
|
|
13
app/indices/comment_index.rb
Normal file
13
app/indices/comment_index.rb
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
|
||||||
|
ThinkingSphinx::Index.define :comment, :with => :active_record do
|
||||||
|
indexes comment
|
||||||
|
indexes user.username, :as => :author
|
||||||
|
|
||||||
|
has "(cast(upvotes as signed) - cast(downvotes as signed))",
|
||||||
|
:as => :score, :type => :bigint, :sortable => true
|
||||||
|
|
||||||
|
has is_deleted
|
||||||
|
has created_at
|
||||||
|
|
||||||
|
where sanitize_sql(:is_deleted => false, :is_moderated => false)
|
||||||
|
end
|
21
app/indices/story_index.rb
Normal file
21
app/indices/story_index.rb
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
|
||||||
|
ThinkingSphinx::Index.define :story, :with => :active_record do
|
||||||
|
indexes url
|
||||||
|
indexes title
|
||||||
|
indexes description
|
||||||
|
indexes user.username, :as => :author
|
||||||
|
indexes tags(:tag), :as => :tags
|
||||||
|
|
||||||
|
has created_at, :sortable => true
|
||||||
|
has hotness, is_expired
|
||||||
|
has "(cast(upvotes as signed) - cast(downvotes as signed))",
|
||||||
|
:as => :score, :type => :bigint, :sortable => true
|
||||||
|
|
||||||
|
set_property :field_weights => {
|
||||||
|
:upvotes => 15,
|
||||||
|
:title => 10,
|
||||||
|
:tags => 5,
|
||||||
|
}
|
||||||
|
|
||||||
|
where sanitize_sql(:is_expired => false)
|
||||||
|
end
|
|
@ -24,19 +24,6 @@ class Comment < ActiveRecord::Base
|
||||||
|
|
||||||
MAX_EDIT_MINS = 45
|
MAX_EDIT_MINS = 45
|
||||||
|
|
||||||
define_index do
|
|
||||||
indexes comment
|
|
||||||
indexes user.username, :as => :author
|
|
||||||
|
|
||||||
has "(cast(upvotes as signed) - cast(downvotes as signed))",
|
|
||||||
:as => :score, :type => :bigint, :sortable => true
|
|
||||||
|
|
||||||
has is_deleted
|
|
||||||
has created_at
|
|
||||||
|
|
||||||
where "is_deleted = 0 AND is_moderated = 0"
|
|
||||||
end
|
|
||||||
|
|
||||||
validate do
|
validate do
|
||||||
self.comment.to_s.strip == "" &&
|
self.comment.to_s.strip == "" &&
|
||||||
errors.add(:comment, "cannot be blank.")
|
errors.add(:comment, "cannot be blank.")
|
||||||
|
|
|
@ -36,30 +36,28 @@ class Search
|
||||||
|
|
||||||
def search_for_user!(user)
|
def search_for_user!(user)
|
||||||
opts = {
|
opts = {
|
||||||
:match_mode => :extended,
|
:ranker => :bm25,
|
||||||
:rank_mode => :bm25,
|
:page => @page,
|
||||||
:page => @page,
|
|
||||||
:per_page => @per_page,
|
:per_page => @per_page,
|
||||||
|
:include => [ :story, :user ],
|
||||||
}
|
}
|
||||||
|
|
||||||
if order == "newest"
|
if order == "newest"
|
||||||
opts[:order] = :created_at
|
opts[:order] = "created_at DESC"
|
||||||
opts[:sort_mode] = :desc
|
|
||||||
elsif order == "points"
|
elsif order == "points"
|
||||||
opts[:order] = :score
|
opts[:order] = "score DESC"
|
||||||
opts[:sort_mode] = :desc
|
|
||||||
end
|
end
|
||||||
|
|
||||||
opts[:classes] = []
|
opts[:classes] = case what
|
||||||
if what == "all"
|
when "all"
|
||||||
opts[:classes] = [ Story, Comment ]
|
[ Story, Comment ]
|
||||||
elsif what == "comments"
|
when what == "comments"
|
||||||
opts[:classes] = [ Comment ]
|
[ Comment ]
|
||||||
elsif what == "stories"
|
when what == "stories"
|
||||||
opts[:classes] = [ Story ]
|
[ Story ]
|
||||||
end
|
else
|
||||||
|
[]
|
||||||
opts[:include] = [ :story, :user ]
|
end
|
||||||
|
|
||||||
# sphinx seems to interpret slashes as a regex(?) so escape them since
|
# sphinx seems to interpret slashes as a regex(?) so escape them since
|
||||||
# nobody is probably using them, but don't just use Riddle.escape because
|
# nobody is probably using them, but don't just use Riddle.escape because
|
||||||
|
|
|
@ -23,27 +23,6 @@ class Story < ActiveRecord::Base
|
||||||
before_save :log_moderation
|
before_save :log_moderation
|
||||||
after_create :mark_submitter
|
after_create :mark_submitter
|
||||||
|
|
||||||
define_index do
|
|
||||||
indexes url
|
|
||||||
indexes title
|
|
||||||
indexes description
|
|
||||||
indexes user.username, :as => :author
|
|
||||||
indexes tags(:tag), :as => :tags
|
|
||||||
|
|
||||||
has created_at, :sortable => true
|
|
||||||
has hotness, is_expired
|
|
||||||
has "(cast(upvotes as signed) - cast(downvotes as signed))",
|
|
||||||
:as => :score, :type => :bigint, :sortable => true
|
|
||||||
|
|
||||||
set_property :field_weights => {
|
|
||||||
:upvotes => 15,
|
|
||||||
:title => 10,
|
|
||||||
:tags => 5,
|
|
||||||
}
|
|
||||||
|
|
||||||
where "is_expired = 0"
|
|
||||||
end
|
|
||||||
|
|
||||||
validate do
|
validate do
|
||||||
if self.url.present?
|
if self.url.present?
|
||||||
# URI.parse is not very lenient, so we can't use it
|
# URI.parse is not very lenient, so we can't use it
|
||||||
|
|
|
@ -2,4 +2,4 @@
|
||||||
|
|
||||||
cd /d/rails/lobsters
|
cd /d/rails/lobsters
|
||||||
# rebuild does a start
|
# rebuild does a start
|
||||||
sudo -u lobsters -H env RAILS_ENV=production NO_TRIPWIRE=1 bundle19 exec rake19 thinking_sphinx:rebuild
|
sudo -u lobsters -H env RAILS_ENV=production NO_TRIPWIRE=1 bundle19 exec rake19 ts:rebuild
|
||||||
|
|
Loading…
Reference in a new issue