diff options
Diffstat (limited to 'app/models/asset.rb')
| -rw-r--r-- | app/models/asset.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/app/models/asset.rb b/app/models/asset.rb index b256b929..4d43b18f 100644 --- a/app/models/asset.rb +++ b/app/models/asset.rb | |||
| @@ -82,4 +82,18 @@ class Asset < ApplicationRecord | |||
| 82 | destroy! | 82 | destroy! |
| 83 | end | 83 | end |
| 84 | end | 84 | end |
| 85 | |||
| 86 | def self.editor_search(term) | ||
| 87 | words = term.to_s.split(/\s+/).reject(&:blank?) | ||
| 88 | return none if words.empty? | ||
| 89 | |||
| 90 | words.inject(all) do |scope, word| | ||
| 91 | like = "%#{sanitize_sql_like(word)}%" | ||
| 92 | scope.where( | ||
| 93 | "assets.name ILIKE :t OR assets.creator ILIKE :t OR " \ | ||
| 94 | "assets.upload_file_name ILIKE :t OR assets.source_url ILIKE :t OR " \ | ||
| 95 | "assets.upload_content_type ILIKE :t", :t => like | ||
| 96 | ) | ||
| 97 | end | ||
| 98 | end | ||
| 85 | end | 99 | end |
