Skip to content

Use tsvector for search #105

@kimburgess

Description

@kimburgess

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).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions