rails3 和 thinking_sphinx安装(brown_zhang)
来源:互联网 发布:淘宝购物比价软件 编辑:程序博客网 时间:2024/06/05 08:12
可以到http://zyn-zyn.iteye.com/blog/1218791网站下载所需插件
1.安装thinking-sphinx,在Gemfile中添加下面代码:
gem 'thinking-sphinx'
再运行bundle,就自动安装thinking-sphinx;或者下载gem包安装
2.把sphinx插件放到vendor/plugins目录下,再Gemfile文件中添加
require 'sphinx'
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 ##停服务
问题
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'
- rails3 和 thinking_sphinx安装(brown_zhang)
- 安装使用railscasts(Rails3)
- 安装使用railscasts(Rails3)
- Rails3.0.3安装Will_paginate和使用(简单示例)(补充样式)
- windows 下ruby1.9.2、Rails3.0.9安装和配置
- Linux下安装ruby1.9.3和rails3.1
- rails3 mysql2安装
- rails3.1simple_captcha安装
- windows7 rails3.1下Rmagick安装(brown)
- rails3学习系列(一)环境安装---缺少包引入
- rails3 环境下安装rmagick
- linecache19在rails3中的安装
- rails3中安装Foundation 4
- fedora15 配置rails3 和mysql
- Rails3处理css和js
- Rails3教程系列之二:Rails3入门(2)
- Rails3教程系列之三:Rails3入门(3)
- Rails3教程系列之四:Rails3入门(4)
- H264/AVC Profile and Level 简介 转自:http://blog.csdn.net/wanggp_2007/article/details/4863573
- 百度Android开发面试题
- MTK——TASK创建及使用
- 在ubuntu下安装sphinx-chinese 用于xml
- hadoop mapred(hive)执行目录 文件权限问题
- rails3 和 thinking_sphinx安装(brown_zhang)
- 如何学VC++?
- 简单命令回顾
- 插件46:简单的web代理服务器
- reids按天分割日志
- hive cli命令行选项
- Jquery调用webservices(各种返回值)
- select、poll与epoll的区别
- 安装pig时遇到的问题