可以下面,下载到thinking-sphinx、sphinx(sphinx插件包)、riddle插件
1.安装thinking-sphinx,在Gemfile中添加下面代码:
gem 'thinking-sphinx'
再运行bundle,就自动安装thinking-sphinx;或者下载gem包安装
如果没有riddle,请先安装riddle插件
2.把sphinx插件放到vendor/plugins目录下,再Gemfile文件中添加
gem 'sphinx'
运行bundle,自动安装sphinx;或下载sphinx的gem插件,安装。
thinking-sphinx和sphinx安装完成,全文搜索的插件就安装好了。
3.配置在config下新建一个文件sphinx.yml,里面添加如下代码:
development: &my_settings
enable_star: 1
min_prefix_len: 0
min_infix_len: 2
min_word_len: 1
max_results: 70000
morphology: none
listen: localhost:3312
port: 9312
charset_type: utf-8
exceptions: f:/wangchuang/wangchuang/log/sphinx_exception.log
##这个路径要根据实际写
chinese_dictionary: f:/wangchuang/wangchuang/vendor/plugins/sphinx/bin/xdict
##这个路径要根据实际写
bin_path: f:/wangchuang/wangchuang/vendor/plugins/sphinx/bin
##这个路径要根据实际写
test:
<<: *my_settings
production:
<<: *my_settings
4.添加delta字段,如下写法:
class AddDeltaToTopic < ActiveRecord::Migration
def self.up
add_column :topics, :delta,:boolean, :default => true, :null => false
add_column :posts, :delta,:boolean, :default => true, :null => false
end
def self.down
remove_column :topics, :delta
remove_column :posts, :delta
end
end
5.model中添加如下代码:
define_index do
indexes :title,:sortable=>true ##索引的字段,如果其他字段也要索引,就重新写一句
has :created_at,:updated_at
set_property :delta => true ##代码实时索引,并且表中要有delta字段
end
6.配置好后,随便运行下面代码一句代码:
rake thinking_sphinx:configure
rake ts:conf
rake ts:config
7.运行好后,会在config目录下生成一个development.sphinx.conf文件,打开文件,
在charset_type = utf-8这句代码下面,添加 chinese_dictionary=f:/wangchuang/wangchuang/vendor/plugins/sphinx/bin/xdict,有几个charset_type = utf-8,就要添加几个chinese_dictionary=f:/wangchuang/wangchuang/vendor/plugins/sphinx/bin/xdict
8.上面修改好后,建立索引,运行下面代码:
rake ts:index INDEX_ONLY=true
如果有建过索引,可运行rake ts:rebuild INDEX_ONLY=true
INDEX_ONLY=true主要是起不生成(development.sphinx.conf)索引文件;如果已经存在development.sphinx.conf文件,在建立索引时就要添加代码INDEX_ONLY=true
9.运行下面代码,开/关服务
rake ts:start ##起服务
rake ts:stop ##停服务
参考网站:
http://www.cnblogs.com/rubylouvre/archive/2009/07/23/1529029.html
问题
1.在搜索中,如果出现下面的错误可以忽视
Sphinx cannot be found on your system. You may need to configure the following
settings in your config/sphinx.yml file:
* bin_path
* searchd_binary_name
* indexer_binary_name
For more information, read the documentation:
http://freelancing-god.github.com/ts/en/advanced_config.html
2.在搜索中,如果出现下面的错误可以忽视
Riddle cannot detect Sphinx on your machine, and so can't determine which
version of Sphinx you are planning on using. Please use one of the following
lines after "require 'riddle'" to avoid this warning.
require 'riddle/0.9.8'
# or
require 'riddle/0.9.9'
# or
require 'riddle/1.10'
分享到:
相关推荐
一个插件,用于使用thinking_sphinx为Rails应用程序安装和管理sphinx。 它处理: 确保安装了狮身人面像 为您生成合理的sphinx.yml 用上帝管理和监视搜索 添加capistrano挂钩以重新启动部署时搜索 (可选)添加...
Rails_3_Cheat_Sheets.pdf
thinking-sphinx, activerecord/Rails的Sphinx插件 ThinkingThinking是将ActiveRecord连接到Sphinx完整文本搜索工具的库,并与 Rails ( 但也适用于其他 ruby 网络框架) 紧密集成。 当前版本为 v3.4.2.插件升级升级时...
复杂Rails系统架构优化
中文世界唯一一本Rails 4.0.0 + Ruby 2.0.0 的自學書籍
rails_apps_composer, 一个 gem,为 Rails 启动应用程序创建 Rails 应用程序模板 Rails 应用编辑器 Rails 应用程序编辑器 gem 安装一个 命令行 工具来从"食谱"的Collection 组装 Rails 应用程序。"你可以使用 rails_...
RestFul_Rails_Dev_v_0.1 RestFul_Rails_Dev_v_0.1
介绍插件,用于对记录进行排序(使用 gem)安装要启用rails_admin_acts_as_list,请将以下内容添加到您的Gemfile : gem 'rails_admin_acts_as_list'gem 'rails_admin' 重要提示: rails_admin_acts_as_list之前必须...
InspiniaAdmin 2.6.1 Rails_Full_Version
NULL 博文链接:https://zyn-zyn.iteye.com/blog/1163148
Api-rails5_api_tutorial.zip,了解如何在michael hartl的rails 5教程上构建一个现代api立即在rails应用程序中构建一个api!(Rails 5版本),一个api可以被认为是多个软件设备之间通信的指导手册。例如,api可用于web...
rails_semantic_logger, Rails 语义记录器用语义记录器替换 Rails 缺省记录器 Rails 语义记录器 语义记录器用语义记录器替代 Rails 缺省记录器。http://github.com/rocketjob/rails_semantic_logger文档有关完整文档...
agile_web_development_with_rails_3rd_edition.9994652073.pdf
Rails_Recipes_with_Source_Code
inspinia admin 2.5 中的 Rails_Full_Version
gem install ts-datetime-delta 在您的 Gemfile 中,您可以像这样使用它: gem 'ts-datetime-delta', '~> 2.0.1', :require => 'thinking_sphinx/deltas/datetime_delta' 或者,如果您仍在使用 Rails 2,请将其与...
ruby_on_rails_3_入门教程(中文)
RailsAdmin和CKEditor的图像管理器。 安装 将此行添加到您的应用程序的Gemfile中: gem 'rails_admin_image_manager' 跑步 $ bundle install 安装RailsAdmin_ImageManager $ rails generate rails_admin_image_...
Windows7_Cygwin_Git_RVM_Ruby1.9.3_Rails3_MongoD B_Nginx_Unicorn_Rspec_Guard_Spork(2-Ruby on Rails3 安装配置