Skip to content
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

Use tsvector for search #105

Open
kimburgess opened this issue Sep 2, 2021 · 1 comment
Open

Use tsvector for search #105

kimburgess opened this issue Sep 2, 2021 · 1 comment
Assignees
Labels

Comments

@kimburgess
Copy link
Contributor

kimburgess commented Sep 2, 2021

The guest model currently uses a text column that contains a copy of attributes used in search.

# Save searchable information
before(:save) do |m|
guest_model = m.as(Guest)
guest_model.email = guest_model.email.downcase
searchable_string = guest_model.email
searchable_string += " #{guest_model.name}" if guest_model.name_column.defined?
searchable_string += " #{guest_model.preferred_name}" if guest_model.preferred_name_column.defined?
searchable_string += " #{guest_model.organisation}" if guest_model.organisation_column.defined?
searchable_string += " #{guest_model.phone}" if guest_model.phone_column.defined?
searchable_string += " #{guest_model.id}" if guest_model.id_column.defined?
guest_model.searchable = searchable_string.downcase
end

Queries are then performed with a LIKE operator, with growing complexity (#104).

To improve control over search behaviour, it may be worthwhile switching to using a tsvector and tsquery. This can then be managed with an update trigger (and possibly a GIN index, depending on perf requirements).

Alternatively, moving this to elasticsearch may also be an option worth considering (at the expense of another service dependency, but providing conformity with other platform services).

@kimburgess kimburgess added the type: enhancement new feature or request label Sep 2, 2021
@caspiano
Copy link
Contributor

caspiano commented Sep 2, 2021

+1 on tsvector

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants