CREATE TABLE vacancies
(
id BIGSERIAL PRIMARY KEY,
name TEXT,
description TEXT,
search_vector tsvector GENERATED ALWAYS AS (to_tsvector('russian', name || ' ' || description)) stored
);
CREATE INDEX vacancies_search_vector_idx ON vacancies USING gin(search_vector);
explain (analyze, timing off, summary off) SELECT * FROM vacancies WHERE search_vector @@ to_tsquery('russian', 'программист');
$users = User::query()->whereHas('keywords', function($query) use($vacancy){
return $query->whereIn('keyword', $vacancy->keywords->pluck('keyword'));
})->get();