diff --git a/app/controllers/school_controller.rb b/app/controllers/school_controller.rb index 1ecd5733..251400d5 100644 --- a/app/controllers/school_controller.rb +++ b/app/controllers/school_controller.rb @@ -126,21 +126,26 @@ class SchoolController < ApplicationController chinese << char end end + if pinyin.size > 0 + search_str = "name like '%#{chinese.join("")}%' and pinyin like '%#{pinyin.join("")}%'" + else + search_str = "name like '%#{chinese.join("")}%'" + end if params[:no_school_ids] if(condition == '') @school = School.where("id not in #{params[:no_school_ids]}").reorder('CONVERT (name USING gbk) COLLATE gbk_chinese_ci asc').page((params[:page].to_i || 1)).per(100) @school_count = School.count else - @school = School.where("id not in #{params[:no_school_ids]} and name like '%#{chinese.join("")}%' and pinyin like '%#{pinyin.join("")}%'").reorder('CONVERT (name USING gbk) COLLATE gbk_chinese_ci asc').page((params[:page].to_i || 1)).per(100) - @school_count = School.where("id not in #{params[:no_school_ids]} and name like '%#{chinese.join("")}%' and pinyin like '%#{pinyin.join("")}%'").count + @school = School.where("id not in #{params[:no_school_ids]} and #{search_str}").reorder('CONVERT (name USING gbk) COLLATE gbk_chinese_ci asc').page((params[:page].to_i || 1)).per(100) + @school_count = School.where("id not in #{params[:no_school_ids]} and #{search_str}").count end else if(condition == '') @school = School.reorder('CONVERT (name USING gbk) COLLATE gbk_chinese_ci asc').page((params[:page].to_i || 1)).per(100) @school_count = School.count else - @school = School.where("name like '%#{chinese.join("")}%' and pinyin like '%#{pinyin.join("")}%'").reorder('CONVERT (name USING gbk) COLLATE gbk_chinese_ci asc').page((params[:page].to_i || 1)).per(100) - @school_count = School.where("name like '%#{chinese.join("")}%' and pinyin like '%#{pinyin.join("")}%'").count + @school = School.where(search_str).reorder('CONVERT (name USING gbk) COLLATE gbk_chinese_ci asc').page((params[:page].to_i || 1)).per(100) + @school_count = School.where(search_str).count end end