From cbd05be1ea497f0457bd1f14821627cf00daf2b9 Mon Sep 17 00:00:00 2001 From: chiu Date: Thu, 15 Aug 2019 09:55:20 +0800 Subject: [PATCH] =?UTF-8?q?Update=20personal=5Fbooks=5Fcontroller.rb=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=90=9C=E5=B0=8B=E5=8A=9F=E8=83=BD=E4=B8=A6?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=E4=B8=8D=E5=BF=85=E8=A6=81=E7=9A=84=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/personal_books_controller.rb | 24 +++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/app/controllers/personal_books_controller.rb b/app/controllers/personal_books_controller.rb index 217ab9b..f420f3f 100644 --- a/app/controllers/personal_books_controller.rb +++ b/app/controllers/personal_books_controller.rb @@ -1,4 +1,9 @@ class PersonalBooksController < ApplicationController + def search_all_words(target,word) + target=target.upcase + words=word.upcase.split(' ') + return words.select{|value| target.include? value}==words + end def index params = OrbitHelper.params books = Book.where(:is_hidden=>false).sort_for_frontend.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) @@ -21,32 +26,29 @@ class PersonalBooksController < ApplicationController ] end if params[:selectbox] !=nil - books = Book.where(:is_hidden=>false) - books_count = books.count - books_temp = books.take(books_count).sort_by{ |tp| [-tp[:year].to_i,-tp[:publication_date].to_i] } + books_temp = Book.where(:is_hidden=>false).sort_by{ |tp| [-tp[:year].to_i,-tp[:publication_date].to_i] } case params[:selectbox] when "book_title", "extracted_chapters", "default" if page.custom_string_field == "table" - books_show = books_temp.select {|value| value.send(params[:selectbox]).include? params[:keywords]} + books_show = books_temp.select {|value| search_all_words(value.send(params[:selectbox]), params[:keywords])} else - books_show = books_temp.select {|value| value.create_link.include? params[:keywords]} + books_show = books_temp.select {|value| search_all_words(value.create_link, params[:keywords])} end when "publish_date", "publication_date" - books_show = books_temp.select {|value| value.send(params[:selectbox]).strftime("%Y/%m/%d").to_s.include? params[:keywords]} + books_show = books_temp.select {|value| search_all_words(value.send(params[:selectbox]).strftime("%Y/%m/%d").to_s, params[:keywords])} when "author_type" - books_show = books_temp.select {|value| value.book_author_types.collect{|bat| bat.title}.join(", ").include? params[:keywords]} + books_show = books_temp.select {|value| search_all_words(value.book_author_types.collect{|bat| bat.title}.join(", "), params[:keywords])} when "language" - books_show = books_temp.select {|value| (!value.language.nil? ? t("#{value.language}") : "").include? params[:keywords]} + books_show = books_temp.select {|value| search_all_words((!value.language.nil? ? t("#{value.language}") : ""), params[:keywords])} else - books_show = books_temp.select {|value| value.send(params[:selectbox]).to_s.include? params[:keywords]} + books_show = books_temp.select {|value| search_all_words(value.send(params[:selectbox]).to_s, params[:keywords])} end if params[:page_no].nil? page_to_show = 1 else page_to_show = params[:page_no].to_i end - books_show_last = books_show[(page_to_show-1)*OrbitHelper.page_data_count...page_to_show*OrbitHelper.page_data_count] - books = books_show_last + books = books_show[(page_to_show-1)*OrbitHelper.page_data_count...page_to_show*OrbitHelper.page_data_count] books_total_pages = (books_show.length/OrbitHelper.page_data_count.to_f).ceil else books_total_pages = books.total_pages