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)
|
.where(id: dossiers_ids)
|
||||||
.pluck('dossiers.id, groupe_instructeurs.label')
|
.pluck('dossiers.id, groupe_instructeurs.label')
|
||||||
.to_h
|
.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'
|
when 'followers_instructeurs'
|
||||||
fields[0][:id_value_h] = Follow
|
fields[0][:id_value_h] = Follow
|
||||||
.active
|
.active
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
class DossierSearchService
|
class DossierSearchService
|
||||||
def self.matching_dossiers_for_instructeur(search_terms, instructeur)
|
def self.matching_dossiers(ids, search_terms, with_annotations = false)
|
||||||
dossier_by_exact_id_for_instructeur(search_terms, instructeur)
|
dossier_by_exact_id(ids, search_terms)
|
||||||
.presence || dossier_by_full_text_for_instructeur(search_terms, instructeur)
|
.presence || dossier_by_full_text(ids, search_terms, with_annotations)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.matching_dossiers_for_user(search_terms, user)
|
def self.matching_dossiers_for_user(search_terms, user)
|
||||||
|
@ -11,17 +11,24 @@ class DossierSearchService
|
||||||
|
|
||||||
private
|
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
|
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.
|
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
|
else
|
||||||
Dossier.none
|
Dossier.none
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.dossiers_by_id(id, instructeur)
|
def self.dossier_by_full_text(ids, search_terms, with_annotations)
|
||||||
instructeur.dossiers.where(id: id).uniq
|
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
|
end
|
||||||
|
|
||||||
def self.id_compatible?(number)
|
def self.id_compatible?(number)
|
||||||
|
@ -49,11 +56,11 @@ class DossierSearchService
|
||||||
end
|
end
|
||||||
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_vector = "to_tsvector('french', search_terms || private_search_terms)"
|
||||||
ts_query = "to_tsquery('french', #{Dossier.connection.quote(to_tsquery(search_terms))})"
|
ts_query = "to_tsquery('french', #{Dossier.connection.quote(to_tsquery(search_terms))})"
|
||||||
|
|
||||||
instructeur
|
user
|
||||||
.dossiers
|
.dossiers
|
||||||
.state_not_brouillon
|
.state_not_brouillon
|
||||||
.where("#{ts_vector} @@ #{ts_query}")
|
.where("#{ts_vector} @@ #{ts_query}")
|
||||||
|
|
Loading…
Reference in a new issue