This commit is contained in:
yanxd 2014-01-20 08:59:17 +08:00
parent 90f1d3c528
commit d357541bb8
1 changed files with 12 additions and 7 deletions

View File

@ -7,12 +7,20 @@ class StoresController < ApplicationController
def search
name = params[:name] ||= ''
(redirect_to stores_path, :notice => l(:label_sumbit_empty);return) if name.blank?
# 按文件名搜索
resultSet = Attachment.where("attachments.container_type IS NOT NULL AND filename LIKE :like ", like: "%#{name}%").
result = find_public_attache name
@searched_attach = paginateHelper result
@result_all_count = result.count;
end
def find_public_attache keywords
# StoresController#search 将每条文件都查出来,再次进行判断过滤。---> resultSet.to_a.map
# 此时内容不多速度还可但文件增长每条判断多则进行3-4次表连接。
# 现在还木有思路 药丸
resultSet = Attachment.where("attachments.container_type IS NOT NULL AND filename LIKE :like ", like: "%#{keywords}%").
reorder("created_on DESC")
result = resultSet.to_a.dup
@result_all_count = result.count;
resultSet.to_a.map { |res|
if(res.container.nil? ||
@ -21,13 +29,10 @@ class StoresController < ApplicationController
(res.container.class.to_s=="HomeworkAttach" && res.container.bid.reward_type == 3) ||
false
)
# logger.debug("=====================================#{result.include? res}")
# logger.debug("=====================================#{res}")
result.delete(res)
# logger.debug("=====================================#{result.include? res}")
end
}
@searched_attach = paginateHelper result
result
end
LIMIT = 12 unless const_defined?(:LIMIT)