-
Notifications
You must be signed in to change notification settings - Fork 372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
associated_against with tsvector_column #359
Comments
This is currently a missing feature. The |
@nertzy Any more thoughts about this? I would like to improve performance when searching against other models (also adding |
And to clarify, by SQL-only, I mean we can drop the |
I did end up going this route and just using CREATE OR REPLACE FUNCTION update_users_tsv() RETURNS trigger AS $$
BEGIN
NEW.tsv := (
SELECT
setweight(to_tsvector('simple', CONCAT(NEW.first_name, ' ', NEW.last_name)), 'A') ||
setweight(to_tsvector('english', array_to_string(array_agg(DISTINCT skills.name), ' ')), 'B') ||
setweight(to_tsvector('simple', array_to_string(array_agg(DISTINCT cv_entries.client_name), ' ')), 'B') ||
setweight(to_tsvector('english', array_to_string(array_agg(DISTINCT CONCAT(cv_entries.short_description, ' ', cv_entries.description)), ' ')), 'C')
FROM users u
LEFT JOIN skill_assignments sa ON sa.skillable_id = u.id AND sa.skillable_type = 'User'
LEFT JOIN skills ON skills.id = sa.skill_id
LEFT JOIN cv_entries ON cv_entries.user_id = u.id
WHERE u.id = NEW.id
GROUP BY u.id
);
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE
ON users FOR EACH ROW EXECUTE PROCEDURE update_users_tsv(); Then the old |
Did you tried to use merge query ? # translation.rb
scope :search_full_text, -> (text) {
joins(:source_phrase).merge(Phrase.search_full_text(text))
} # phrase.rb
pg_search_scope :search_full_text,
against: [:text],
using: {
tsearch: {
tsvector_column: 'tsv_text'
}
} |
Would it be possible to update the readme with instructions on how to create a trigger to index associated records? |
You can use my branch #504; we are running that branch in production while I wait for feedback on the PR. |
@mhenrixon Thanks, I ended up writing my own gem: https://rubygems.org/gems/pg_fulltext. It supports native websearch_to_tsquery, so it actually does a lot of things that this gem doesn't, and I've opted to manage associations via the record's tsv column for efficiency. |
I have tried every which way and cannot get this pg_search scope to work. The following does work:
Translation
Phrase
In the above I am not trying to use a ts_vector column on the associated table - I am just using the text field (which is obviously incredibly slow). If I try the following (in translation.rb):
I get the error:
NoMethodError: undefined method 'table_name' for nil:NilClass
. Well that makes sense becauseusing
isn't part ofAssociation
. If I change it up slightly:I get the error
column translations.tsv_text does not exist
, which makes sense, because the column I want isphrases.tsv_text
. I can't specify the table name in thetsearch
option, so I don't know what to do.How do I use the
:tsvector_column
option for an associated table? I.e. I want to queryphrases.tsv_text
. Is this even possible with the current state of the library?The text was updated successfully, but these errors were encountered: