Здравствуйте, никак не могу заставить работать сфинкс на минимальной конфигурации
Версия 3, конфиг взял из дистрибутива, стандартный файл, чтобы исключить косяки с неверными настройками
Код конфига# Minimal Sphinx configuration sample (clean, simple, functional)
source src1
{
type = mysql
sql_host = localhost
sql_user = a0239779_a*****
sql_pass = r********
sql_db = a0239779_m****
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 = group_id
sql_attr_timestamp = date_added
}
index test1
{
source = src1
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]$ ./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: failed to open /home/a0239779/sphinx/data/test1.sph:
No such file or directory; NOT SERVING
precaching index 'testrt'
precached 2 indexes in 0.001 sec
Индексация
[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'...
collected 4 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 4 docs, 193 bytes
total 0.010 sec, 19141 bytes/sec, 396.70 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
Проверка поиска
search --config /home/a0239779/sphinx/etc/sphinx.conf 'another' Всё находит корректно.
[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, group_id=2, date_added=Sat Nov 26 20:27:31 2022
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.
Подключаюсь через
mysql -h127.0.0.1 -P9306
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 3.1.1 (commit 612d99f)
Copyright (c) 2009-2022 Percona LLC and/or its affiliates
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> SHOW TABLES;
+--------+------+
| Index | Type |
+--------+------+
| testrt | rt |
+--------+------+
1 row in set (0,00 sec)
Команда на показ таблиц. Ведь здесь должно быть 2 таблицы? Rt и test1 или нет? Показывает только Rt
Делаю запрос через консоль мускула.
SELECT * FROM test1 WHERE MATCH('another');
Не срабатывает. Как я понял не видит индексов test1
mysql> SELECT * FROM test1 WHERE MATCH('another');
ERROR 1064 (42000): no enabled local indexes to search
Теперь через PHP на сервере, сделал несколько разных вариантов
1. Скрипт через PDO
$options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8');
$db=new PDO("mysql:host=127.0.0.1;port=9306;dbname=a0239779_m*;charset=utf8;","a0239779_*","r*",$options);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE);
$db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$stmt = $db->query("SELECT `id` FROM `test1` WHERE MATCH('another')");
$results = $stmt->fetchAll();
var_dump($results);
Подключение есть, порты указаны верные.
Результат:
Не видит индексов тест1
<b>Fatal error</b>: Uncaught PDOException: SQLSTATE[42000]:
Syntax error or access violation: 1064 no enabled local indexes to search in /home/a0239779/domains/m*:57
Stack trace:
#0 /home/a0239779/domains/m*/public_html/sp1.php(57): PDO->query('SELECT `id` FRO...')
Взял готовые скрипты из дистрибутива
require ( "sphinxapi.php" );
$docs = array
(
"this is my test text to be highlighted,
and for the sake of the testing we need to pump its length somewhat",
"another test text to be highlighted, below limit",
"test number three, without phrase match",
"final test, not only without phrase match,
but also above limit and with swapped phrase text test as well",
);
$words = "another";
$index = "test1";
$opts = array
(
"before_match" => "<b>",
"after_match" => "</b>",
"chunk_separator" => " ... ",
"limit" => 60,
"around" => 3,
);
foreach ( array(0,1) as $exact )
{
$opts["exact_phrase"] = $exact;
print "exact_phrase=$exact\n";
$cl = new SphinxClient ();
$res = $cl->BuildExcerpts ( $docs, $index, $words, $opts );
if ( !$res )
{
die ( "ERROR: " . $cl->GetLastError() . ".\n" );
} else
{
$n = 0;
foreach ( $res as $entry )
{
$n++;
print "n=$n, res=$entry\n";
}
print "\n";
}
}
Результат:
exact_phrase=0 ERROR: searchd error: unknown local index 'test1' in search request.
Также, нету индексов таблицы test1, а testrt есть
Не могу понять что не так, пробовал 3 разных версии сфинкса, менял порты, ничего не помогает