Answer the question
In order to leave comments, you need to log in
Sphinx - how to use strict search with expressions?
Hello. There is Sphinx as a PHP module. The task is essentially simple, but I can not find a suitable solution in any way.
MySQL has a table like id | user_id | title. Sphinx indexes this and searches for user_id + title.
The title field can be of the form abc | abc:xyz i.e. either just a string or a string with a colon.
It is necessary to make a suggest-search, i.e. the entire search of the form query*.
There are two search options:
1. Find a string that starts with the query text.
2. Find the line in which the query text follows the colon.
At the moment, the search is carried out as follows:
$sphinx = Service::sphinx(); // Здесь происходит подключение клиента к серверу
$sphinx->SetMatchMode( SPH_MATCH_EXTENDED ); // Устанавливается режим совпадения
$sphinx->setFilter('user_id', [$this->id]); // Устанавливается фильтр по user_id
// Собственно сам запрос
if ($part == 'second') {
$results = $sphinx->query(':'.$text.'*', 'index');
} else {
$results = $sphinx->query('^'.$text.'*', 'index');
}
source index
{
type = mysql
sql_host = ...
sql_user = ...
sql_pass = ...
sql_db = ...
sql_port = 3306
sql_query_pre = SET NAMES utf8
sql_query = \
SELECT \
id, user_id, title \
FROM \
table
sql_field_string = title
sql_attr_uint = user_id
sql_query_pre = SET NAMES utf8
sql_query_pre = SET SESSION query_cache_type=OFF
sql_query_info = SELECT * FROM table WHERE id=$id
}
index index
{
source = index
path = /var/lib/sphinxsearch/data/index
docinfo = extern
charset_type = utf-8
mlock = 0
index_exact_words = 1
min_word_len = 1
enable_star = 1
prefix_fields = title
min_prefix_len = 1
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question