Revision 442:753f1380d6bc vendor/plugins/acts_as_searchable/lib
| vendor/plugins/acts_as_searchable/lib/.svn/entries | ||
|---|---|---|
| 1 | 1 |
10 |
| 2 | 2 |
|
| 3 | 3 |
dir |
| 4 |
4993
|
|
| 5 |
http://redmine.rubyforge.org/svn/trunk/vendor/plugins/acts_as_searchable/lib
|
|
| 4 |
6000
|
|
| 5 |
http://redmine.rubyforge.org/svn/branches/1.2-stable/vendor/plugins/acts_as_searchable/lib
|
|
| 6 | 6 |
http://redmine.rubyforge.org/svn |
| 7 | 7 |
|
| 8 | 8 |
|
| 9 | 9 |
|
| 10 |
2010-02-17T20:20:51.097274Z
|
|
| 11 |
3445
|
|
| 10 |
2011-04-05T12:55:19.162428Z
|
|
| 11 |
5327
|
|
| 12 | 12 |
jplang |
| 13 | 13 |
|
| 14 | 14 |
|
| ... | ... | |
| 32 | 32 |
|
| 33 | 33 |
|
| 34 | 34 |
|
| 35 |
2011-03-03T11:05:12.000000Z
|
|
| 36 |
f282f30a34a9560d7ef3d5883aba5fe9
|
|
| 37 |
2010-02-17T20:20:51.097274Z
|
|
| 38 |
3445
|
|
| 35 |
2011-06-06T13:18:33.000000Z
|
|
| 36 |
4dd9ab6c2387d779d21e2fac9727e70f
|
|
| 37 |
2011-04-05T12:55:19.162428Z
|
|
| 38 |
5327
|
|
| 39 | 39 |
jplang |
| 40 | 40 |
has-props |
| 41 | 41 |
|
| ... | ... | |
| 58 | 58 |
|
| 59 | 59 |
|
| 60 | 60 |
|
| 61 |
5937
|
|
| 61 |
6360
|
|
| 62 | 62 |
|
| vendor/plugins/acts_as_searchable/lib/.svn/text-base/acts_as_searchable.rb.svn-base | ||
|---|---|---|
| 1 |
# redMine - project management software
|
|
| 2 |
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
|
| 1 |
# Redmine - project management software
|
|
| 2 |
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
|
| 3 | 3 |
# |
| 4 | 4 |
# This program is free software; you can redistribute it and/or |
| 5 | 5 |
# modify it under the terms of the GNU General Public License |
| ... | ... | |
| 45 | 45 |
searchable_options[:date_column] ||= "#{table_name}.created_on"
|
| 46 | 46 |
searchable_options[:order_column] ||= searchable_options[:date_column] |
| 47 | 47 |
|
| 48 |
# Permission needed to search this model |
|
| 49 |
searchable_options[:permission] = "view_#{self.name.underscore.pluralize}".to_sym unless searchable_options.has_key?(:permission)
|
|
| 50 |
|
|
| 51 | 48 |
# Should we search custom fields on this model ? |
| 52 | 49 |
searchable_options[:search_custom_fields] = !reflect_on_association(:custom_values).nil? |
| 53 | 50 |
|
| ... | ... | |
| 65 | 62 |
# projects argument can be either nil (will search all projects), a project or an array of projects |
| 66 | 63 |
# Returns the results and the results count |
| 67 | 64 |
def search(tokens, projects=nil, options={})
|
| 65 |
# TODO: make user an argument |
|
| 66 |
user = User.current |
|
| 68 | 67 |
tokens = [] << tokens unless tokens.is_a?(Array) |
| 69 | 68 |
projects = [] << projects unless projects.nil? || projects.is_a?(Array) |
| 70 | 69 |
|
| ... | ... | |
| 99 | 98 |
|
| 100 | 99 |
find_options[:conditions] = [sql, * (tokens.collect {|w| "%#{w.downcase}%"} * token_clauses.size).sort]
|
| 101 | 100 |
|
| 101 |
scope = self |
|
| 102 | 102 |
project_conditions = [] |
| 103 |
project_conditions << (searchable_options[:permission].nil? ? Project.visible_by(User.current) : |
|
| 104 |
Project.allowed_to_condition(User.current, searchable_options[:permission])) |
|
| 103 |
if searchable_options.has_key?(:permission) |
|
| 104 |
project_conditions << Project.allowed_to_condition(user, searchable_options[:permission] || :view_project) |
|
| 105 |
elsif respond_to?(:visible) |
|
| 106 |
scope = scope.visible(user) |
|
| 107 |
else |
|
| 108 |
ActiveSupport::Deprecation.warn "acts_as_searchable with implicit :permission option is deprecated. Add a visible scope to the #{self.name} model or use explicit :permission option."
|
|
| 109 |
project_conditions << Project.allowed_to_condition(user, "view_#{self.name.underscore.pluralize}".to_sym)
|
|
| 110 |
end |
|
| 111 |
# TODO: use visible scope options instead |
|
| 105 | 112 |
project_conditions << "#{searchable_options[:project_key]} IN (#{projects.collect(&:id).join(',')})" unless projects.nil?
|
| 113 |
project_conditions = project_conditions.empty? ? nil : project_conditions.join(' AND ')
|
|
| 106 | 114 |
|
| 107 | 115 |
results = [] |
| 108 | 116 |
results_count = 0 |
| 109 | 117 |
|
| 110 |
with_scope(:find => {:conditions => project_conditions.join(' AND ')}) do
|
|
| 118 |
with_scope(:find => {:conditions => project_conditions}) do
|
|
| 111 | 119 |
with_scope(:find => find_options) do |
| 112 |
results_count = count(:all) |
|
| 113 |
results = find(:all, limit_options) |
|
| 120 |
results_count = scope.count(:all)
|
|
| 121 |
results = scope.find(:all, limit_options)
|
|
| 114 | 122 |
end |
| 115 | 123 |
end |
| 116 | 124 |
[results, results_count] |
| vendor/plugins/acts_as_searchable/lib/acts_as_searchable.rb | ||
|---|---|---|
| 1 |
# redMine - project management software
|
|
| 2 |
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
|
| 1 |
# Redmine - project management software
|
|
| 2 |
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
|
| 3 | 3 |
# |
| 4 | 4 |
# This program is free software; you can redistribute it and/or |
| 5 | 5 |
# modify it under the terms of the GNU General Public License |
| ... | ... | |
| 45 | 45 |
searchable_options[:date_column] ||= "#{table_name}.created_on"
|
| 46 | 46 |
searchable_options[:order_column] ||= searchable_options[:date_column] |
| 47 | 47 |
|
| 48 |
# Permission needed to search this model |
|
| 49 |
searchable_options[:permission] = "view_#{self.name.underscore.pluralize}".to_sym unless searchable_options.has_key?(:permission)
|
|
| 50 |
|
|
| 51 | 48 |
# Should we search custom fields on this model ? |
| 52 | 49 |
searchable_options[:search_custom_fields] = !reflect_on_association(:custom_values).nil? |
| 53 | 50 |
|
| ... | ... | |
| 65 | 62 |
# projects argument can be either nil (will search all projects), a project or an array of projects |
| 66 | 63 |
# Returns the results and the results count |
| 67 | 64 |
def search(tokens, projects=nil, options={})
|
| 65 |
# TODO: make user an argument |
|
| 66 |
user = User.current |
|
| 68 | 67 |
tokens = [] << tokens unless tokens.is_a?(Array) |
| 69 | 68 |
projects = [] << projects unless projects.nil? || projects.is_a?(Array) |
| 70 | 69 |
|
| ... | ... | |
| 99 | 98 |
|
| 100 | 99 |
find_options[:conditions] = [sql, * (tokens.collect {|w| "%#{w.downcase}%"} * token_clauses.size).sort]
|
| 101 | 100 |
|
| 101 |
scope = self |
|
| 102 | 102 |
project_conditions = [] |
| 103 |
project_conditions << (searchable_options[:permission].nil? ? Project.visible_by(User.current) : |
|
| 104 |
Project.allowed_to_condition(User.current, searchable_options[:permission])) |
|
| 103 |
if searchable_options.has_key?(:permission) |
|
| 104 |
project_conditions << Project.allowed_to_condition(user, searchable_options[:permission] || :view_project) |
|
| 105 |
elsif respond_to?(:visible) |
|
| 106 |
scope = scope.visible(user) |
|
| 107 |
else |
|
| 108 |
ActiveSupport::Deprecation.warn "acts_as_searchable with implicit :permission option is deprecated. Add a visible scope to the #{self.name} model or use explicit :permission option."
|
|
| 109 |
project_conditions << Project.allowed_to_condition(user, "view_#{self.name.underscore.pluralize}".to_sym)
|
|
| 110 |
end |
|
| 111 |
# TODO: use visible scope options instead |
|
| 105 | 112 |
project_conditions << "#{searchable_options[:project_key]} IN (#{projects.collect(&:id).join(',')})" unless projects.nil?
|
| 113 |
project_conditions = project_conditions.empty? ? nil : project_conditions.join(' AND ')
|
|
| 106 | 114 |
|
| 107 | 115 |
results = [] |
| 108 | 116 |
results_count = 0 |
| 109 | 117 |
|
| 110 |
with_scope(:find => {:conditions => project_conditions.join(' AND ')}) do
|
|
| 118 |
with_scope(:find => {:conditions => project_conditions}) do
|
|
| 111 | 119 |
with_scope(:find => find_options) do |
| 112 |
results_count = count(:all) |
|
| 113 |
results = find(:all, limit_options) |
|
| 120 |
results_count = scope.count(:all)
|
|
| 121 |
results = scope.find(:all, limit_options)
|
|
| 114 | 122 |
end |
| 115 | 123 |
end |
| 116 | 124 |
[results, results_count] |
Also available in: Unified diff