diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index 16d516f82..f462a64e7 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -118,7 +118,7 @@ class MyController < ApplicationController @user.safe_attributes = params[:user] @user.pref.attributes = params[:pref] @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') - @user.login = params[:login] + #@user.login = params[:login] unless @user.user_extensions.nil? if @user.user_extensions.identity == 2 @user.firstname = params[:enterprise_name] diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 815a44839..1508fc871 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -161,7 +161,7 @@ class WelcomeController < ApplicationController query: @name, type:"most_fields", operator: "or", - fields: ['login', 'firstname','lastname','name','description^0.5','filename'] + fields: ['login', 'firstname','lastname','name','description^0.5','filename','subject','content^0.5'] } }, highlight: { @@ -173,10 +173,12 @@ class WelcomeController < ApplicationController lastname: {}, name:{}, description:{}, - filename:{} + filename:{}, + subject:{}, + content:{} } } - },[User,Course,Attachment,Project] ).page(params[:page] || 1).per(20).results + },[User,Course,Attachment,Project,Memo] ).page(params[:page] || 1).per(20).results when 'user' @users = User.search(@name).page(params[:page] || 1).per(20) when 'project' @@ -185,6 +187,8 @@ class WelcomeController < ApplicationController @courses = Course.search(@name).page(params[:page] || 1).per(20).results when 'attachment' @attachments = Attachment.search(@name).page(params[:page] || 1).per(20).results + when 'memo' + @memos = Memo.search(@name).page(params[:page] || 1).per(20).results else @alls = Elasticsearch::Model.search({ query: { @@ -192,7 +196,7 @@ class WelcomeController < ApplicationController query: @name, type:"most_fields", operator: "or", - fields: ['login', 'firstname','lastname','name','description^0.5','filename'] + fields: ['login', 'firstname','lastname','name','description^0.5','filename','subject','content^0.5'] } }, highlight: { @@ -204,10 +208,12 @@ class WelcomeController < ApplicationController lastname: {}, name:{}, description:{}, - filename:{} + filename:{}, + subject:{}, + content:{} } } - },[User,Course,Attachment,Project] ).page(params[:page] || 1).per(20).results + },[User,Course,Attachment,Project,Memo] ).page(params[:page] || 1).per(20).results end @@ -216,13 +222,14 @@ class WelcomeController < ApplicationController @course_count = Course.search(@name).results.total @attach_count = Attachment.search(@name).results.total @project_count = Project.search(@name).results.total + @memo_count = Memo.search(@name).results.total @total_count = Elasticsearch::Model.search({ query: { multi_match: { query: @name, type:"most_fields", operator: "or", - fields: ['login', 'firstname','lastname','name','description^0.5','filename'] + fields: ['login', 'firstname','lastname','name','description^0.5','filename','subject','content^0.5'] } }, highlight: { @@ -234,10 +241,12 @@ class WelcomeController < ApplicationController lastname: {}, name:{}, description:{}, - filename:{} + filename:{}, + subject:{}, + content:{} } } - },[User,Course,Attachment,Project] ).results.total + },[User,Course,Attachment,Project,Memo] ).results.total # search_type = params[:search_type].to_sym unless search_condition.blank? # search_by = params[:search_by] # diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 999cefdaa..8d4a1a524 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -46,7 +46,7 @@ class Attachment < ActiveRecord::Base settings index: { number_of_shards: 5 } do mappings dynamic: 'false' do indexes :filename, analyzer: 'smartcn',index_options: 'offsets' - indexes :downloads, analyzer: 'smartcn',index_options: 'offsets' + indexes :downloads, index:"not_analyzed",index_options: 'offsets' end end diff --git a/app/models/course.rb b/app/models/course.rb index 1c1bedb3b..d7ca1387c 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -16,7 +16,7 @@ class Course < ActiveRecord::Base mappings dynamic: 'false' do indexes :name, analyzer: 'smartcn',index_options: 'offsets' indexes :description, analyzer: 'smartcn',index_options: 'offsets' - indexes :updated_at, analyzer: 'smartcn',index_options: 'offsets',type:"date" + indexes :updated_at, index:"not_analyzed",type:"date" end end diff --git a/app/models/memo.rb b/app/models/memo.rb index 7c4fbdcf1..2ead1cbb6 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -1,7 +1,9 @@ +require 'elasticsearch/model' class Memo < ActiveRecord::Base include Redmine::SafeAttributes include UserScoreHelper include ApplicationHelper + include Elasticsearch::Model belongs_to :forum has_many_kindeditor_assets :assets, :dependent => :destroy belongs_to :author, :class_name => "User", :foreign_key => 'author_id' @@ -12,6 +14,18 @@ class Memo < ActiveRecord::Base validates_length_of :content, maximum: 30000 validate :cannot_reply_to_locked_topic, :on => :create + + #elasticsearch kaminari init + Kaminari::Hooks.init + Elasticsearch::Model::Response::Response.__send__ :include, Elasticsearch::Model::Response::Pagination::Kaminari + settings index: { number_of_shards: 5 } do + mappings dynamic: 'false' do + indexes :subject, analyzer: 'smartcn',index_options: 'offsets' + indexes :content, analyzer: 'smartcn',index_options: 'offsets' + indexes :updated_at,index:"not_analyzed" ,type:'date' + end + end + acts_as_tree :counter_cache => :replies_count, :order => "#{Memo.table_name}.created_at ASC" acts_as_attachable has_many :user_score_details, :class_name => 'UserScoreDetails',:as => :score_changeable_obj @@ -47,9 +61,9 @@ class Memo < ActiveRecord::Base "parent_id", "replies_count" - after_create :add_author_as_watcher, :reset_counters!, :send_mail, :send_message - # after_update :update_memos_forum - after_destroy :reset_counters!,:delete_kindeditor_assets#,:down_user_score -- 公共区发帖暂不计入得分 + after_create :add_author_as_watcher, :reset_counters!, :send_mail, :send_message,:create_memo_ealasticsearch_index + after_update :update_memo_ealasticsearch_index + after_destroy :reset_counters!,:delete_kindeditor_assets,:delete_memo_ealasticsearch_index#,:down_user_score -- 公共区发帖暂不计入得分, # after_create :send_notification # after_save :plusParentAndForum # after_destroy :minusParentAndForum @@ -57,6 +71,36 @@ class Memo < ActiveRecord::Base # scope :visible, lambda { |*args| # includes(:forum => ).where() # } + scope :indexable,lambda { + where('parent_id is null') + } + + def self.search(query) + __elasticsearch__.search( + { + query: { + multi_match: { + query: query, + type:"most_fields", + operator: "or", + fields: ['subject','content^0.5'] + } + }, + sort: { + _score:{order: "desc" }, + updated_at:{order: "desc" } + }, + highlight: { + pre_tags: [''], + post_tags: [''], + fields: { + subject: {}, + content: {} + } + } + } + ) + end def send_mail Mailer.run.forum_message_added(self) if Setting.notified_events.include?('forum_message_added') @@ -203,6 +247,22 @@ class Memo < ActiveRecord::Base # Author lizanle # Description 从硬盘上删除资源 def delete_kindeditor_assets - delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::MEMO + delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::MEMO + end + + def create_memo_ealasticsearch_index + if self.parent_id.nil? + self.__elasticsearch__.index_document + end + end + def update_memo_ealasticsearch_index + if self.parent_id.nil? + self.__elasticsearch__.update_document + end + end + def delete_memo_ealasticsearch_index + if self.parent_id.nil? + self.__elasticsearch__.delete_document + end end end diff --git a/app/models/project.rb b/app/models/project.rb index 44b9a7912..cd4036810 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -39,7 +39,7 @@ class Project < ActiveRecord::Base mappings dynamic: 'false' do indexes :name, analyzer: 'smartcn',index_options: 'offsets' indexes :description, analyzer: 'smartcn',index_options: 'offsets' - indexes :updated_on, analyzer: 'smartcn',index_options: 'offsets', type:'date' + indexes :updated_on, index:"not_analyzed", type:'date' end end diff --git a/app/models/user.rb b/app/models/user.rb index 1c5d1b0c8..8e2c096de 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -35,7 +35,7 @@ class User < Principal indexes :login, analyzer: 'smartcn',index_options: 'offsets' indexes :firstname, analyzer: 'smartcn',index_options: 'offsets' indexes :lastname, analyzer: 'smartcn',index_options: 'offsets' - indexes :last_login_on, analyzer: 'smartcn',index_options: 'offsets',type: 'date' + indexes :last_login_on, index:"not_analyzed",type: 'date' end end diff --git a/app/views/my/account.html.erb b/app/views/my/account.html.erb index be178607f..fa9171496 100644 --- a/app/views/my/account.html.erb +++ b/app/views/my/account.html.erb @@ -30,7 +30,7 @@
  •   
  • @@ -202,7 +208,7 @@ ">启动作业匿评失败
  • - <%= link_to "作业题目:" + ma.course_message.name, student_work_index_path(:homework => ma.course_message.id), :class => "#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", + <%= link_to truncate(ma.course_message.name,:length=>25)+'(失败原因:提交作品的人数低于2人)', student_work_index_path(:homework => ma.course_message.id), :class => "#{ma.viewed == 0 ? "c_red" : "newsGrey "}", :onmouseover => "message_titile_show($(this),event)", :onmouseout => "message_titile_hide($(this))" %>
  • @@ -213,7 +219,6 @@

    + <% when 'memo'%> + <%end %> <% end %>
    diff --git a/app/views/welcome/_search_memo_results.html.erb b/app/views/welcome/_search_memo_results.html.erb new file mode 100644 index 000000000..c5fe9cc72 --- /dev/null +++ b/app/views/welcome/_search_memo_results.html.erb @@ -0,0 +1,24 @@ +<% unless memos.nil? || memos.empty?%> + <% memos.each do |memo|%> + + <% end %> +
    + <%= paginate memos,:params => {:controller => 'welcome', :action => 'search',:search_type=>'memo'}%> +
    +<% end %> \ No newline at end of file diff --git a/app/views/welcome/search.html.erb b/app/views/welcome/search.html.erb index c25d7bfb1..ca26ba8c3 100644 --- a/app/views/welcome/search.html.erb +++ b/app/views/welcome/search.html.erb @@ -3,7 +3,7 @@ function g(o){return document.getElementById(o);} function HoverLi(n){ //如果有N个标签,就将i<=N; - for(var i=1;i<=5;i++){ + for(var i=1;i<=6;i++){ g('searchBaner_'+i).className='searchBannerNormal'; g('searchContent_'+i).className='undis';g('searchNum_'+i).className="numRed"; g('searchType_'+i).className="fontGrey2 f14"; @@ -28,6 +28,8 @@ search('attachment') }else if(n == 5){ search('project') + }else if(n == 6){ + search('memo') } } @@ -56,6 +58,10 @@ }else if('<%= @search_type%>' == 'project'){ HoverLi(5) $("#searchContent_5").html('<%= escape_javascript(render :partial => 'search_project_results',:locals => {:projects=>@projects})%>'); + }else if('<%= @search_type%>' == 'memo') + { + HoverLi(6) + $("#searchContent_6").html('<%= escape_javascript(render :partial => 'search_memo_results',:locals => {:memos=>@memos})%>'); } }) //如果要做成点击后再转到请将
  • 中的onmouseover 改成 onclick; @@ -76,6 +82,7 @@
  • 课程(<%=@course_count%>)
  • 资源(<%= @attach_count%>)
  • 项目(<%= @project_count%>)
  • +
  • 帖子(<%= @memo_count%>)
  • +
    +
    +
    diff --git a/app/views/welcome/search.js.erb b/app/views/welcome/search.js.erb index c53c5d219..5cb446896 100644 --- a/app/views/welcome/search.js.erb +++ b/app/views/welcome/search.js.erb @@ -9,5 +9,7 @@ $("#searchContent_3").html('<%= escape_javascript(render :partial => 'search_cou $("#searchContent_5").html('<%= escape_javascript(render :partial => 'search_project_results',:locals => {:projects=>@projects})%>'); <% when 'attachment'%> $("#searchContent_4").html('<%= escape_javascript(render :partial => 'search_attachment_results',:locals => {:attachments=>@attachments})%>'); +<% when 'memo'%> +$("#searchContent_6").html('<%= escape_javascript(render :partial => 'search_memo_results',:locals => {:memos=>@memos})%>'); <%else%> <%end %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index db63fe3ee..0ef113d18 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -489,7 +489,7 @@ RedmineApp::Application.routes.draw do post "add_exist_file_to_course" post "add_exist_file_to_project" get 'resource_preview' - post 'rename_resource' + get 'rename_resource' get 'search_user_project' get 'user_resource_type' get 'user_ref_resource_search' diff --git a/lib/tasks/elasticsearch_batch_op.rake b/lib/tasks/elasticsearch_batch_op.rake index fb2c638bc..91c2ddff9 100644 --- a/lib/tasks/elasticsearch_batch_op.rake +++ b/lib/tasks/elasticsearch_batch_op.rake @@ -28,4 +28,11 @@ namespace :importer do ENV['BATCH']='1000' Rake::Task["elasticsearch:import:model"].invoke end + task :importmemo do + ENV['CLASS']='Memo' + ENV['SCOPE']='indexable' + ENV['FORCE']='y' + ENV['BATCH']='1000' + Rake::Task["elasticsearch:import:model"].invoke + end end \ No newline at end of file