modify service
This commit is contained in:
parent
7d9cf63056
commit
fdde55f675
2 changed files with 22 additions and 9 deletions
|
@ -74,6 +74,12 @@ class DossierProjectionService
|
|||
.where(id: dossiers_ids)
|
||||
.pluck('dossiers.id, groupe_instructeurs.label')
|
||||
.to_h
|
||||
when 'procedure'
|
||||
Dossier
|
||||
.joins(:procedure)
|
||||
.where(id: dossiers_ids)
|
||||
.pluck(:id, *fields.map { |f| f[COLUMN].to_sym })
|
||||
.each { |id, *columns| fields.zip(columns).each { |field, value| field[:id_value_h][id] = value } }
|
||||
when 'followers_instructeurs'
|
||||
fields[0][:id_value_h] = Follow
|
||||
.active
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class DossierSearchService
|
||||
def self.matching_dossiers_for_instructeur(search_terms, instructeur)
|
||||
dossier_by_exact_id_for_instructeur(search_terms, instructeur)
|
||||
.presence || dossier_by_full_text_for_instructeur(search_terms, instructeur)
|
||||
def self.matching_dossiers(ids, search_terms, with_annotations = false)
|
||||
dossier_by_exact_id(ids, search_terms)
|
||||
.presence || dossier_by_full_text(ids, search_terms, with_annotations)
|
||||
end
|
||||
|
||||
def self.matching_dossiers_for_user(search_terms, user)
|
||||
|
@ -11,17 +11,24 @@ class DossierSearchService
|
|||
|
||||
private
|
||||
|
||||
def self.dossier_by_exact_id_for_instructeur(search_terms, instructeur)
|
||||
def self.dossier_by_exact_id(ids, search_terms)
|
||||
id = search_terms.to_i
|
||||
if id != 0 && id_compatible?(id) # Sometimes instructeur is searching dossiers with a big number (ex: SIRET), ActiveRecord can't deal with them and throws ActiveModel::RangeError. id_compatible? prevents this.
|
||||
dossiers_by_id(id, instructeur)
|
||||
ids.filter { |dossier_id| dossier_id == id }.uniq
|
||||
else
|
||||
Dossier.none
|
||||
end
|
||||
end
|
||||
|
||||
def self.dossiers_by_id(id, instructeur)
|
||||
instructeur.dossiers.where(id: id).uniq
|
||||
def self.dossier_by_full_text(ids, search_terms, with_annotations)
|
||||
ts_vector = "to_tsvector('french', #{with_annotations ? 'dossiers.search_terms || dossiers.private_search_terms' : 'dossiers.search_terms'})"
|
||||
ts_query = "to_tsquery('french', #{Dossier.connection.quote(to_tsquery(search_terms))})"
|
||||
|
||||
Dossier.where(id: ids)
|
||||
.where("#{ts_vector} @@ #{ts_query}")
|
||||
.order(Arel.sql("COALESCE(ts_rank(#{ts_vector}, #{ts_query}), 0) DESC"))
|
||||
.pluck('id')
|
||||
.uniq
|
||||
end
|
||||
|
||||
def self.id_compatible?(number)
|
||||
|
@ -49,11 +56,11 @@ class DossierSearchService
|
|||
end
|
||||
end
|
||||
|
||||
def self.dossier_by_full_text_for_instructeur(search_terms, instructeur)
|
||||
def self.dossier_by_full_text_for_current_user(search_terms, user)
|
||||
ts_vector = "to_tsvector('french', search_terms || private_search_terms)"
|
||||
ts_query = "to_tsquery('french', #{Dossier.connection.quote(to_tsquery(search_terms))})"
|
||||
|
||||
instructeur
|
||||
user
|
||||
.dossiers
|
||||
.state_not_brouillon
|
||||
.where("#{ts_vector} @@ #{ts_query}")
|
||||
|
|
Loading…
Reference in a new issue