public similar ( string $string, integer $take = 15, string | null $instanceId = null ) : Illuminate\Database\Eloquent\Collection | static[] | ||
$string | string | partial of word |
$take | integer | take count |
$instanceId | string | null | instance id of taggable |
return | Illuminate\Database\Eloquent\Collection | static[] |
public function similar($string, $take = 15, $instanceId = null)
{
$model = $this->createModel();
$query = $model->newQuery()->where('decomposed', 'like', $this->decomposer->execute($string) . '%')->orderBy('count', 'desc')->take($take);
if ($instanceId) {
$query->where('instanceId', $instanceId);
}
return $query->get();
}
/** * 해시태그 suggestion 리스트 * * @param Request $request * @param TagHandler $tag * @return mixed */ public function hashTag(Request $request, TagHandler $tag) { $tags = $tag->similar($request->get('string')); $suggestions = []; foreach ($tags as $tag) { $suggestions[] = ['id' => $tag->id, 'word' => $tag->word]; } return XePresenter::makeApi($suggestions); }