当前位置:网站首页>sphinx matches the specified field
sphinx matches the specified field
2022-08-05 08:39:00 【reg183】
In order to relieve the query pressure of the database, the data of the specified table is made into a sphinx index. Since the value of the field to be queried and other field values will be repeated, then I love programming to introduce the method of sphinx accurate query., friends in need can refer to:
1. Requirements:
There is a table in the database with 2 million pieces of data. Every time the spider crawls, the load of the database will be very high. Sphinx is often used for searching, and what I need to do isIt is necessary to accurately match the specified content, that is, to transfer the operation of querying the database to the use of sphinx.
Because the values of the ID and url fields of the data table will be repeated, we need to specify the fields here to achieve accurate query and display results.
2. Solution:
(1), Set the search mode:
$sphinx->SetMatchMode(SPH_MATCH_EXTENDED2);
(2), set the specified search field:
$res_index = $sphinx->Query('@url' . $url, 'itbiancheng'); //itbiancheng is my index, here you need to replace it with your own according to the actual situation
3. Verification result:
[total] => 1[total_found] => 1[time] => 0.000[words] => Array([42891] => Array([docs] => 2[hits] => 2))
Although there are two hits shown here, according to the conditions we set above, only one will be displayed in the result
4. SetMatchMode optional matching mode:
Constant | Description |
---|---|
SPH_MATCH_ALL | Matches all query terms (default pattern). |
SPH_MATCH_ANY | Matches any of the query terms. |
SPH_MATCH_PHRASE | Consider the entire query as a phrase, requiring complete matches in order. |
SPH_MATCH_BOOLEAN | Consider the query as a boolean expression. |
SPH_MATCH_EXTENDED | Consider the query as an expression in Sphinx's internal query language. |
SPH_MATCH_FULLSCAN | Use full scan, ignoring query terms. |
SPH_MATCH_EXTENDED2 | Similar to SPH_MATCH_EXTENDED and supports scoring and weighting, the extended match mode allows the use of some conditional statements like mysql |
边栏推荐
猜你喜欢
代码审计—PHP
[Structural Internal Power Cultivation] The Mystery of Enumeration and Union (3)
数据源对象管理Druid和c3p0
Chapter 12 贝叶斯网络
链表专项之环形链表
Pagoda measurement - building small and medium-sized homestay hotel management source code
EA谈单机游戏:仍是产品组合中极其重要的部分
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)
D2--FPGA SPI接口通信2022-08-03
随机推荐
Adb authorization process analysis
动态内存开辟(C语言)
执子之手,与子偕老。你同意么?
Luogu P1966: [NOIP2013 提高组] 火柴排队 [树状数组+逆序对]
撕裂寂寞
Jmeter永久设置中文界面
[Repost] Marry a man must marry a man whose salary is at least 3571.4 yuan higher than yours
【每日一题】1403. 非递增顺序的最小子序列
Adb 授权过程分析
写出了一个CPU占用极高的代码后引发的思考
十一道家常小菜详细攻略[图文并茂]
SQL SERVER关于主从表触发器设计
生命的颜色占卜
spark集群部署(第三弹)
How to replace colors in ps, self-study ps software photoshop2022, replace one color of a picture in ps with another color
基因数据平台
Linux导出数据库数据到硬盘
代码审计—PHP
基于多块信息提取和马氏距离的k近邻故障监测
彩绘漂亮MM集