我对Sphinx
感到困惑。我说的是这个问题。
我的系统配置:
Ubuntu 16.04 LTS
Apache 2.4.18
PHP 5.6.21
MariaDB 10.1.14
sphinx 2.2.10
我的数据库是test2
,它包含2个表(文档和用户)和1个视图(搜索)。
文件(表格):
用户(表):
fname
lname
搜索(查看):
sphinxid
itemid
datatype
搜索视图查询
CREATE
算法=未定义
DEFINER = root
@ localhost
SQL安全定义器
查看search
AS
选择
UUID_SHORT()AS sphinxid
,
users
。id
AS itemid
,
CONCAT_WS('',
users
。fname
,
users
。lname
,
users
。email
)AS data
,
1 AS datatype
从
users
UNION SELECT
UUID_SHORT()AS sphinxid
,
documents
。id
AS itemid
,
documents
。name
AS data
,
2 AS 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
),但是当我搜索它时(类似于&#39; Scarlet&#39;),我得不到结果:
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 rows!(users表有100行,documents表有90行)。
我使用本教程Integrating Sphinx Search into a PHP
Application,但我无法在我的应用程序中获得结果! :(
当我使用默认sphinx.conf
及其测试数据库时,我的应用程序正常工作。我认为我的sphinx.conf
错误或者可能是我的观点(搜索)造成的!
答案 0 :(得分:1)
查看您的查询
SELECT sphinxid,itemid, data, datatype \
FROM test2.search;
轮流拍摄
document_id
(第一列)uint attribute
(由于sql_attr_uint)uint attribute
(由于sql_attr_uint)field
。 但是,你的观点
... CONCAT_WS(' ', users.fname, users.lname, users.email) AS data,
1 AS datatype ...
看起来你的实际文本在'data'中,然后存储在整数属性中。不会工作!
:建议
sql_attr_uint = data
是一个错字,应该
sql_attr_uint = datatype
代替? (将数据留作文本字段索引!)