From b13acb431553bfea14046207b0be1c4d751afe98 Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Wed, 27 Feb 2013 21:47:15 -0300 Subject: [PATCH] Adding list of searchable items for models --- app/controllers/application_controller.rb | 4 ++-- app/models/article.rb | 8 ++++++++ app/models/category.rb | 7 +++++++ app/models/certifier.rb | 6 ++++++ app/models/comment.rb | 6 ++++++ app/models/license.rb | 6 ++++++ app/models/national_region.rb | 5 +++++ app/models/product.rb | 5 +++++ app/models/profile.rb | 6 ++++++ app/models/qualifier.rb | 4 ++++ app/models/scrap.rb | 3 +++ 11 files changed, 58 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 87715a7..35df565 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -154,8 +154,8 @@ class ApplicationController < ActionController::Base end end - def find_by_contents(klass, query, paginate_options{}, options={}) - @plugins.first(:find_by_contents, klass, query, paginate_options, options) || + def find_by_contents(klass, query, paginate_options={}, options={}) + @plugins.first(:find_by_contents, klass, query, paginate_options, options)# || # Failback search using like end diff --git a/app/models/article.rb b/app/models/article.rb index fcc7687..c5094d0 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -2,6 +2,14 @@ require 'hpricot' class Article < ActiveRecord::Base + SEARCHABLE_FIELDS = { + :name => 10, + :abstract => 3, + :body => 2, + :slug => 1, + :filename => 1, + } + track_actions :create_article, :after_create, :keep_params => [:name, :url, :lead, :first_image], :if => Proc.new { |a| a.is_trackable? && !a.image? } # xss_terminate plugin can't sanitize array fields diff --git a/app/models/category.rb b/app/models/category.rb index 110d790..04f8d98 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -1,5 +1,12 @@ class Category < ActiveRecord::Base + SEARCHABLE_FIELDS = { + :name => 10, + :acronym => 5, + :abbreviation => 5, + :slug => 1, + } + validates_exclusion_of :slug, :in => [ 'index' ], :message => N_('%{fn} cannot be like that.').fix_i18n validates_presence_of :name, :environment_id validates_uniqueness_of :slug,:scope => [ :environment_id, :parent_id ], :message => N_('%{fn} is already being used by another category.').fix_i18n diff --git a/app/models/certifier.rb b/app/models/certifier.rb index 1db7984..1292322 100644 --- a/app/models/certifier.rb +++ b/app/models/certifier.rb @@ -1,5 +1,11 @@ class Certifier < ActiveRecord::Base + SEARCHABLE_FIELDS = { + :name => 10, + :description => 3, + :link => 1, + } + belongs_to :environment has_many :qualifier_certifiers, :dependent => :destroy diff --git a/app/models/comment.rb b/app/models/comment.rb index ed99a97..8e85a8f 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,5 +1,11 @@ class Comment < ActiveRecord::Base + SEARCHABLE_FIELDS = { + :title => 10, + :name => 4, + :body => 2, + } + validates_presence_of :body belongs_to :source, :counter_cache => true, :polymorphic => true diff --git a/app/models/license.rb b/app/models/license.rb index 9b57d08..3db2dba 100644 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -1,4 +1,10 @@ class License < ActiveRecord::Base + + SEARCHABLE_FIELDS = { + :name => 10, + :url => 5, + } + belongs_to :environment has_many :content, :class_name => 'Article', :foreign_key => 'license_id' diff --git a/app/models/national_region.rb b/app/models/national_region.rb index 557a12f..e06e4ba 100644 --- a/app/models/national_region.rb +++ b/app/models/national_region.rb @@ -1,5 +1,10 @@ class NationalRegion < ActiveRecord::Base + SEARCHABLE_FIELDS = { + :name => 1, + :national_region_code => 1, + } + def self.search_city(city_name, like = false, state = nil) operator = "=" diff --git a/app/models/product.rb b/app/models/product.rb index 775547c..2fc76f9 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -1,5 +1,10 @@ class Product < ActiveRecord::Base + SEARCHABLE_FIELDS = { + :name => 10, + :description => 1, + } + belongs_to :enterprise has_one :region, :through => :enterprise validates_presence_of :enterprise diff --git a/app/models/profile.rb b/app/models/profile.rb index 2178da6..5fc1a3e 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -3,6 +3,12 @@ # which by default is the one returned by Environment:default. class Profile < ActiveRecord::Base + SEARCHABLE_FIELDS = { + :name => 10, + :identifier => 5, + :nickname => 2, + } + module Roles def self.admin(env_id) find_role('admin', env_id) diff --git a/app/models/qualifier.rb b/app/models/qualifier.rb index 3852dc7..6ae55d0 100644 --- a/app/models/qualifier.rb +++ b/app/models/qualifier.rb @@ -1,5 +1,9 @@ class Qualifier < ActiveRecord::Base + SEARCHABLE_FIELDS = { + :name => 1, + } + belongs_to :environment has_many :qualifier_certifiers, :dependent => :destroy diff --git a/app/models/scrap.rb b/app/models/scrap.rb index 4fc3ac5..85d100a 100644 --- a/app/models/scrap.rb +++ b/app/models/scrap.rb @@ -1,4 +1,7 @@ class Scrap < ActiveRecord::Base + SEARCHABLE_FIELDS = { + :content => 1, + } validates_presence_of :content validates_presence_of :sender_id, :receiver_id -- libgit2 0.21.2