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 "thinking-sphinx", "2.0.12"
|
||||
gem "thinking-sphinx", "~> 3.0.6"
|
||||
|
||||
gem "mail"
|
||||
|
||||
|
|
12
Gemfile.lock
12
Gemfile.lock
|
@ -38,6 +38,7 @@ GEM
|
|||
hike (1.2.3)
|
||||
htmlentities (4.3.1)
|
||||
i18n (0.6.9)
|
||||
innertube (1.1.0)
|
||||
jquery-rails (3.0.4)
|
||||
railties (>= 3.0, < 5.0)
|
||||
thor (>= 0.14, < 2.0)
|
||||
|
@ -47,6 +48,7 @@ GEM
|
|||
mail (2.5.4)
|
||||
mime-types (~> 1.16)
|
||||
treetop (~> 1.4.8)
|
||||
middleware (0.1.0)
|
||||
mime-types (1.25.1)
|
||||
mini_portile (0.5.2)
|
||||
minitest (4.7.5)
|
||||
|
@ -99,10 +101,12 @@ GEM
|
|||
activesupport (>= 3.0)
|
||||
sprockets (~> 2.8)
|
||||
sqlite3 (1.3.8)
|
||||
thinking-sphinx (2.0.12)
|
||||
activerecord (>= 3.0.3)
|
||||
thinking-sphinx (3.0.6)
|
||||
activerecord (>= 3.1.0)
|
||||
builder (>= 2.1.2)
|
||||
riddle (>= 1.5.2)
|
||||
innertube (>= 1.0.2)
|
||||
middleware (>= 0.1.0)
|
||||
riddle (>= 1.5.9)
|
||||
thor (0.18.1)
|
||||
thread_safe (0.1.3)
|
||||
atomic
|
||||
|
@ -138,6 +142,6 @@ DEPENDENCIES
|
|||
rdiscount
|
||||
rspec-rails (~> 2.6)
|
||||
sqlite3
|
||||
thinking-sphinx (= 2.0.12)
|
||||
thinking-sphinx (~> 3.0.6)
|
||||
uglifier (>= 1.3.0)
|
||||
unicorn
|
||||
|
|
|
@ -61,7 +61,7 @@ generated key from the output of `rake secret`:
|
|||
* (Optional, only needed for the search engine) Install Sphinx. Build Sphinx
|
||||
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,
|
||||
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
|
||||
|
||||
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
|
||||
self.comment.to_s.strip == "" &&
|
||||
errors.add(:comment, "cannot be blank.")
|
||||
|
|
|
@ -36,30 +36,28 @@ class Search
|
|||
|
||||
def search_for_user!(user)
|
||||
opts = {
|
||||
:match_mode => :extended,
|
||||
:rank_mode => :bm25,
|
||||
:page => @page,
|
||||
:ranker => :bm25,
|
||||
:page => @page,
|
||||
:per_page => @per_page,
|
||||
:include => [ :story, :user ],
|
||||
}
|
||||
|
||||
if order == "newest"
|
||||
opts[:order] = :created_at
|
||||
opts[:sort_mode] = :desc
|
||||
opts[:order] = "created_at DESC"
|
||||
elsif order == "points"
|
||||
opts[:order] = :score
|
||||
opts[:sort_mode] = :desc
|
||||
opts[:order] = "score DESC"
|
||||
end
|
||||
|
||||
opts[:classes] = []
|
||||
if what == "all"
|
||||
opts[:classes] = [ Story, Comment ]
|
||||
elsif what == "comments"
|
||||
opts[:classes] = [ Comment ]
|
||||
elsif what == "stories"
|
||||
opts[:classes] = [ Story ]
|
||||
end
|
||||
|
||||
opts[:include] = [ :story, :user ]
|
||||
opts[:classes] = case what
|
||||
when "all"
|
||||
[ Story, Comment ]
|
||||
when what == "comments"
|
||||
[ Comment ]
|
||||
when what == "stories"
|
||||
[ Story ]
|
||||
else
|
||||
[]
|
||||
end
|
||||
|
||||
# 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
|
||||
|
|
|
@ -23,27 +23,6 @@ class Story < ActiveRecord::Base
|
|||
before_save :log_moderation
|
||||
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
|
||||
if self.url.present?
|
||||
# URI.parse is not very lenient, so we can't use it
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
|
||||
cd /d/rails/lobsters
|
||||
# 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