拼音字母搜索功能
使用的gem:
https://github.com/huacnlee/redis-search
使用方法
配置文件路径: config/initializers/redis_search.rb
# -*- coding: utf-8 -*-
require "redis"
require "redis-namespace"
require "redis-search"
begin
redis = Redis.new(:host => "127.0.0.1",:port => "6379")
redis.select(3)
redis = Redis::Namespace.new("you_app_name:redis_search", :redis => redis)
Redis::Search.configure do |config|
config.redis = redis
config.complete_max_length = 100
config.pinyin_match = true
# 是否关闭中文分词,true为关闭,可节省内存占用
config.disable_rmmseg = true
end
rescue
p "redis server not running"
end
为模块做索引
class User < ActiveRecord::Base
include Redis::Search
def hits
# 计算权重
end
redis_search_index(:title_field => :name, #主要索引域
:alias_field => :login, #次要的索引域
:score_field => :hits, #传入一个方法名,根据方法返回值来确定权重
:prefix_index_enable => true, #逐字索引,逐字搜索时开启
:condition_fields => [:role], #条件,传入的是一组字段,搜索时可以以
:conditions => {:role => :admin}) 的方法使用。
:ext_fields => [:email, :created_at]) #其余需要索引的域
end
# 重新build索引
rake redis_search:index
搜索
# 逐字搜索
Redis::Search.complete("User", params[:query], :conditions => {:role => :admin})
# 全文搜索
Redis::Search.query("User", params[:query], :conditions => {:role => :admin})
分享到:
相关推荐
gem5仿真器的介绍与说明,并且指导该如何运行gem5仿真器
thin.gem eventmachine.gem for windows
SECS/GEM/GEM300的测试模拟器,某公司流出版本,好用无BUG,功能支持好用,不想其他SECS Driver每次都要编辑交互指令。
LetterAvatar 从用户名(或其他字符串)创建字母头像的 gem
gem5模拟器的详细介绍,各个部分的系统介绍,入门必看。
在本章中,我们将重点介绍x86,因为它是gem5中使用的最受欢迎的ISA之一。 包含有关如何配置ARM系统的信息。对于其他ISA,您可以参考configs / common / FSConfig.py中主线gem5中的代码。 在开始之前,请确保已构建...
command:gem
版本为:rails-2.3.8.gem 可使用指令安装:gem install rails-2.3.8.gem
SECS GEM Solution
本软件专门用于gem系列血气分析仪(gem3000.gem3500,gem4000)用串口连接电脑传输测试结果,样本数据处理,并自定义打印分析报告单。
ruby资源文件,ruby rdoc.gem文件,离线ruby文件包
Ruby gem 通过按字母顺序排列您的 Gemfile 来缓解您的强迫症 安装 将此行添加到应用程序的 Gemfile 中: gem 'alphabetize' 然后执行: $ bundle 或者自己安装: $ gem install alphabetize 用法 转到 Rails ...
环球GEM接口协议。This document supports UPS+ 2.0.x and higher and Fuzion 1.0.x and higher
PLC的SECS/GEM通讯白皮书 采取分布式结构设计。 单个服务器瘫痪,立即切换到新的其他服务器分担连接,实现无丢失服务 超高并发处理,单服务器可达上百的连接数量。 快速、稳定可靠,您的选择不会有错。 ...
CPU 2006在Gem5中1
deprecated-2.0.1.gem 下载
gem5学习基础完整版,介绍了gem5环境的安装,以及一些基本概念。 gem5仿真器是用于计算机系统体系结构研究的模块化平台,涵盖系统级体系结构以及处理器微体系结构。1、多个可互换的CPU型号。 gem5提供了四种基于...
gem5模拟器介绍,主要介绍gem5的功能、gem5的特点,以及gem5的应用
redis-3.0.0.gem redis-3.0.0.gem redis-3.0.0.gem redis-3.0.0.gem redis-3.0.0.gem
详细介绍SECS/GEM通讯规范和SECSII的消息介绍文档