diff options
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/asset.rb | 14 | ||||
| -rw-r--r-- | app/models/event.rb | 18 |
2 files changed, 32 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 |
diff --git a/app/models/event.rb b/app/models/event.rb index 792ab448..e7823617 100644 --- a/app/models/event.rb +++ b/app/models/event.rb | |||
| @@ -54,6 +54,24 @@ class Event < ApplicationRecord | |||
| 54 | destroyed | 54 | destroyed |
| 55 | end | 55 | end |
| 56 | 56 | ||
| 57 | def self.editor_search(term) | ||
| 58 | words = term.to_s.split(/\s+/).reject(&:blank?) | ||
| 59 | return none if words.empty? | ||
| 60 | |||
| 61 | words.inject(all) do |scope, word| | ||
| 62 | like = "%#{sanitize_sql_like(word)}%" | ||
| 63 | tagged = ActsAsTaggableOn::Tagging | ||
| 64 | .where(:taggable_type => base_class.name) | ||
| 65 | .joins(:tag).where("tags.name ILIKE ?", like) | ||
| 66 | .select(:taggable_id) | ||
| 67 | scope.where( | ||
| 68 | "events.title ILIKE :t OR events.description ILIKE :t OR " \ | ||
| 69 | "events.location ILIKE :t OR events.url ILIKE :t OR " \ | ||
| 70 | "events.id IN (:tagged)", :t => like, :tagged => tagged | ||
| 71 | ) | ||
| 72 | end | ||
| 73 | end | ||
| 74 | |||
| 57 | private | 75 | private |
| 58 | def generate_occurrences | 76 | def generate_occurrences |
| 59 | Occurrence.generate self | 77 | Occurrence.generate self |
