From d357541bb883329f9438810cb4880ab2ffb3842e Mon Sep 17 00:00:00 2001 From: yanxd Date: Mon, 20 Jan 2014 08:59:17 +0800 Subject: [PATCH] yaowan --- app/controllers/stores_controller.rb | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/app/controllers/stores_controller.rb b/app/controllers/stores_controller.rb index e1af58b9..0ed12d76 100644 --- a/app/controllers/stores_controller.rb +++ b/app/controllers/stores_controller.rb @@ -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)