当前位置:网站首页>sphinx匹配指定字段
sphinx匹配指定字段
2022-08-05 08:34:00 【reg183】
为了缓解数据库的查询压力,把指定表的数据做成了sphinx索引,由于要查询的字段和别的字段值会有重复的,接下来吾爱编程为大家介绍一下sphinx精准查询的方法,有需要的小伙伴可以参考一下:
1、需求:
数据库中有一张表的数据已经200万条了,每次蜘蛛抓取的时候数据库的负载都会很高,sphinx常用来做搜索使用,而我需要做的是需要精准的去匹配到指定的内容,也就是把查询数据库的操作,转移到使用sphinx上面来进行操作。
由于数据表的ID和url字段的值会有重复的,所以想要做到精准查询显示结果,这里我们需要指定字段。
2、解决方法:
(1)、设置搜索模式:
$sphinx->SetMatchMode(SPH_MATCH_EXTENDED2);
(2)、设置指定的搜索字段:
$res_index = $sphinx->Query('@url ' . $url, 'itbiancheng'); //itbiancheng是我的索引,这里需要根据实际情况替换成自己的
3、验证结果:
[total] => 1
[total_found] => 1
[time] => 0.000
[words] => Array
(
[42891] => Array
(
[docs] => 2
[hits] => 2
)
)
这里虽然显示了命中的有两个,但是根据上面的我们设置的条件,结果中只会显示一条
4、SetMatchMode可选匹配模式:
| Constant | Description |
|---|---|
| SPH_MATCH_ALL | 匹配所有查询词(默认模式). |
| SPH_MATCH_ANY | 匹配查询词中的任意一个. |
| SPH_MATCH_PHRASE | 将整个查询看作一个词组,要求按顺序完整匹配. |
| SPH_MATCH_BOOLEAN | 将查询看作一个布尔表达式. |
| SPH_MATCH_EXTENDED | 将查询看作一个Sphinx内部查询语言的表达式. |
| SPH_MATCH_FULLSCAN | 使用完全扫描,忽略查询词汇. |
| SPH_MATCH_EXTENDED2 | 类似 SPH_MATCH_EXTENDED ,并支持评分和权重,扩展匹配模式允许使用一些像mysql的条件语句 |
边栏推荐
- How to replace colors in ps, self-study ps software photoshop2022, replace one color of a picture in ps with another color
- P1160 队列安排
- iptables实现网络限制下ntp自定义端口同步时间
- 路由----router
- Thinking after writing a code with a very high CPU usage
- 链表专项之环形链表
- unity urp 渲染管线顶点偏移的实现
- 基于多块信息提取和马氏距离的k近邻故障监测
- What is the connection and difference between software system testing and acceptance testing? Professional software testing solution recommendation
- 让硬盘更快,让系统更稳定
猜你喜欢

D2--FPGA SPI interface communication2022-08-03

TensorFlow安装步骤

Redis缓存以及存在的问题--缓存穿透、缓存雪崩、缓存击穿及解决方法

uniapp time component encapsulates year-month-day-hour-minute-second

How to make pictures clear in ps, self-study ps software photoshop2022, simple and fast use ps to make photos clearer and more textured

Redis cache and existing problems--cache penetration, cache avalanche, cache breakdown and solutions

php向mysql写入数据失败

复现一次循环和两次循环

v-if/v-else根据计算判断是否显示

Spark cluster deployment (third bullet)
随机推荐
“充钱”也难治快手的“亏亏亏”?
nn.unfold和nn.fold
pnpm 是凭什么对 npm 和 yarn 降维打击的
iptables实现网络限制下ntp自定义端口同步时间
Controller-----controller
工程制图试题
What is a good movie to watch on Qixi Festival?Crawl movie ratings and save to csv file
SVG big fish eat small fish animation js special effects
SVG大鱼吃小鱼动画js特效
微信小程序请求封装
七夕给自己new一个chatRobot当对象
Thinking after writing a code with a very high CPU usage
SQL SERVER关于主从表触发器设计
The toss of MM before going to the street (interesting)
Ethernet Principle
NC20164 :最大数MAXNUMBER [线段树]
Chapter 12 Bayesian Networks
How to make pictures clear in ps, self-study ps software photoshop2022, simple and fast use ps to make photos clearer and more textured
MySQL 数据库 报错 The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid)
嵌入式系统:基本定时器