Commit b13acb431553bfea14046207b0be1c4d751afe98

Authored by Rodrigo Souto
1 parent 5954b097

Adding list of searchable items for models

app/controllers/application_controller.rb
... ... @@ -154,8 +154,8 @@ class ApplicationController < ActionController::Base
154 154 end
155 155 end
156 156  
157   - def find_by_contents(klass, query, paginate_options{}, options={})
158   - @plugins.first(:find_by_contents, klass, query, paginate_options, options) ||
  157 + def find_by_contents(klass, query, paginate_options={}, options={})
  158 + @plugins.first(:find_by_contents, klass, query, paginate_options, options)# ||
159 159 # Failback search using like
160 160 end
161 161  
... ...
app/models/article.rb
... ... @@ -2,6 +2,14 @@ require 'hpricot'
2 2  
3 3 class Article < ActiveRecord::Base
4 4  
  5 + SEARCHABLE_FIELDS = {
  6 + :name => 10,
  7 + :abstract => 3,
  8 + :body => 2,
  9 + :slug => 1,
  10 + :filename => 1,
  11 + }
  12 +
5 13 track_actions :create_article, :after_create, :keep_params => [:name, :url, :lead, :first_image], :if => Proc.new { |a| a.is_trackable? && !a.image? }
6 14  
7 15 # xss_terminate plugin can't sanitize array fields
... ...
app/models/category.rb
1 1 class Category < ActiveRecord::Base
2 2  
  3 + SEARCHABLE_FIELDS = {
  4 + :name => 10,
  5 + :acronym => 5,
  6 + :abbreviation => 5,
  7 + :slug => 1,
  8 + }
  9 +
3 10 validates_exclusion_of :slug, :in => [ 'index' ], :message => N_('%{fn} cannot be like that.').fix_i18n
4 11 validates_presence_of :name, :environment_id
5 12 validates_uniqueness_of :slug,:scope => [ :environment_id, :parent_id ], :message => N_('%{fn} is already being used by another category.').fix_i18n
... ...
app/models/certifier.rb
1 1 class Certifier < ActiveRecord::Base
2 2  
  3 + SEARCHABLE_FIELDS = {
  4 + :name => 10,
  5 + :description => 3,
  6 + :link => 1,
  7 + }
  8 +
3 9 belongs_to :environment
4 10  
5 11 has_many :qualifier_certifiers, :dependent => :destroy
... ...
app/models/comment.rb
1 1 class Comment < ActiveRecord::Base
2 2  
  3 + SEARCHABLE_FIELDS = {
  4 + :title => 10,
  5 + :name => 4,
  6 + :body => 2,
  7 + }
  8 +
3 9 validates_presence_of :body
4 10  
5 11 belongs_to :source, :counter_cache => true, :polymorphic => true
... ...
app/models/license.rb
1 1 class License < ActiveRecord::Base
  2 +
  3 + SEARCHABLE_FIELDS = {
  4 + :name => 10,
  5 + :url => 5,
  6 + }
  7 +
2 8 belongs_to :environment
3 9 has_many :content, :class_name => 'Article', :foreign_key => 'license_id'
4 10  
... ...
app/models/national_region.rb
1 1 class NationalRegion < ActiveRecord::Base
2 2  
  3 + SEARCHABLE_FIELDS = {
  4 + :name => 1,
  5 + :national_region_code => 1,
  6 + }
  7 +
3 8 def self.search_city(city_name, like = false, state = nil)
4 9  
5 10 operator = "="
... ...
app/models/product.rb
1 1 class Product < ActiveRecord::Base
2 2  
  3 + SEARCHABLE_FIELDS = {
  4 + :name => 10,
  5 + :description => 1,
  6 + }
  7 +
3 8 belongs_to :enterprise
4 9 has_one :region, :through => :enterprise
5 10 validates_presence_of :enterprise
... ...
app/models/profile.rb
... ... @@ -3,6 +3,12 @@
3 3 # which by default is the one returned by Environment:default.
4 4 class Profile < ActiveRecord::Base
5 5  
  6 + SEARCHABLE_FIELDS = {
  7 + :name => 10,
  8 + :identifier => 5,
  9 + :nickname => 2,
  10 + }
  11 +
6 12 module Roles
7 13 def self.admin(env_id)
8 14 find_role('admin', env_id)
... ...
app/models/qualifier.rb
1 1 class Qualifier < ActiveRecord::Base
2 2  
  3 + SEARCHABLE_FIELDS = {
  4 + :name => 1,
  5 + }
  6 +
3 7 belongs_to :environment
4 8  
5 9 has_many :qualifier_certifiers, :dependent => :destroy
... ...
app/models/scrap.rb
1 1 class Scrap < ActiveRecord::Base
  2 + SEARCHABLE_FIELDS = {
  3 + :content => 1,
  4 + }
2 5 validates_presence_of :content
3 6 validates_presence_of :sender_id, :receiver_id
4 7  
... ...