Created
September 1, 2018 11:36
-
-
Save phanngoc/78bafa244462b9ecf63d391046d6f2b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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