Giter Club home page Giter Club logo

redis-search's Introduction

Redis-Search (Deprecated! 不在维护!)

High performance real-time prefix search, indexes store in Redis for Rails application. 中文介绍和使用说明

NOTE!

There have more better ways you can choice!

下面的两种方式将是更好的选择:

Master Status

Gem Version CI Status CodeCov

Features

  • Real-time search
  • High performance
  • Prefix match search
  • Support match with alias
  • Support ActiveRecord and Mongoid
  • Sort results by one field
  • Homophone search, pinyin search
  • Search as pinyin first chars
  • Conditions support

Requirements

  • Redis 2.2+

Install

gem 'redis-search'
$ bundle install

Configure

  • Create file in: config/initializers/redis-search.rb
require "redis"
require "redis-namespace"
require "redis-search"

# don't forget change namespace
redis = Redis.new(host: '127.0.0.1', port: '6379')
# We suggest you use a special db in Redis, when you need to clear all data, you can use `flushdb` command to cleanup.
redis.select(3)
# Give a special namespace as prefix for Redis key, when your have more than one project used redis-search, this config will make them work fine.
redis = Redis::Namespace.new("your_app_name:redis_search", redis: redis)
Redis::Search.configure do |config|
  config.redis = redis
  config.complete_max_length = 100
  config.pinyin_match = true
end

Usage

  • Bind Redis::Search callback event, it will to rebuild search indices when data create or update.
class Post < ActiveRecord::Base
  include Redis::Search

  belongs_to :user
  belongs_to :category

  redis_search title_field: :title,
               score_field: :hits,
               condition_fields: [:user_id, :category_id],
               ext_fields: [:category_name]

  def category_name
    self.category.name
  end
end
class User < ActiveRecord::Base
  include Redis::Search

  serialize :alias_names, Array

  redis_search title_field: :name,
               alias_field: :alias_names,
               score_field: :followers_count,
               ext_fields: [:email, :tagline]
end
class SearchController < ApplicationController
  # GET /search_users?q=j
  def search_users
    Post.prefix_match(params[:q], conditions: { user_id: 12, category_id: 4 })
  end
end

Index data to Redis

Specify Model

Redis-Search index data to Redis from your model (pass name as CLASS environment variable).

$ rake redis_search:index:model CLASS='User'

Customize the batch size:

$ rake redis_search:index:model CLASS='User' BATCH=100

All Models

Redis-Search all index data to Redis from app/models (or use DIR environment variabl).

$ rake redis_search:index DIR=app/models

Customize the batch size:

$ rake redis_search:index DIR=app/models BATCH=100

Documentation

Benchmark test

You can run the rake command (see Rakefile) to make test. There is my performance test result.

Demo

Projects used redis-search:

License

  • MIT

redis-search's People

Contributors

huacnlee avatar iamzhangdabei avatar jjyr avatar nowa avatar pmq20 avatar tumayun avatar wongyouth avatar ycwei5 avatar yesmeck avatar ymkjp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

redis-search's Issues

更新redis_search :title的指向字段后部分搜索结果未更新的问题

情况描述如下:

  1. 我有一个模型类叫Products,里面有2000条数据,redis search的title是desc字段,其中60条desc字段有"邮件"字样。搜索结果无问题。
  2. 后修改redis search的title到keyword字段,之前desc字段里有“邮件”两字的products中,有一个id为30的product的keyword字段是没有“邮件”这两个字的。
  3. rake redis_search:index 后,发现还是会搜索出这个id为30的product.
  4. 用redis的gui工具查看本地的redis,发现redis_search:Products中hash key为30的value没有问题,里面并没有“邮件”两字。
  5. 在tempinterstore下有 “邮件+Product”这样的表,看里面,也没有30这个value
  6. 在tempsunionstore下也有 “邮件+Product”这样的表,看里面,也没有30这个value,但是数量和tempinterstore下面的不一样。
  7. 尝试修改了30这个ID的产品的desc字段,而后重新更新redis索引,也不行。

另外,不知道redis_search有没有一个强制全部重写索引的办法呢?

搜索条件无效

Model Map:
belongs_to :user

redis_search_index(:title_field => :title,
:score_field => :view_count,
:condition_fields => [:user_id],
:ext_fields => [:id, :title])

Controller:
Redis::Search.query("Map", params[:q], :conditions => {:user_id => 12})

无论后面的条件是否加上,返回的结果都是所有user_id的结果,木有实现过滤的效果。
数据库:sqlite, ActiveRecord
请华顺兄给指导一下,谢谢!

mysql下无法建立索引的问题

要索引的Model中有title字段,于是添加索引:
redis_search_index(:title_field => :title)
但是rake redis_search:index --trace时报错:

Now indexing search to Redis...
rake aborted!
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each
ruby-1.9.2-p180/gems/redis-search-0.7.0/lib/redis/search/tasks.rb:12:in `block (2 levels) in <top (required)>'
....

如何批量清空索引?

想手动清空之前建立的索引,由于Redis 中同时还存有其他的数据所以不能直接 flushall,想列出所有相关的KEY,但是发现通过 redis-cli keys * 返回结果中看不到 Redis search 相关的key,请问redis-search 存储的规则是怎样呢?

随便问一句

redis搜索富文本会不会产生问题?
sphinx呢?

如果是富文本,应该怎样搜索?

task tIDENTIFIER

ERROR:
lib/redis-search/tasks.rb:35: syntax error, unexpected tIDENTIFIER, expecting ')'
batch = ENV['BATCH'].to_i || 1000

and in lib/redis-search/tasks.rb line 34
klass = Object.const_get((ENV['CLASS'].to_s)

不能修改在搜索字段的内容为中文,直接把我的server挂了

环境Mysql Devise
添加了 redis_search_index(:title_field => :name)
1.9.3-p194 :008 > u.name = '张三'
=> "张三"
1.9.3-p194 :009 > u.save
(0.2ms) BEGIN
(0.5ms) UPDATE users SET name = '张三', updated_at = '2012-08-03 18:51:09' WHERE users.id = 1
/home/fahchen/.rvm/gems/ruby-1.9.3-p194/gems/redis-search-0.9.0/lib/redis/search/finder.rb:187: [BUG] Segmentation fault
ruby 1.9.3p194 (2012-04-20 revision 35410) [i686-linux]

-- Control frame information -----------------------------------------------
c:0062 p:---- s:0253 b:0253 l:000252 d:000252 CFUNC :new
c:0061 p:0059 s:0249 b:0249 l:000248 d:000248 METHOD /home/fahchen/.rvm/gems/ruby-1.9.3-p194/gems/redis-search-0.9.0/lib/redis/search/finder.rb:187
c:0060 p:0013 s:0243 b:0243 l:000242 d:000242 METHOD /home/fahchen/.rvm/gems/ruby-1.9.3-p194/gems/redis-search-0.9.0/lib/redis/search/finder.rb:7
c:0059 p:0019 s:0239 b:0239 l:000238 d:000238 METHOD /home/fahchen/.rvm/gems/ruby-1.9.3-p194/gems/redis-search-0.9.0/lib/redis/search/index.rb:66
c:0058 p:0077 s:0232 b:0232 l:000231 d:000231 METHOD /home/fahchen/.rvm/gems/ruby-1.9.3-p194/gems/redis-search-0.9.0/lib/redis/search/index.rb:54
c:0057 p:0048 s:0226 b:0226 l:000217 d:000225 BLOCK (eval):37
c:0056 p:---- s:0223 b:0223 l:000222 d:000222 FINISH
c:0055 p:---- s:0221 b:0221 l:000220 d:000220 CFUNC :each
c:0054 p:0018 s:0218 b:0218 l:000217 d:000217 METHOD (eval):36
c:0053 p:0059 s:0214 b:0214 l:000210 d:000213 LAMBDA (eval):83
c:0052 p:---- s:0211 b:0211 l:000210 d:000210 FINISH
c:0051 p:0626 s:0209 b:0209 l:000208 d:000208 METHOD /home/fahchen/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:492
c:0050 p:0115 s:0203 b:0203 l:000202 d:000202 METHOD /home/fahchen/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:405
c:0049 p:0027 s:0194 b:0194 l:000193 d:000193 METHOD /home/fahchen/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:385
c:0048 p:0024 s:0189 b:0189 l:000188 d:000188 METHOD /home/fahchen/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:81
c:0047 p:0013 s:0183 b:0183 l:001f80 d:001f80 METHOD /home/fahchen/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.6/lib/active_record/callbacks.rb:272
c:0046 p:0055 s:0179 b:0179 l:000178 d:000178 METHOD /home/fahchen/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.6/lib/active_record/persistence.rb:344
c:0045 p:0008 s:0175 b:0175 l:001e4c d:000174 BLOCK /home/fahchen/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.6/lib/active_record/callbacks.rb:264
c:0044 p:0137 s:0173 b:0173 l:000172 d:000172 METHOD /home/fahchen/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:425
c:0043 p:0115 s:0167 b:0167 l:000166 d:000166 METHOD /home/fahchen/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:405
c:0042 p:0027 s:0158 b:0158 l:000157 d:000157 METHOD /home/fahchen/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:385
c:0041 p:0024 s:0153 b:0153 l:000152 d:000152 METHOD /home/fahchen/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:81
c:0040 p:0013 s:0147 b:0147 l:001e4c d:001e4c METHOD /home/fahchen/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.6/lib/active_record/callbacks.rb:264
c:0039 p:0013 s:0144 b:0144 l:000143 d:000143 METHOD /home/fahchen/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.6/lib/active_record/persistence.rb:84
c:0038 p:0027 s:0140 b:0140 l:000139 d:000139 METHOD /home/fahchen/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.6/lib/active_record/validations.rb:50
c:0037 p:0012 s:0136 b:0136 l:000135 d:000135 METHOD /home/fahchen/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.6/lib/active_record/attribute_methods/dirty.rb:22
c:0036 p:0010 s:0131 b:0131 l:0012b0 d:000130 BLOCK /home/fahchen/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.6/lib/active_record/transactions.rb:241
c:0035 p:0015 s:0129 b:0129 l:001360 d:000128 BLOCK /home/fahchen/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.6/lib/active_record/transactions.rb:295
c:0034 p:0232 s:0127 b:0127 l:000126 d:000126 METHOD /home/fahchen/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract/database_stateme
c:0033 p:0025 s:0118 b:0118 l:000117 d:000117 METHOD /home/fahchen/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.6/lib/active_record/transactions.rb:208
c:0032 p:0022 s:0113 b:0113 l:001360 d:001360 METHOD /home/fahchen/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.6/lib/active_record/transactions.rb:293
c:0031 p:0009 s:0109 b:0109 l:0012b0 d:0012ec BLOCK /home/fahchen/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.6/lib/active_record/transactions.rb:241
c:0030 p:0017 s:0107 b:0107 l:000106 d:000106 METHOD /home/fahchen/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.6/lib/active_record/transactions.rb:252
c:0029 p:0011 s:0104 b:0104 l:0012b0 d:0012b0 METHOD /home/fahchen/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.6/lib/active_record/transactions.rb:240
c:0028 p:0011 s:0100 b:0100 l:000424 d:000099 EVAL (irb):9
c:0027 p:---- s:0098 b:0098 l:000097 d:000097 FINISH
c:0026 p:---- s:0096 b:0096 l:000095 d:000095 CFUNC :eval
c:0025 p:0028 s:0089 b:0089 l:000088 d:000088 METHOD /home/fahchen/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/workspace.rb:80
c:0024 p:0033 s:0082 b:0081 l:000080 d:000080 METHOD /home/fahchen/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/context.rb:254
c:0023 p:0031 s:0076 b:0076 l:001b94 d:000075 BLOCK /home/fahchen/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb.rb:159
c:0022 p:0042 s:0068 b:0068 l:000067 d:000067 METHOD /home/fahchen/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb.rb:273
c:0021 p:0011 s:0063 b:0063 l:001b94 d:000062 BLOCK /home/fahchen/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb.rb:156
c:0020 p:0144 s:0059 b:0059 l:000042 d:000058 BLOCK /home/fahchen/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/ruby-lex.rb:243
c:0019 p:---- s:0056 b:0056 l:000055 d:000055 FINISH
c:0018 p:---- s:0054 b:0054 l:000053 d:000053 CFUNC :loop
c:0017 p:0009 s:0051 b:0051 l:000042 d:000050 BLOCK /home/fahchen/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/ruby-lex.rb:229
c:0016 p:---- s:0049 b:0049 l:000048 d:000048 FINISH
c:0015 p:---- s:0047 b:0047 l:000046 d:000046 CFUNC :catch
c:0014 p:0023 s:0043 b:0043 l:000042 d:000042 METHOD /home/fahchen/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/ruby-lex.rb:228
c:0013 p:0046 s:0040 b:0040 l:001b94 d:001b94 METHOD /home/fahchen/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb.rb:155
c:0012 p:0011 s:0037 b:0037 l:001ca4 d:000036 BLOCK /home/fahchen/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb.rb:70
c:0011 p:---- s:0035 b:0035 l:000034 d:000034 FINISH
c:0010 p:---- s:0033 b:0033 l:000032 d:000032 CFUNC :catch
c:0009 p:0183 s:0029 b:0029 l:001ca4 d:001ca4 METHOD /home/fahchen/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb.rb:69
c:0008 p:0251 s:0024 b:0024 l:002218 d:002218 METHOD /home/fahchen/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/commands/console.rb:47
c:0007 p:0019 s:0020 b:0020 l:000019 d:000019 METHOD /home/fahchen/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/commands/console.rb:8
c:0006 p:0596 s:0016 b:0016 l:000015 d:000015 TOP /home/fahchen/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/commands.rb:41
c:0005 p:---- s:0012 b:0012 l:000011 d:000011 FINISH
c:0004 p:---- s:0010 b:0010 l:000009 d:000009 CFUNC :require
c:0003 p:0061 s:0006 b:0006 l:000fe4 d:000bfc EVAL script/rails:6
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:0000 s:0002 b:0002 l:000fe4 d:000fe4 TOP

v1.0.0 暂时没有办法使用

目测到的问题
在建索引时
base.rb
150行redis_search_index_batch_create方法,count与progressbar没有办法传入_redis_search_reindex_items
自己修了后,对应的检索也没有办法用
以前很好用的redis-search忘了是哪个版本了 T-T

@huacnlee

文档跟进

hi,
最近一个项目用到相关的搜索功能.尝试了一下这个项目, 发现不论是英文文档还是中文文档都不是特别准确, 走了不少弯路, 最终看代码才正常跑起来.不知您这边能否对这些文档进行进行润色修正? 我最近比较忙, 如果您暂时没时间修理这个问题, 后续待我有空之后, 可以帮助您修正一些问题.

下面是我碰到的文档上的一些问题:

  1. 我使用的是最新的0.9.6, 但 Github 项目 Readme 上建立索引数据的 rake 任务是不存在的. 0.9.6 只有 rake redis_search:index 这个任务.
  2. 中文 wiki 上环境和 Gem 的配置没有更新, 中文的 Gem 安装的版本比较低.
  3. 中文 wiki 上最底下的的一段代码让人不知所云.
  4. 用 Redis::Search.complete 进行搜索的话, 我看代码的实现貌似得必须在相应的 Model 下配置 :prefix_search_enable => true. 但给的说明没有提到这个问题.
  5. 中文的 wiki 貌似有比较多的 typo. 尤其是在 redis_search_index 参数说明这个小节.

using gem without rails

redis-search.rb

should

require "redis"

search/base

Example, seems to indicate that Rails is not required for the gem to work (since it uses mongoid), however search/base has this

extend ActiveSupport::Concern

Which is part of active_support. Is it possible to use this gem with out Rails?
Thanks

complete搜不出结果

有几个问题请教一下:
1、使用query可以搜出结果,使用complete搜不出结果。

Redis::Search.query("Post","abc",:limit => 10) #搜到一条记录
Redis::Search.complete("Post","abc",:limit => 10) #未搜到记录

2、关于分词系统
为什么我只能搜到词,而搜不到字。如:
中文 “企业”可以搜到,“企”就搜不到;
英文“abc”可以搜到,“a”就搜不到;

需要什么额外配置吗?

搜索结果第一次有问题,但是之后就正确了

redis_search设置

Redis::Search.configure do |config|
  config.redis = redis
  config.complete_max_length = 100
  config.pinyin_match = false
  config.disable_rmmseg = true
end

模型索引设置

class User < ActiveRecord::Base
  include Redis::Search
  redis_search_index :title_field => :name,
                     :prefix_index_enable => true,
                     :condition_fields => [:is_admin?, :is_teacher?, :is_student?],
                     :ext_fields => [:normal_avatar_url]
end

查询语句

Redis::Search.query 'User', "王", :conditions => {:is_admin? => :false}

第一次结果

[{"title"=>"王冠成", "id"=>67, "type"=>"User", "created_at"=>"2013-05-17T10:47:10+08:00", "is_admin?"=>false, "is_teacher?"=>false, "is_student?"=>true}, 
{"title"=>"吴家荣", "id"=>60, "type"=>"User", "created_at"=>"2013-05-17T10:47:09+08:00", "is_admin?"=>false, "is_teacher?"=>false, "is_student?"=>true}, 
{"title"=>"王北安", "id"=>57, "type"=>"User", "created_at"=>"2013-05-17T10:47:08+08:00", "is_admin?"=>false, "is_teacher?"=>false, "is_student?"=>true}, 
{"title"=>"王培芳", "id"=>53, "type"=>"User", "created_at"=>"2013-05-17T10:47:08+08:00", "is_admin?"=>false, "is_teacher?"=>false, "is_student?"=>true}, 
{"title"=>"魏江山", "id"=>52, "type"=>"User", "created_at"=>"2013-05-17T10:47:08+08:00", "is_admin?"=>false, "is_teacher?"=>false, "is_student?"=>true}, 
{"title"=>"王鹏昊", "id"=>51, "type"=>"User", "created_at"=>"2013-05-17T10:47:08+08:00", "is_admin?"=>false, "is_teacher?"=>false, "is_student?"=>true}, 
{"title"=>"王简丽", "id"=>42, "type"=>"User", "created_at"=>"2013-05-17T10:47:07+08:00", "is_admin?"=>false, "is_teacher?"=>false, "is_student?"=>true}, 
{"title"=>"王天乐", "id"=>18, "type"=>"User", "created_at"=>"2013-05-17T10:47:04+08:00", "is_admin?"=>false, "is_teacher?"=>true, "is_student?"=>false}]

之后的结果

[{"title"=>"王冠成", "id"=>67, "type"=>"User", "created_at"=>"2013-05-17T10:47:10+08:00", "is_admin?"=>false, "is_teacher?"=>false, "is_student?"=>true}, 
{"title"=>"王北安", "id"=>57, "type"=>"User", "created_at"=>"2013-05-17T10:47:08+08:00", "is_admin?"=>false, "is_teacher?"=>false, "is_student?"=>true}, 
{"title"=>"王培芳", "id"=>53, "type"=>"User", "created_at"=>"2013-05-17T10:47:08+08:00", "is_admin?"=>false, "is_teacher?"=>false, "is_student?"=>true}, 
{"title"=>"王鹏昊", "id"=>51, "type"=>"User", "created_at"=>"2013-05-17T10:47:08+08:00", "is_admin?"=>false, "is_teacher?"=>false, "is_student?"=>true}, 
{"title"=>"王简丽", "id"=>42, "type"=>"User", "created_at"=>"2013-05-17T10:47:07+08:00", "is_admin?"=>false, "is_teacher?"=>false, "is_student?"=>true}, 
{"title"=>"王天乐", "id"=>18, "type"=>"User", "created_at"=>"2013-05-17T10:47:04+08:00", "is_admin?"=>false, "is_teacher?"=>true, "is_student?"=>false}]

alias_field: :desc nil issues

rake aborted!
can't clone NilClass
(eval):12:in clone' (eval):12:inredis_search_alias_value'
(eval):22:in redis_search_index_create' /var/www/online_20120824/vendor/bundle/ruby/1.9.1/gems/redis-search-0.9.0/lib/redis/search/tasks.rb:17:inblock (5 levels) in <top (required)>'
/var/www/online_20120824/vendor/bundle/ruby/1.9.1/gems/redis-search-0.9.0/lib/redis/search/tasks.rb:16:in each' /var/www/online_20120824/vendor/bundle/ruby/1.9.1/gems/redis-search-0.9.0/lib/redis/search/tasks.rb:16:inblock (4 levels) in <top (required)>'
/var/www/online_20120824/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.8/lib/active_record/relation/batches.rb:72:in find_in_batches' /var/www/online_20120824/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.8/lib/active_record/querying.rb:8:infind_in_batches'
/var/www/online_20120824/vendor/bundle/ruby/1.9.1/gems/redis-search-0.9.0/lib/redis/search/tasks.rb:15:in block (3 levels) in <top (required)>' /var/www/online_20120824/vendor/bundle/ruby/1.9.1/gems/redis-search-0.9.0/lib/redis/search/tasks.rb:12:ineach'
/var/www/online_20120824/vendor/bundle/ruby/1.9.1/gems/redis-search-0.9.0/lib/redis/search/tasks.rb:12:in `block (2 levels) in <top (required)>'

NoMethodError (undefined method `strip' for nil:NilClass)

今天学下用redids-search 但是总是出现这个错误,是在 Redis::Search.query("Topic", params[:key])这个地方抛出来的
我运行命令 rake redis_search:index 把数据放入到redis中,命名窗口给出反馈 indexed 705 rows | Time spend:3.8s
然后查看redis-server 命令窗口 ,显示 DB3:1411keys(0 volatile)in 048 slots Ht

感觉前期工作都准备好了,但是打开页面,出现错误NoMethodError (undefined method `strip' for nil:NilClass)是在 Redis::Search.query("Topic", params[:key])这个地方抛出来的,不知道怎么解决了

补充下 我是在windows下测试的,使用windowns下redis最新版本2.0.2

关于删除的一些问题

目前我正在模仿写一个java 版本的,从删除的代码上看是需要再次传入 title 和 所有aliases ,感觉很麻烦而且也没有删除对应的condition_fields 。

这里我想请问如果我把所有索引对应的redis key 都存在一个redis set 里,删除的时候全取出来用于删除对应key下的id值是否可行?

执行rake redis_search:index后,redis里却没有数据,所以autocomplete功能查不出来数据?

老大让做seo酒店,觉得用redis-search来做“城市下拉框的提示”挺不错。你的sample跑通了,但是到了实际项目就出现了问题,求助
1、image

2、接着到redis里查,没有?
image

3、db是mysql,gem用的mysql2,测试过能从db获得数据。不知道是哪里出了问题,导致数据没索引到redis中?
下面是config/initializers/redis-search.rb:
image

incompatible character encodings: UTF-8 and ASCII-8BIT

打开了拼音搜索后,对以下词语的索引会报错:
戒毒所所长
倩女幽魂

简单调查了下,应该是ruby-pinyin中的sentence方法识别多音字导致的:
[55] pry(Game):2> PinYin.sentence("戒毒所所长")
=> "jie du suo suo chanɡ" (这里的g是一个很怪异的小g, 复制粘贴过来就正常了)
[61] pry(Game):2> PinYin.sentence("倩女幽魂2")
=> "qian n̈u you hun 2"

通过配置PinYin.backend = PinYin::Backend::Simple.new 依然没有解决问题。
过来发一记,看看有没有人遇到过。

更新时报错

当我对使用redis-search索引的模型类实例使用update_attributes时 报错.

Redis::InheritedError (Tried to use a connection from a child process without reconnecting. You need to reconnect to Redis after forking.):

找到http://ruby-china.org/topics/6190 这个解决了

redis_search_index()怎么用?

redis_search_index(:title_field => :title,
                     :score_field => :hits,
                     :condition_fields => [:user_id, :category_id],
                     :ext_fields => [:category_name])

这个title_field、score_field……是什么意思?
具体怎么用的?

搜索条件conditions被修改后查询结果不正确

在ActiveRecord的condition_fields字段上进行初始索引,搜索结果正确。但之后update_attribute修改ActiveRecord的condition_fields字段内容后,在Model:_by:_conditions各种条件中,结果重复出现,导致指定conditions不起作用。根据代码推测在做redis_search_index_delete的时候,可能没有删除Model:_by:_conditions中的旧内容

请教一下作者,想在一个model对两个字段进行索引

1.如题,请教下作者,项目用到贵gem,在一个model对两个字段进行索引,在new一个model时,只会对一个字段进行索引,该如何进行扩展啊?或者思路?

例如:

class Person < ActiveRecord::Base
redis_search_index(title_field: :name_cn,
prefix_index_enable: false,
ext_fields: [ :name_en, :age])

redis_search_index(title_field: :name_en,
prefix_index_enable: false,
ext_fields: [ :name_cn, :age])
end

2.update问题。在修改添加过索引的model字段时,貌似会报错。error: segmentation fault

搜索条件的怪异问题

我使用Redis::Search.complete搜索,如果搜索ab,附带搜索条件与不附带搜索条件,返回结果都正确。
如果搜索a,不附带搜索条件,结果正确,附带搜索条件,无结果(数据库中有符合的记录)。

怪哉!

rake redis_search:index not working

i try legacy index update

but rake aborted! because Redis::Search.indexed_models is nil

below my trace log

** Invoke redis_search:index (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute redis_search:index

REDIS-SEARCH INDEX

                                                                                     Now indexing search to Redis...

rake aborted!
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each
/Users/ried/.rvm/gems/ruby-1.9.3-p0/gems/redis-search-0.7.0/lib/redis/search/tasks.rb:12:in block (2 levels) in <top (required)>' /Users/ried/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/task.rb:205:incall'
/Users/ried/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/task.rb:205:in block in execute' /Users/ried/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/task.rb:200:ineach'
/Users/ried/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/task.rb:200:in execute' /Users/ried/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/task.rb:158:inblock in invoke_with_call_chain'
/Users/ried/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/monitor.rb:211:in mon_synchronize' /Users/ried/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/task.rb:151:ininvoke_with_call_chain'
/Users/ried/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/task.rb:144:in invoke' /Users/ried/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/application.rb:116:ininvoke_task'
/Users/ried/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/application.rb:94:in block (2 levels) in top_level' /Users/ried/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/application.rb:94:ineach'
/Users/ried/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/application.rb:94:in block in top_level' /Users/ried/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/application.rb:133:instandard_exception_handling'
/Users/ried/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/application.rb:88:in top_level' /Users/ried/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/application.rb:66:inblock in run'
/Users/ried/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/application.rb:133:in standard_exception_handling' /Users/ried/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/application.rb:63:inrun'
/Users/ried/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/bin/rake:33:in <top (required)>' /Users/ried/.rvm/gems/ruby-1.9.3-p0/bin/rake:19:inload'
/Users/ried/.rvm/gems/ruby-1.9.3-p0/bin/rake:19:in `

'
Tasks: TOP => redis_search:index

不支持单表继承

使用了单表继承的一个model作为indexed model, 输出 'not support', 看了代码, indexed_model的superclass要是'ActiveRecord::Base'才可以.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.