[Fix #2179] Use new full text search
This commit is contained in:
parent
8fc359c54d
commit
d681b1116f
1 changed files with 16 additions and 4 deletions
|
@ -27,9 +27,21 @@ class DossierSearchService
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.dossier_by_full_text_for_gestionnaire(search_terms, gestionnaire)
|
def self.dossier_by_full_text_for_gestionnaire(search_terms, gestionnaire)
|
||||||
Search.new(
|
ts_vector = "to_tsvector('french', search_terms || private_search_terms)"
|
||||||
gestionnaire: gestionnaire,
|
ts_query = "to_tsquery('french', #{Dossier.connection.quote(to_tsquery(search_terms))})"
|
||||||
query: search_terms
|
|
||||||
).results
|
gestionnaire
|
||||||
|
.dossiers
|
||||||
|
.not_archived
|
||||||
|
.state_not_brouillon
|
||||||
|
.where("#{ts_vector} @@ #{ts_query}")
|
||||||
|
.order("COALESCE(ts_rank(#{ts_vector}, #{ts_query}), 0) DESC")
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.to_tsquery(search_terms)
|
||||||
|
search_terms.gsub(/['?\\:&|!]/, "") # drop disallowed characters
|
||||||
|
.split(/\s+/) # split words
|
||||||
|
.map { |x| "#{x}:*" } # enable prefix matching
|
||||||
|
.join(" & ")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue