Skip to content
Browse files

Redis-Search update

  • Loading branch information...
1 parent 00e114e commit 24d265df9852b57bf6608c060f2ce3b76c5860eb @huacnlee committed Sep 23, 2011
View
2 Gemfile
@@ -73,7 +73,7 @@ gem "juggernaut"
# Diff 内容并输出 HTML 格式
gem "htmldiff", :git => "git://github.com/huacnlee/htmldiff.git"
-gem "redis-search", "0.3.1"
+gem "redis-search", "0.4", :path => "../redis-search"
group :development do
gem 'rails-dev-boost-beta','0.1.2', :require => 'rails_development_boost'
View
12 Gemfile.lock
@@ -4,6 +4,13 @@ GIT
specs:
htmldiff (0.0.1)
+PATH
+ remote: ../redis-search
+ specs:
+ redis-search (0.4)
+ redis (>= 2.1.1)
+ rmmseg-cpp-huacnlee (~> 0.2.8)
+
GEM
remote: http://rubygems.org/
specs:
@@ -172,9 +179,6 @@ GEM
redis (2.1.1)
redis-namespace (1.0.3)
redis (< 3.0.0)
- redis-search (0.3.1)
- redis (~> 2.1.1)
- rmmseg-cpp-huacnlee (~> 0.2.8)
resque (1.15.0)
json (~> 1.4.6)
redis-namespace (>= 0.10.0)
@@ -243,7 +247,7 @@ DEPENDENCIES
rails (= 3.0.5)
rails-dev-boost-beta (= 0.1.2)
redis (= 2.1.1)
- redis-search (= 0.3.1)
+ redis-search (= 0.4)!
resque (= 1.15.0)
resque_mailer (= 1.0.1)
rmmseg-cpp-huacnlee (= 0.2.8)
View
12 app/controllers/search_controller.rb
@@ -8,11 +8,11 @@ def index
end
def all
- result = RedisSearch::Search.query("Topic",params[:q].strip,:limit => 10)
+ result = Redis::Search.query("Topic",params[:q].strip,:limit => 10)
if result.length < 10
- result += RedisSearch::Search.query("User",params[:q].strip,:limit => 10)
+ result += Redis::Search.query("User",params[:q].strip,:limit => 10)
if result.length < 10
- result += RedisSearch::Search.query("Ask",params[:q].strip,:limit => 10)
+ result += Redis::Search.query("Ask",params[:q].strip,:limit => 10)
end
end
@@ -31,7 +31,7 @@ def all
end
def topics
- result = RedisSearch::Search.complete("Topic",params[:q],:limit => 10)
+ result = Redis::Search.complete("Topic",params[:q],:limit => 10)
if params[:format] == "json"
lines = []
result.each do |item|
@@ -48,7 +48,7 @@ def topics
end
def asks
- result = RedisSearch::Search.query("Ask",params[:q].strip,:limit => 10)
+ result = Redis::Search.query("Ask",params[:q].strip,:limit => 10)
puts result.inspect
if params[:format] == "json"
render :json => result.to_json
@@ -62,7 +62,7 @@ def asks
end
def users
- result = RedisSearch::Search.complete("User",params[:q],:limit => 10)
+ result = Redis::Search.complete("User",params[:q],:limit => 10)
if params[:format] == "json"
render :json => result.to_json
else
View
2 app/models/ask.rb
@@ -2,7 +2,7 @@
class Ask
include Mongoid::Document
include Mongoid::Timestamps
- include RedisSearch
+ include Redis::Search
include BaseModel
field :title
View
2 app/models/topic.rb
@@ -1,7 +1,7 @@
# coding: utf-8
class Topic
include Mongoid::Document
- include RedisSearch
+ include Redis::Search
include BaseModel
attr_accessor :current_user_id, :cover_changed, :followers_count_changed
View
2 app/models/user.rb
@@ -3,7 +3,7 @@ class User
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Voter
- include RedisSearch
+ include Redis::Search
include BaseModel
devise :invitable, :database_authenticatable, :registerable,
View
2 config/environments/development.rb
@@ -12,7 +12,7 @@
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_view.debug_rjs = true
- config.action_controller.perform_caching = true
+ config.action_controller.perform_caching = false
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
View
4 config/initializers/redis.rb
@@ -1,13 +1,13 @@
require "redis"
-require "redis_search"
+require "redis-search"
redis_config = YAML.load_file("#{Rails.root}/config/redis.yml")[Rails.env]
$redis = Redis.new(:host => redis_config[:host],:port => redis_config[:port])
$redis.select("0")
redis_search = Redis.new(:host => redis_config[:host],:port => redis_config[:port])
redis_search.select("3")
-RedisSearch.configure do |config|
+Redis::Search.configure do |config|
config.redis = redis_search
config.complete_max_length = 30
end
View
21 lib/tasks/search.rake
@@ -1,21 +0,0 @@
-namespace :search do
- task :index => :environment do
- print "Now indexing search to Redis..."
- Ask.all.each do |item|
- item.redis_search_index_create
- item = nil
- print "."
- end
- Topic.all.each do |item|
- item.redis_search_index_create
- item = nil
- print "."
- end
- User.all.each do |item|
- item.redis_search_index_create
- item = nil
- print "."
- end
- puts "Done."
- end
-end

0 comments on commit 24d265d

Please sign in to comment.
Something went wrong with that request. Please try again.