我正在尝试设置我的 Sphinx3 搜索,我正在使用来自 分布。
source src
{
type = mysql
sql_host = localhost
sql_user = a0239779_a*
sql_pass = r*
sql_db = a0239779_r*
sql_port = 3306 # optional, default is 3306
sql_query = \
SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content \
FROM documents
sql_attr_uint = id
sql_attr_timestamp = date_added
}
index test1
{
source = src
path = /home/a0239779/sphinx/data/test1
}
index testrt
{
type = rt
rt_mem_limit = 128M
path = /home/a0239779/sphinx/data/testrt
rt_field = title
rt_field = content
rt_attr_uint = gid
}
indexer
{
mem_limit = 128M
}
searchd
{
listen = 9312
listen = 9306:mysql41
log = /home/a0239779/sphinx/log/searchd.log
query_log = /home/a0239779/sphinx/log/query.log
read_timeout = 5
max_children = 30
pid_file = /home/a0239779/sphinx/log/searchd.pid
seamless_rotate = 1
preopen_indexes = 1
unlink_old = 1
workers = threads # for RT to work
binlog_path = /home/a0239779/sphinx/data
}
我做了索引,好像还可以
[a0239779@jarl bin]$ indexer -c /home/a0239779/sphinx/etc/sphinx.conf --all
Sphinx 2.1.5-id64-release (rel21-r4508)
Copyright (c) 2001-2014, Andrew Aksyonoff
Copyright (c) 2008-2014, Sphinx Technologies Inc (http://sphinxsearch.com)
using config file '/home/a0239779/sphinx/etc/sphinx.conf'...
indexing index 'test1'...
WARNING: attribute 'id' not found - IGNORING
collected 4 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 4 docs, 227 bytes
total 0.013 sec, 17048 bytes/sec, 300.41 docs/sec
skipping non-plain index 'testrt'...
total 3 reads, 0.000 sec, 0.1 kb/call avg, 0.0 msec/call avg
total 10 writes, 0.000 sec, 0.1 kb/call avg, 0.0 msec/call avg
开始搜索了,好像还可以
[a0239779@jarl bin]$ ./sphinx.sh start
Sphinx 3.1.1 (commit 612d99f)
Copyright (c) 2001-2018, Andrew Aksyonoff
Copyright (c) 2008-2016, Sphinx Technologies Inc (http://sphinxsearch.com)
using config file '/home/a0239779/sphinx/etc/sphinx.conf'...
listening on all interfaces, port=9312
listening on all interfaces, port=9306
precaching index 'test1'
WARNING: index 'test1': prealloc: /home/a0239779/sphinx/data/test1.sph is
v.38 (from Sphinx 2.x), binary is v.48; NOT SERVING
precaching index 'testrt'
precached 2 indexes in 0.001 sec
我通过命令检查了搜索的工作,好吧
[a0239779@jarl bin\]$ search --config /home/a0239779/sphinx/etc/sphinx.conf 'another'
Sphinx 2.1.5-id64-release (rel21-r4508)
Copyright (c) 2001-2014, Andrew Aksyonoff
Copyright (c) 2008-2014, Sphinx Technologies Inc (http://sphinxsearch.com)
using config file '/home/a0239779/sphinx/etc/sphinx.conf'...
index 'test1': query 'another ': returned 1 matches of 1 total in 0.000 sec
displaying matches:
1. document=3, weight=2769, date_added=Sun Oct 11 19:25:17 2020
words:
1. 'another': 1 documents, 2 hits
index 'testrt': search error: failed to open /home/a0239779/sphinx/data/testrt.sph:
No such file or directory.
然后我想测试直接SQL查询
mysql -h127.0.0.1 -P9306
mysql> SELECT * FROM test1 WHERE MATCH('another');
ERROR 1064 (42000): no enabled local indexes to search
为什么会这样?
我也显示所有表格
mysql> SHOW TABLES;
+--------+------+
| index | type |
+--------+------+
| testrt | rt |
+--------+------+
1 row in set (0.00 sec)
为什么只有一张桌子?我的桌子“test1”在哪里
我正在尝试通过 PHP 进行测试
$db = new PDO("mysql:host=127.0.0.1; port=9306; dbname=a0239779_r--; charset=utf8;",
"a0239779_a--", "a0239779_r--");
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE);
$db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$stmt = $db->query("SELECT * FROM `test1` WHERE MATCH('another')");
$results = $stmt->fetchAll();
var_dump($results);
未捕获的 PDOException:SQLSTATE [42000]:语法错误或访问冲突:1064 未启用 要搜索的本地索引
是否应该有一个用于SQL查询的索引表test1?
如何使用 RT 表进行 SQL 查询?
索引器没有创建索引,因为老版本 2.1.5 是在没有可执行文件和配置的绝对路径的索引命令时启动的
search --config /home/a0239779/sphinx/etc/sphinx.conf 'another'
Sphinx 2.1.5-id64-release (rel21-r4508)
failed to open /home/a0239779/sphinx/data/testrt.sph:
No such file or directory.
您应该检查该目录是否具有写入权限(用户和组)。