【发布时间】:2016-05-23 23:45:32
【问题描述】:
我对@987654324@ 感到困惑。我说一下问题。
我的系统配置:
Ubuntu 16.04 LTSApache 2.4.18-
PHP 5.6.21 MariaDB 10.1.14sphinx 2.2.10
我的数据库是 test2,它包含 2 个表(文档和用户)和 1 个视图(搜索)。
-
文件(表格):
- 身份证
- 姓名
-
用户(表):
- 身份证
-
fname lname- 电子邮件
-
搜索(查看):
sphinxiditemid- 数据
datatype
搜索视图查询是
创建
算法 = 未定义
定义者 = root@localhost
SQL 安全定义器
查看search AS
选择
UUID_SHORT() 作为sphinxid,
users.id AS itemid,
CONCAT_WS(' ',
users.fname,
users.lname,
users.email) 如data,
1 作为datatype
从
users
联合选择
UUID_SHORT() 作为sphinxid,
documents.id AS itemid,
documents.name AS data,
2 作为datatype
从
documents
Sphinx 配置文件:
source my_search
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass = myPass
sql_db = test2
sql_port = 3306 # optional, default is 3306
sql_query = \
SELECT sphinxid,itemid, data, datatype \
FROM test2.search;
sql_attr_uint = itemid
sql_attr_uint = data
}
index test1
{
source = my_search
path = /var/lib/sphinxsearch/data/test1
morphology = stem_en
min_word_len = 3
# min_prefix_len = 0
# enable_star = 0
}
searchd
{
listen = 9312
listen = 9306:mysql41
log = /var/log/sphinxsearch/searchd.log
query_log = /var/log/sphinxsearch/query.log
read_timeout = 5
max_children = 30
pid_file = /var/run/sphinxsearch/searchd.pid
# max_matches = 1000
seamless_rotate = 1
preopen_indexes = 1
unlink_old = 1
workers = threads # for RT to work
binlog_path = /var/lib/sphinxsearch
}
我使用此命令创建索引 indexer --config /etc/sphinxsearch/sphinx.conf --all --rotate 。结果是:
Sphinx 2.2.10-id64-release (2c212e0)
Copyright (c) 2001-2015, Andrew Aksyonoff
Copyright (c) 2008-2015, Sphinx Technologies Inc (http://sphinxsearch.com)
using config file '/etc/sphinxsearch/sphinx.conf'...
indexing index 'test1'...
collected 200 docs, 0.0 MB
total 200 docs, 200 bytes
total 0.007 sec, 28417 bytes/sec, 28417.16 docs/sec
total 2 reads, 0.000 sec, 1.5 kb/call avg, 0.0 msec/call avg
total 10 writes, 0.000 sec, 0.6 kb/call avg, 0.0 msec/call avg
rotating indices: successfully sent SIGHUP to searchd (pid=2287).
我使用sphinxapi.php 作为客户端api,我的php 测试文件是:
<?php
include '../sphinxapi.php';
if(!empty($_GET['q'])){
var_dump($_GET['q']);
// Build search query
$cl = new SphinxClient();
$cl->SetServer( "localhost", 9312 );
$cl->SetMatchMode( SPH_MATCH_EXTENDED );
$cl->SetRankingMode ( SPH_RANK_SPH04 );
// Execute the query
$q = '"' . $cl->EscapeString($_GET['q']) . '"/1';
$searchresults = $cl->Query($q ,'test1');
var_dump($cl->GetLastError());
var_dump($cl->GetLastWarning());
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Sphinx test 1</title>
</head>
<body>
<form name="search" method="get" action="">
<input type="text" name="q" id="q" />
<input type="submit" value="GO" class="form-submit" />
</form>
<p>
<pre>
<?php
if(!empty($searchresults)){
print_r($searchresults);
}
?>
</pre>
</p>
</body>
</html>
我查看 search view 并选择了一个字段 (Scarlett Downsit.fermentum@sapienimperdiet.com),但是当我搜索它时(类似于“Scarlet”),我没有得到任何结果:
Array
(
[error] =>
[warning] =>
[status] => 0
[fields] => Array
(
[0] => datatype
)
[attrs] => Array
(
[itemid] => 1
[data] => 1
)
[total] => 0
[total_found] => 0
[time] => 0.000
[words] => Array
(
[scarlet] => Array
(
[docs] => 0
[hits] => 0
)
)
)
真的不知道什么都不返回的原因吗?
我根据sphinx教程使用这个命令mysql -h0 -P9306。你可以在图片中看到我没有任何数据(你可以在sphinx.conf看到我的查询)它返回20行!(用户表有100 行,文档表有 90 行)。
我使用本教程Integrating Sphinx Search into a PHP Application,但我无法在我的应用程序中获得结果! :(
当我使用默认的sphinx.conf 及其测试数据库时,我的应用程序可以工作。我认为我的sphinx.conf 是错误的,或者可能是我的视图(搜索)引起的!
【问题讨论】:
标签: php search-engine sphinx mariadb