dmails: add search[title_matches] param.

This commit is contained in:
evazion
2017-04-29 11:39:18 -05:00
parent 27d6025425
commit d1216f260e
2 changed files with 10 additions and 0 deletions

View File

@@ -102,6 +102,11 @@ class Dmail < ActiveRecord::Base
where("is_deleted = ?", true)
end
def title_matches(query)
query = "*#{query}*" unless query =~ /\*/
where("lower(dmails.title) LIKE ?", query.to_escaped_for_sql_like)
end
def search_message(query)
if query =~ /\*/ && CurrentUser.user.is_builder?
escaped_query = query.to_escaped_for_sql_like
@@ -131,6 +136,10 @@ class Dmail < ActiveRecord::Base
q = where("true")
return q if params.blank?
if params[:title_matches].present?
q = q.title_matches(params[:title_matches])
end
if params[:message_matches].present?
q = q.search_message(params[:message_matches])
end