/
Dmitry-F
/
cbt_tool
Обзор
Документация
Войти
/
Dmitry-F
/
cbt_tool
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
python-ml-service
app/models/client.rb
28 строк
978 B
Dmitriy-Filatov
Глобальный полнотекстовый поиск (FTS) внедрён
19 мар 2026, 21:45
19 мар 2026, 21:45
94b70c9
Код
Авторство
О чём код?
class Client < ApplicationRecord belongs_to :therapist has_many :sessions, dependent: :nullify has_many :smer_diary_entries, class_name: "SmerDiary::DiaryEntry", foreign_key: "client_id" validates :name, presence: true validates :email, uniqueness: { scope: :therapist_id, allow_blank: true } validates :phone, format: { with: /\A\d{10,11}\z/, allow_blank: true } # Полнотекстовый поиск с ранжированием по весам A (name, email) scope :search, ->(query) { return all if query.blank? quoted_query = connection.quote(query) where("search_vector @@ websearch_to_tsquery('russian', ?)", query) .order(Arel.sql("ts_rank(search_vector, websearch_to_tsquery('russian', #{quoted_query})) DESC")) } before_validation :normalize_phone private def normalize_phone return if phone.blank? digits = phone.to_s.gsub(/\D/, "") self.phone = digits.length == 11 ? digits[1..-1] : digits end end