我有一个 phone
表,其中包含 3 列,即 id、brand 和 model
。然后,我有另一个名为 my_devices
的表,其中包含我的特定设备列表,并且具有相同数量的相同名称的列。我使用 Sphinx 来匹配这两个表,即对于 my_devices 中的每个条目,为我提供电话表中相应的匹配项。
我的 php 代码是这样的:
<?php
$con = mysqli_connect("localhost", "root", "", "merge") or die("error connecting database".mysqli_error($con));
require_once('sphinxapi.php');
$s = new SphinxClient;
$s->setServer("127.0.0.1", 9312); // NOT "localhost" under Windows 7!
$s->setMatchMode(SPH_MATCH_EXTENDED2);
$s->SetLimits(0,10000);
$no=0;
$imi_model="A110";
$result = $s->Query($imi_model);
var_dump($result); echo "<pre>";
if ($result['total'] > 0) {
echo "****";
echo 'Total: ' . $result['total'] . "<br>\n";
echo 'Total Found: ' . $result['total_found'] . "<br>\n";
echo '<table>';
echo '<tr><td>No.</td><td>ID</td><td>brand</td><td>model</td></tr>';
foreach ($result['matches'] as $id => $otherStuff)
{
$row = mysqli_fetch_array(mysqli_query($con,"select * from pda where id = $id"));
// var_dump($row); exit;
extract($row);
++ $no;
echo "<tr><td>$no</td><td>$id</td><td>$brand</td><td>$model</td></tr>";
}
echo '</table>';
} else {
echo 'No results found';
}
?>
现在这段代码给出的输出如下:
No. ID brand model
1 50 Acer Acer Iconia Tab A110 16GB
2 51 Acer Acer Iconia Tab A110 8GB
3 2752 Micromax Micromax A110 Canvas 2
4 3508 Nokia Nokia X Dual SIM A110 (Nokia Normandy)
我的 sphinx 配置如下所示:
#
# Minimal Sphinx configuration sample (clean, simple, functional)
#
source sphinx_merge
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass =
sql_db = merge
sql_port = 3306 # optional, default is 3306
sql_query = \
SELECT id, brand, model \
FROM pda
sql_query_info = SELECT * FROM pda WHERE id=$id
}
index merge_indexing
{
source = sphinx_merge
path = c:\sphinx\data\test1
docinfo = extern
charset_type = sbcs
}
index testrt
{
type = rt
rt_mem_limit = 32M
path = c:\sphinx\data\testrt
charset_type = utf-8
rt_field = title
rt_field = content
rt_attr_uint = gid
}
indexer
{
mem_limit = 32M
}
searchd
{
listen = 9312
listen = 9306:mysql41
log = c:\sphinx\log\searchd.log
query_log = c:\sphinx\log\query.log
read_timeout = 5
max_children = 30
pid_file = c:\sphinx\log\searchd.pid
max_matches = 1000
seamless_rotate = 1
preopen_indexes = 1
unlink_old = 1
workers = threads # for RT to work
binlog_path = c:\sphinx\data
}
我有以下问题:
1 ) 我应该在查询中更改什么,以便可以获得特定品牌的结果,例如 acer 的 A110
。我应该在 php 或配置文件中的 sql 查询中将此更改放在哪里。
2) 如何删除 sphinx 中的 setLimit
。不过,我已将限制设置为一个非常大的值。但当我有一个巨大的数据集时,它可能会产生问题
最佳答案
1)使用@field限制运算符...
$result = $s->Query("@brand acer @model A110");
2) 您无法删除该限制。将始终受到 max_matches 的限制。但是将 max_matches 设置得很大会导致所有查询都很慢并且浪费内存。
关于php - 在 sphinx 中添加 where 条件以及如何删除 sphinx 中的 setlimit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25061311/