Skip to content
This repository has been archived by the owner on Mar 6, 2018. It is now read-only.

Commit

Permalink
Redis-Search update
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee committed Sep 22, 2011
1 parent 00e114e commit 24d265d
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
12 changes: 8 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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|
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/ask.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
class Ask
include Mongoid::Document
include Mongoid::Timestamps
include RedisSearch
include Redis::Search
include BaseModel

field :title
Expand Down
2 changes: 1 addition & 1 deletion app/models/topic.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions config/initializers/redis.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
21 changes: 0 additions & 21 deletions lib/tasks/search.rake

This file was deleted.

0 comments on commit 24d265d

Please sign in to comment.