$contry_data = array (
'Украина' => array ( 'population' => 46, 'capital' => 'Киев' ),
'Нидерланды' => array ( 'population' => 17.02, 'capital' => 'Амстердам' ),
'Норвегия' => array ( 'population' => 5.233, 'capital' => 'Осло' ),
);
foreach ($contry_data as $country_name =>$country) {
echo "$country_name, {$country['population']} млн., {$country['capital']}";
}
source contacts
{
type = mysql
sql_host = localhost
sql_user = export_user
sql_pass = Y1q0P2s8
sql_db = sales_db
sql_port = 3306
sql_query_pre = SET NAMES utf8
sql_query_pre = SET CHARACTER SET utf8
sql_query = SELECT * FROM contacts WHERE CHAR_LENGTH(name)>4
sql_attr_string = name
}
index contacts
{
source = contacts
path = /var/lib/sphinxsearch/data/contacts
docinfo = extern
mlock = 0
morphology = soundex, metaphone
charset_table = 0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F
}
searchd
{
listen = 9312
log = /var/lib/sphinxsearch/log.log
query_log = /var/lib/sphinxsearch/query.log
read_timeout = 5
max_children = 30
pid_file = /var/run/sphinxsearch/searchd.pid
seamless_rotate = 1
preopen_indexes = 1
unlink_old = 1
workers = threads # for RT to work
binlog_path = /var/lib/sphinxsearch/data
}
require_once "sphinxapi.php";
$name = "Виктор Рядых";
$sphinx = new SphinxClient();
$sphinx->SetServer('localhost', 9312);
$sphinx->SetMatchMode(SPH_MATCH_ANY);
$sphinx->SetSortMode(SPH_SORT_RELEVANCE);
$result = $sphinx->query($name, "*");
if($result === false){
var_dump($sphinx->GetLastError());
}else{
var_dump($result);
}
{
"error": "",
"warning": "",
"status": 0,
"fields": [
"updated_at",
"created_at",
"created_by",
"responsible_user_id",
"company",
"tags"
],
"attrs": {
"name": 7
},
"total": "0",
"total_found": "0",
"time": "0.000",
"words": {
"виктор": {
"docs": "0",
"hits": "0"
},
"рядых": {
"docs": "0",
"hits": "0"
}
}
}
Создать для него конфиг, который будет работать с БД, указать в конфиге что sphinxsearch должен индексировать.
#
# Minimal Sphinx configuration sample (clean, simple, functional)
#
source contacts
{
type = mysql
sql_host = localhost
sql_user = user
sql_pass = password
sql_db = sales_db
sql_port = 3306
sql_query_pre = SET NAMES utf8
sql_query = SELECT * FROM contacts
sql_attr_uint = id
sql_attr_string = name
}
index contacts
{
source = contacts
path = /var/lib/sphinxsearch/data/contacts
morphology = stem_ru
min_word_len = 1
}
searchd
{
listen = 9312
log = /var/lib/sphinxsearch/log.log
query_log = /var/lib/sphinxsearch/query.log
read_timeout = 5
max_children = 30
pid_file = /var/run/sphinxsearch/searchd.pid
seamless_rotate = 1
preopen_indexes = 1
unlink_old = 1
workers = threads # for RT to work
binlog_path = /var/lib/sphinxsearch/data
}
read()
.