Есть запрос к Sphinx, в ответе получаем массив со строками и Snippets, с выделенными словами в теге <b>%s</b>:
Код: Выделить всё
$data = $query->from('test')
->snippetCallback(
function ($rows) {
$result = [];
foreach ($rows as $row) {
$text = SearchText::find()->where(['id' => $row['id']])->one();
$result[] = $text->full_text;
}
return $result;
}
)
->snippetOptions(['before_match' => '<b>', 'after_match' => '</b>'])
->match($query_string])
->all();
Код: Выделить всё
$data = $query->from('test')
->snippetCallback(
function ($rows) {
$result = [];
foreach ($rows as $row) {
$text = SearchText::find()->where(['id' => $row['id']])->one();
$result[] = $text->full_text;
}
return $result;
}
)
->snippetOptions(['before_match' => '<b>', 'after_match' => '</b>'])
->match(new Expression(':match', ['match' => '@(full_text) ' . $query_string]))
->all();