Skip to content

Instantly share code, notes, and snippets.

@phanngoc
Created September 1, 2018 11:36
Show Gist options
  • Save phanngoc/78bafa244462b9ecf63d391046d6f2b8 to your computer and use it in GitHub Desktop.
Save phanngoc/78bafa244462b9ecf63d391046d6f2b8 to your computer and use it in GitHub Desktop.
public function findMatching($threadId, $text = '', $lastMessageId = 0, $comparison = '<', $limit = 3)
{
if ($lastMessageId == 0) {
$lastMessageId = $this->message->max('id') + 1;
}
$querySeri = [
[
'match' => [
'message' => $text,
],
],
];
$filters = [
['term' => ['thread_id' => $threadId]],
];
if ($comparison == '<') {
$sorts = ['id' => ['order' => 'desc']];
} else {
$sorts = ['id' => ['order' => 'asc']];
}
$params = [
'index' => 'message',
'type' => 'message_search',
'body' => [
'query' => [
'bool' => [
'should' => $querySeri,
'filter' => $filters,
'minimum_should_match' => 1,
],
],
'sort' => $sorts,
'search_after' => [$lastMessageId],
'size' => $limit,
],
];
$response = SearchService::init()->search($params);
return $response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment