当前位置:网站首页>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的条件语句 |
边栏推荐
- 宝塔实测-搭建中小型民宿酒店管理源码
- php fails to write data to mysql
- 8.4 Summary of the mock competition
- Version number naming convention
- Pagoda measurement - building small and medium-sized homestay hotel management source code
- 执子之手,与子偕老。你同意么?
- Beautifully painted MM set
- How Entrepreneurs Attract Venture Capitalists
- uniapp time component encapsulates year-month-day-hour-minute-second
- Jmeter永久设置中文界面
猜你喜欢

MySQL database error The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid)

【结构体内功修炼】结构体内存对齐(一)

TensorFlow installation steps

Spark cluster deployment (third bullet)

SVG大鱼吃小鱼动画js特效
![[Structural Internal Power Cultivation] The Mystery of Enumeration and Union (3)](/img/39/d20f45ccc86ebc4e5aebc8e4d0115f.png)
[Structural Internal Power Cultivation] The Mystery of Enumeration and Union (3)

sql server收缩日志的作业和记录,失败就是因为和备份冲突了吗?

Detailed explanation of DNS query principle

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

mySQL数据库初始化失败,有谁可以指导一下吗
随机推荐
支持触屏slider轮播插件
TensorFlow安装步骤
七夕给自己new一个chatRobot当对象
egg framework
最 Cool 的 Kubernetes 网络方案 Cilium 入门教程
CROS and JSONP configuration
Data source object management Druid and c3p0
Nn. Unfold and nn. The fold
D2--FPGA SPI interface communication2022-08-03
The magic weapon for small entrepreneurs!
D2--FPGA SPI接口通信2022-08-03
Stored procedure writing experience and optimization measures
iptables实现网络限制下ntp自定义端口同步时间
浅谈自动采集程序及入库
Redis缓存以及存在的问题--缓存穿透、缓存雪崩、缓存击穿及解决方法
复现一次循环和两次循环
【无标题】目录
SVG星球大战样式Toggle切换开关按钮
好资料汇总
What is a good movie to watch on Qixi Festival?Crawl movie ratings and save to csv file