sphinx的简单实例
sphinx.conf中的配置:
source indexLocation
{
type = mysql sql_host = 192.168.1.113
sql_user = root
sql_pass = redidai@@2013
sql_db = redidai
sql_port = 3306 # optional, default is 3306 sql_query_pre = SET NAMES utf8
sql_query_pre = SET SESSION query_cache_type=OFF sql_query = \
SELECT a.location_id as id,a.location_id,a.location_name as `location_name`,a.location_name as `name`,a.location_bname,a.attach_id,a.showstatus,a.is_del,a.status,b.area_name as city_name FROM `ts_rdd_location` a LEFT JOIN `ts_rdd_area` b ON a.city_id = b.area_id
#sql_attr_string = name
sql_attr_uint = status
#sql_attr_timestamp = date_added
sql_query_info = SELECT * FROM `ts_rdd_location` WHERE location_id = $id
} index indexLocation
{
source = indexLocation
path = /var/lib/sphinx/test1
docinfo = extern
mlock = 0 #缓存数据内存锁定
morphology = none #形态学(对中文无效)
min_word_len = 2 #索引的词最小长度
charset_type = utf-8
min_prefix_len = 0 #最小前缀
html_strip = 1
ngram_len = 1 #对于非字母型数据的长度切割
ngram_chars = U+3000..U+2FA1F #则会对每个中文,英文字词进行分割,速度会慢 #字符表,注意:如使用这种方式,则sphinx会对中文进行单字切分,即进行字索引。
#若要使用中文分词,必须使用其他分词插件如 coreseek,sfc
charset_table = 0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F
} indexer
{
mem_limit = 32M
} searchd
{
listen = 9312
#listen = 9306:mysql41
log = /var/log/sphinx/searchd.log
query_log = /var/log/sphinx/query.log
read_timeout = 5
max_children = 30
pid_file = /var/run/sphinx/searchd.pid
max_matches = 1000
seamless_rotate = 1
preopen_indexes = 1
unlink_old = 1
compat_sphinxql_magics = 0
#workers = threads # for RT to work
binlog_path = /var/lib/sphinx
}
php代码:
<?php
class SearchAction extends AdministratorAction { public $sphinxClient = null; public function __construct() {
parent::__construct(); require_once SITE_PATH . '/sphinxapi.php'; if ($this->sphinxClient == null) {
$this->sphinxClient = new SphinxClient ();
} $this->sphinxClient->SetServer('192.168.0.0', 9312);
$this->sphinxClient->open();
} public function QLocation($params = array()) {
$searchWord = ''; if (isset($params['keyword'])) {
$searchWord = $params['keyword'];
} $result = $this->suggestHandle($this->sphinxClient, $searchWord); $nodeResult = array(); if ($result['total'] > 0) {
$matches = array(); foreach($result['matches'] as $mvale) {
$matches[] = $mvale['id'];
} $matches_id = implode(",", $matches); $locationModel = D('RddLocation', 'admin');
$list = $locationModel->getLocationListByID($matches_id);
$nodeResult = $list;
} print_r($nodeResult);exit; return $nodeResult;
} public function suggestHandle($spx, $searchWord = ''){
//$spx->SetSortMode(SPH_SORT_EXTENDED, "@weight DESC, larea DESC, is_recommend DESC, like_count DESC");
$spx->SetSortMode(SPH_SORT_EXTENDED, "@weight DESC");
$spx->ResetFilters();
//$cityId = filter_input(INPUT_GET, 'area', FILTER_SANITIZE_STRING);
//$spx->SetFilter('showstatus', array('Y'));
//$spx->SetFilter('is_del', array('0'));
$spx->SetFilter('status', array(1));
//$result = $spx->Query($searchWord, 'plan14_location,delta_plan14_location');
$spx->SetArrayResult(true);
$result = $spx->Query($searchWord, 'indexLocation');
//var_dump($spx);
return $result;
} }
调用:
$searchAction = new SearchAction();
$list = $searchAction->QLocation(array('keyword' => $name));
sphinx的简单实例的更多相关文章
- Hibernate(二)__简单实例入门
首先我们进一步理解什么是对象关系映射模型? 它将对数据库中数据的处理转化为对对象的处理.如下图所示: 入门简单实例: hiberante 可以用在 j2se 项目,也可以用在 j2ee (web项目中 ...
- 最新 Eclipse IDE下的Spring框架配置及简单实例
前段时间开始着手学习Spring框架,又是买书又是看视频找教程的,可是鲜有介绍如何配置Spring+Eclipse的方法,现在将我的成功经验分享给大家. 本文的一些源代码来源于码农教程:http:// ...
- 修改js confirm alert 提示框文字的简单实例
修改js confirm alert 提示框文字的简单实例: <!DOCTYPE html> <html> <head lang="en"> & ...
- 利用navicat创建存储过程、触发器和使用游标的简单实例
利用navicat创建存储过程.触发器和使用游标的简单实例 标签: navicat存储过程触发器mysql游标 2013-08-03 21:34 15516人阅读 评论(1) 收藏 举报 分类: 数 ...
- 【转】Android Https服务器端和客户端简单实例
转载地址:http://blog.csdn.net/gf771115/article/details/7827233 AndroidHttps服务器端和客户端简单实例 工具介绍 Eclipse3.7 ...
- Centos7的安装、Docker1.12.3的安装,以及Docker Swarm集群的简单实例
目录 [TOC] 1.环境准备 本文中的案例会有四台机器,他们的Host和IP地址如下 c1 -> 10.0.0.31 c2 -> 10.0.0.32 c3 -> 10.0.0. ...
- vue路由的简单实例
vue2.0 和 vue1.0 路由的语法还是有点稍微的差别,下面介绍一下vue-router 2的简单实例: <!DOCTYPE html> <html lang="en ...
- Flume概述和简单实例
Flume概述 Flume是一个分布式.可靠.和高可用的海量日志采集.聚合和传输的系统.支持在日志系统中定制各类数据发送方,用于收集数据;同时,Flume提供对数据进行简单处理,并写到各种数据接受方( ...
- jsoup解析HTML及简单实例
jsoup 中文参考文献 http://www.open-open.com/jsoup/ 本文将利用jsoup,简单实现网络抓取的功能,并给出一个小实例,该实例效果为:获取作者本人在博客园写的所 ...
随机推荐
- ASP.NET中的FileUpload文件上传控件的使用
本篇文章教大家如何将客户端的图片或者文件上传到服务器: 无论是上传图片(.jpg .png .gif等等) 文档(word excel ppt 等等). 第一步:放入以下三个控件 Image控件,Fi ...
- 【原】android通过adb wireless的使用
开发android程序,总是需要插拔插拔的,usb口都给弄坏掉了,现在adb可以通过无线网,链接处在同一个局域网下面的android设备 1.将电脑和移动设备链接到同一个无线网下 2.在android ...
- We need the sql script to query the table Ditronics.Kiosk.Journal to find journal with mismatch denom information versus amount.
CREATE TABLE #MoneyTable ( Id , ) PRIMARY KEY , MoneyName ) , Cents INT ) INSERT INTO #MoneyTable ( ...
- 中文Win7下成功安装calabash-android步骤
Calabash-android是支持android的UI自动化测试框架,网上看见很多同学说,安装calabash比较费劲,特别是Windows下安装,也没有一个详细的安装手册可供参考.正好,今天在W ...
- SQL Server: Difference Between Locking, Blocking and Dead Locking
Like ever, today’s article of Pinal Dave was interesting and informative. After, our mutual discussi ...
- 系统虚拟化学习笔记——PCI设备
内容摘自<系统虚拟化:原理与实现> PCI 总线架构 PCI总线是典型的树结构.把北桥中host-PCI桥看做根,总线中其他PCI-PCI桥,PCI-ISA桥(ISA总线转PCI总线桥)等 ...
- POJ 2429
思路:a/n*b/n=lcm/gcd 所以这道题就是分解ans.dfs枚举每种素数情况.套Miller_Rabin和pollard_rho模板 //#pragma comment(linker, &q ...
- 相当管用了 mstha插件
http://www.i-magical.com/2010/04/feizhuliu-kill-virus-mshta-exe/ 非主流杀毒 – mshta.exe Vincent | Apr 23, ...
- 异常(Exception)
1.Java中所有的异常类都会直接或间接地继承自Exception. 2.RuntimeException类也是直接继承自Exception类,它叫做运行时异常,Java中所有的运行时异常都会直接或间 ...
- Bzoj-2190 仪仗队 欧拉函数
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2190 简单的欧拉函数题,实际上就是求gcd(x,y)=1, 0<=x,y<=n ...