Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Redis-Search update

  • Loading branch information...
commit 24d265df9852b57bf6608c060f2ce3b76c5860eb 1 parent 00e114e
Jason Lee authored
2  Gemfile
@@ -73,7 +73,7 @@ gem "juggernaut"
73 73 # Diff 内容并输出 HTML 格式
74 74 gem "htmldiff", :git => "git://github.com/huacnlee/htmldiff.git"
75 75
76   -gem "redis-search", "0.3.1"
  76 +gem "redis-search", "0.4", :path => "../redis-search"
77 77
78 78 group :development do
79 79 gem 'rails-dev-boost-beta','0.1.2', :require => 'rails_development_boost'
12 Gemfile.lock
@@ -4,6 +4,13 @@ GIT
4 4 specs:
5 5 htmldiff (0.0.1)
6 6
  7 +PATH
  8 + remote: ../redis-search
  9 + specs:
  10 + redis-search (0.4)
  11 + redis (>= 2.1.1)
  12 + rmmseg-cpp-huacnlee (~> 0.2.8)
  13 +
7 14 GEM
8 15 remote: http://rubygems.org/
9 16 specs:
@@ -172,9 +179,6 @@ GEM
172 179 redis (2.1.1)
173 180 redis-namespace (1.0.3)
174 181 redis (< 3.0.0)
175   - redis-search (0.3.1)
176   - redis (~> 2.1.1)
177   - rmmseg-cpp-huacnlee (~> 0.2.8)
178 182 resque (1.15.0)
179 183 json (~> 1.4.6)
180 184 redis-namespace (>= 0.10.0)
@@ -243,7 +247,7 @@ DEPENDENCIES
243 247 rails (= 3.0.5)
244 248 rails-dev-boost-beta (= 0.1.2)
245 249 redis (= 2.1.1)
246   - redis-search (= 0.3.1)
  250 + redis-search (= 0.4)!
247 251 resque (= 1.15.0)
248 252 resque_mailer (= 1.0.1)
249 253 rmmseg-cpp-huacnlee (= 0.2.8)
12 app/controllers/search_controller.rb
@@ -8,11 +8,11 @@ def index
8 8 end
9 9
10 10 def all
11   - result = RedisSearch::Search.query("Topic",params[:q].strip,:limit => 10)
  11 + result = Redis::Search.query("Topic",params[:q].strip,:limit => 10)
12 12 if result.length < 10
13   - result += RedisSearch::Search.query("User",params[:q].strip,:limit => 10)
  13 + result += Redis::Search.query("User",params[:q].strip,:limit => 10)
14 14 if result.length < 10
15   - result += RedisSearch::Search.query("Ask",params[:q].strip,:limit => 10)
  15 + result += Redis::Search.query("Ask",params[:q].strip,:limit => 10)
16 16 end
17 17 end
18 18
@@ -31,7 +31,7 @@ def all
31 31 end
32 32
33 33 def topics
34   - result = RedisSearch::Search.complete("Topic",params[:q],:limit => 10)
  34 + result = Redis::Search.complete("Topic",params[:q],:limit => 10)
35 35 if params[:format] == "json"
36 36 lines = []
37 37 result.each do |item|
@@ -48,7 +48,7 @@ def topics
48 48 end
49 49
50 50 def asks
51   - result = RedisSearch::Search.query("Ask",params[:q].strip,:limit => 10)
  51 + result = Redis::Search.query("Ask",params[:q].strip,:limit => 10)
52 52 puts result.inspect
53 53 if params[:format] == "json"
54 54 render :json => result.to_json
@@ -62,7 +62,7 @@ def asks
62 62 end
63 63
64 64 def users
65   - result = RedisSearch::Search.complete("User",params[:q],:limit => 10)
  65 + result = Redis::Search.complete("User",params[:q],:limit => 10)
66 66 if params[:format] == "json"
67 67 render :json => result.to_json
68 68 else
2  app/models/ask.rb
@@ -2,7 +2,7 @@
2 2 class Ask
3 3 include Mongoid::Document
4 4 include Mongoid::Timestamps
5   - include RedisSearch
  5 + include Redis::Search
6 6 include BaseModel
7 7
8 8 field :title
2  app/models/topic.rb
... ... @@ -1,7 +1,7 @@
1 1 # coding: utf-8
2 2 class Topic
3 3 include Mongoid::Document
4   - include RedisSearch
  4 + include Redis::Search
5 5 include BaseModel
6 6
7 7 attr_accessor :current_user_id, :cover_changed, :followers_count_changed
2  app/models/user.rb
@@ -3,7 +3,7 @@ class User
3 3 include Mongoid::Document
4 4 include Mongoid::Timestamps
5 5 include Mongoid::Voter
6   - include RedisSearch
  6 + include Redis::Search
7 7 include BaseModel
8 8
9 9 devise :invitable, :database_authenticatable, :registerable,
2  config/environments/development.rb
@@ -12,7 +12,7 @@
12 12 # Show full error reports and disable caching
13 13 config.consider_all_requests_local = true
14 14 config.action_view.debug_rjs = true
15   - config.action_controller.perform_caching = true
  15 + config.action_controller.perform_caching = false
16 16
17 17 # Don't care if the mailer can't send
18 18 config.action_mailer.raise_delivery_errors = false
4 config/initializers/redis.rb
... ... @@ -1,5 +1,5 @@
1 1 require "redis"
2   -require "redis_search"
  2 +require "redis-search"
3 3
4 4 redis_config = YAML.load_file("#{Rails.root}/config/redis.yml")[Rails.env]
5 5 $redis = Redis.new(:host => redis_config[:host],:port => redis_config[:port])
@@ -7,7 +7,7 @@
7 7
8 8 redis_search = Redis.new(:host => redis_config[:host],:port => redis_config[:port])
9 9 redis_search.select("3")
10   -RedisSearch.configure do |config|
  10 +Redis::Search.configure do |config|
11 11 config.redis = redis_search
12 12 config.complete_max_length = 30
13 13 end
21 lib/tasks/search.rake
... ... @@ -1,21 +0,0 @@
1   -namespace :search do
2   - task :index => :environment do
3   - print "Now indexing search to Redis..."
4   - Ask.all.each do |item|
5   - item.redis_search_index_create
6   - item = nil
7   - print "."
8   - end
9   - Topic.all.each do |item|
10   - item.redis_search_index_create
11   - item = nil
12   - print "."
13   - end
14   - User.all.each do |item|
15   - item.redis_search_index_create
16   - item = nil
17   - print "."
18   - end
19   - puts "Done."
20   - end
21   -end

0 comments on commit 24d265d

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