Skip to content

Commit

Permalink
Fixed Sphinx brick (fixed bad capistrano and rake tasks).
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspard committed May 16, 2011
1 parent 949d004 commit 5f58186
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
8 changes: 6 additions & 2 deletions bricks/sphinx/lib/bricks/sphinx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module NodeClassMethods
def search_text(query, opts = {})
if offset = opts[:offset]
limit = opts[:limit] || 20
ids = search_for_ids(query, :with => with, :limit => (offset + limit) * [limit,20].max)
ids = search_for_ids(query, :with => opts[:with], :limit => (offset + limit) * [limit,20].max)
return [] if ids.empty?
# 1. filter with secure
secure_ids = Zena::Db.fetch_ids("SELECT id FROM nodes WHERE #{secure_scope('nodes')} AND id IN (#{ids.join(',')})")
Expand Down Expand Up @@ -56,7 +56,11 @@ def self.included(klass)

where "versions.status >= #{Zena::Status[:pub]}"

set_property :field_weights => { :idx_text_high => 5, :idx_text_medium => 3, :idx_text_low => 2 }
set_property :field_weights => {
:idx_text_high => 5,
:idx_text_medium => 3,
:idx_text_lowv => 2
}
set_property :group_concat_max_len => 30000 # FIXME: articles can easily have a length of 17000 chars...
set_property :delta => (has_dd ? :delayed : true)
end
Expand Down
13 changes: 13 additions & 0 deletions bricks/sphinx/zena/sphinx.yml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
test:
sql_range_step: 10000000

production:
enable_star: 1
min_infix_len: 2
pid_file: <%= shared_path %>/log/searchd.production.pid
searchd_files: <%= shared_path %>/db/sphinx
run_indexer_at: "10,40"

development:
enable_star: 1
min_infix_len: 2
30 changes: 28 additions & 2 deletions bricks/sphinx/zena/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@
# environment since it needs to get configuration settings from the classes in zena.
require 'tempfile'
require 'yaml'
require 'thinking_sphinx'


class RenderClass
def initialize(path)
@text = File.read(path)
end

def render(hash)
@values = hash
ERB.new(@text).result(binding)
end

def method_missing(sym)
return @values[sym] if @values.has_key?(sym)
super
end
end

def render(file, hash)
RenderClass.new(file).render(hash)
end

namespace :sphinx do
setup_done = File.exist?("#{RAILS_ROOT}/config/#{RAILS_ENV}.sphinx.conf")
Expand All @@ -14,7 +36,10 @@
if File.exist?("#{RAILS_ROOT}/config/sphinx.yml")
puts "Sphinx searchd: config/sphinx.yml exists, not copying"
else
FileUtils.cp(File.join(File.dirname(__FILE__), 'sphinx.yml'), "#{RAILS_ROOT}/config/sphinx.yml")
conf = render(File.join(File.dirname(__FILE__), 'sphinx.yml.erb'), :shared_path => File.expand_path(File.join(RAILS_ROOT,'..', '..', 'shared')))
File.open("#{RAILS_ROOT}/config/sphinx.yml", 'wb') do |f|
f.puts conf
end
puts "Sphinx searchd: created initial config/sphinx.yml"
end

Expand Down Expand Up @@ -48,7 +73,8 @@
else
crontab = res.chomp.split("\n")
res = []
job = "#{every} * * * * /usr/bin/rake RAILS_ENV=production sphinx:index >> /root/cron.log 2>&1"
root = File.expand_path(File.join(RAILS_ROOT, '..', '..', 'current'))
job = "#{every} * * * * cd #{root} && /usr/bin/env rake RAILS_ENV=production sphinx:index >> /root/cron.log 2>&1"
job_inserted = false
job_action = 'install'
crontab.each do |line|
Expand Down

0 comments on commit 5f58186

Please sign in to comment.