当前位置:网站首页>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 situation3. 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 result4. 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 |
边栏推荐
猜你喜欢
随机推荐
Ethernet Principle
[Untitled] Long-term recruitment of hardware engineers-Shenzhen Baoan
[Structural Internal Power Cultivation] Structural Realization Stages (2)
mySQL数据库初始化失败,有谁可以指导一下吗
Redis实现分布式锁-原理-问题详解
Redis implements distributed lock-principle-detailed explanation of the problem
手机上流行的各类谜语
七夕给自己new一个chatRobot当对象
Why is pnpm hitting npm and yarn dimensionality reduction?
CROS和JSONP配置
Long-term recruitment embedded development-Shenzhen Baoan
写出了一个CPU占用极高的代码后引发的思考
程序设计中的感悟
Spark cluster deployment (third bullet)
全面讲解GET 和 POST请求的本质区别是什么?原来我一直理解错了
What is a good movie to watch on Qixi Festival?Crawl movie ratings and save to csv file
The color of life divine
【结构体内功修炼】结构体实现位段(二)
动态库之间回调函数使用
让程序员崩溃的N个瞬间(非程序员误入)









