diff --git a/app/controllers/admin/patents_controller.rb b/app/controllers/admin/patents_controller.rb index 42d7ea2..731f8fa 100644 --- a/app/controllers/admin/patents_controller.rb +++ b/app/controllers/admin/patents_controller.rb @@ -26,7 +26,7 @@ class Admin::PatentsController < OrbitMemberController redirect_to :action=> 'index' end def merge - @patents=Patent.order_by(:year=>'desc').map{|value| value}.group_by{|v| [v[:patent_title],v[:patent_no]]} + @patents=Patent.sort_year_date.map{|value| value}.group_by{|v| [v[:patent_title],v[:patent_no]]} @patents.each do |key,value| if value.length<=1 @patents.delete key @@ -49,7 +49,7 @@ class Admin::PatentsController < OrbitMemberController end def index - @patents = Patent.order_by(:year=>'desc').page(params[:page]).per(10) + @patents = Patent.sort_year_date.page(params[:page]).per(10) end def new diff --git a/app/controllers/personal_patents_controller.rb b/app/controllers/personal_patents_controller.rb index 565c4d1..af58c96 100644 --- a/app/controllers/personal_patents_controller.rb +++ b/app/controllers/personal_patents_controller.rb @@ -3,7 +3,7 @@ class PersonalPatentsController < ApplicationController def index params = OrbitHelper.params page_data_count = OrbitHelper.page_data_count - patents = Patent.where(is_hidden: false).sort_for_frontend.page(OrbitHelper.params[:page_no]).per(page_data_count) + patents = Patent.sort_for_frontend.page(OrbitHelper.params[:page_no]).per(page_data_count) fields_to_show = Page.where(page_id: params[:page_id]).first.custom_array_field rescue [] if fields_to_show.blank? fields_to_show = %w[ diff --git a/app/models/patent.rb b/app/models/patent.rb index 28cce00..0593686 100644 --- a/app/models/patent.rb +++ b/app/models/patent.rb @@ -34,7 +34,9 @@ class Patent before_validation :add_http - scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year => "desc", :application_date => "desc", :publish_date => "desc") } + index({year: -1, application_date: -1, publish_date: -1, _id: -1}, { unique: false, background: false }) + scope :sort_year_date, ->{ order_by(:year => "desc", :application_date => "desc", :publish_date => "desc", :id => "desc") } + scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year => "desc", :application_date => "desc", :publish_date => "desc", :id => "desc") } def member_profile() (super || MemberProfile.find(self.member_profile_id)) rescue nil diff --git a/app/views/plugin/personal_patent/_profile.html.erb b/app/views/plugin/personal_patent/_profile.html.erb index e3f50c5..006271b 100644 --- a/app/views/plugin/personal_patent/_profile.html.erb +++ b/app/views/plugin/personal_patent/_profile.html.erb @@ -7,9 +7,9 @@ <% if has_access? - @patents = Patent.where(member_profile_id: @member.id).desc(:year).page(params[:page]).per(10) + @patents = Patent.where(member_profile_id: @member.id).sort_year_date.page(params[:page]).per(10) else - @patents = Patent.where(is_hidden: false, member_profile_id: @member.id).desc(:year).page(params[:page]).per(10) + @patents = Patent.where(is_hidden: false, member_profile_id: @member.id).sort_year_date.page(params[:page]).per(10) end %>