diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-08-05 23:56:56 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-08-05 23:56:56 +0200 |
| commit | af2c6fd85e13139be3e3b2329a51c3a35acb3c40 (patch) | |
| tree | 02114279d6517ffc12b9920cc1d843937bff5a10 /app/models/asset.rb | |
| parent | a0a495d804319c3f7ad179baba7b87b41f1dc1f3 (diff) | |
Search assets and events, and order events by when they happen
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 |
