From 07f5ed1088c27588fe85df6b4f0d486efd5c827e Mon Sep 17 00:00:00 2001 From: znerol Date: Sat, 14 Nov 2020 18:04:38 +0100 Subject: [PATCH] Switch to query-time boosting --- app/controllers/redsun_search_controller.rb | 10 ++++++++++ lib/redmine_redsun/attachment_patch.rb | 4 ++-- lib/redmine_redsun/issue_patch.rb | 6 +++--- lib/redmine_redsun/journal_patch.rb | 2 +- lib/redmine_redsun/project_patch.rb | 2 +- lib/redmine_redsun/wiki_page_patch.rb | 4 ++-- 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/controllers/redsun_search_controller.rb b/app/controllers/redsun_search_controller.rb index fa1087b..0ab9f16 100644 --- a/app/controllers/redsun_search_controller.rb +++ b/app/controllers/redsun_search_controller.rb @@ -54,6 +54,16 @@ def index highlight :id highlight :title highlight :filename + boost_fields( + :filename => 9, + :subject => 9, + :description => 7, + :comments => 9, + :notes => 9, + :project_name => 10, + :title => 10, + :wiki_content => 8, + ) end any_of do diff --git a/lib/redmine_redsun/attachment_patch.rb b/lib/redmine_redsun/attachment_patch.rb index 584eb9c..6c2cb8e 100644 --- a/lib/redmine_redsun/attachment_patch.rb +++ b/lib/redmine_redsun/attachment_patch.rb @@ -34,7 +34,7 @@ def self.included(base) # :nodoc: end # Filename - text :filename, stored: true, boost: 9 do + text :filename, stored: true do filename.gsub(/[[:cntrl:]]/, ' ').scan(/[[:print:][:space:]]/).join if filename.present? end @@ -92,4 +92,4 @@ def description_for_search end end -end \ No newline at end of file +end diff --git a/lib/redmine_redsun/issue_patch.rb b/lib/redmine_redsun/issue_patch.rb index ba54b55..c84e1ce 100644 --- a/lib/redmine_redsun/issue_patch.rb +++ b/lib/redmine_redsun/issue_patch.rb @@ -31,12 +31,12 @@ def self.included(base) # :nodoc: boolean :is_private, stored: true # Subject - text :subject, stored: true, boost: 9 do + text :subject, stored: true do subject.gsub(/[[:cntrl:]]/, ' ').scan(/[[:print:][:space:]]/).join if subject.present? end # Description - text :description, stored: true, boost: 7 do + text :description, stored: true do description.gsub(/[[:cntrl:]]/, ' ').scan(/[[:print:][:space:]]/).join if description.present? end @@ -44,7 +44,7 @@ def self.included(base) # :nodoc: integer :project_id # Journals entries, i.e. status updates, comments, etc. - text :comments, stored: true, boost: 9 do + text :comments, stored: true do journals.where("journals.notes != ''").map { |j| j.notes.gsub(/[[:cntrl:]]/, ' ').scan(/[[:print:][:space:]]/).join if j.notes.present? }.join(' ') end diff --git a/lib/redmine_redsun/journal_patch.rb b/lib/redmine_redsun/journal_patch.rb index 3985bd5..9d2ccc6 100644 --- a/lib/redmine_redsun/journal_patch.rb +++ b/lib/redmine_redsun/journal_patch.rb @@ -28,7 +28,7 @@ def self.included(base) # :nodoc: end # Notes - text :notes, stored: true, boost: 9 do + text :notes, stored: true do notes.gsub(/[[:cntrl:]]/, ' ').scan(/[[:print:][:space:]]/).join if notes.present? end diff --git a/lib/redmine_redsun/project_patch.rb b/lib/redmine_redsun/project_patch.rb index 2e49b52..a000b7d 100644 --- a/lib/redmine_redsun/project_patch.rb +++ b/lib/redmine_redsun/project_patch.rb @@ -37,7 +37,7 @@ def self.included(base) # :nodoc: end # Name of Project - text :project_name, stored: true, boost: 10 do + text :project_name, stored: true do name.gsub(/[[:cntrl:]]/, ' ').scan(/[[:print:][:space:]]/).join if name.present? end end diff --git a/lib/redmine_redsun/wiki_page_patch.rb b/lib/redmine_redsun/wiki_page_patch.rb index 664dd38..637c8e9 100644 --- a/lib/redmine_redsun/wiki_page_patch.rb +++ b/lib/redmine_redsun/wiki_page_patch.rb @@ -27,12 +27,12 @@ def self.included(base) # :nodoc: end # Page Title - text :title, stored: true, boost: 10 do + text :title, stored: true do title.gsub(/[[:cntrl:]]/, ' ').gsub(/_/, ' ').scan(/[[:print:][:space:]]/).join end # Content of Page - text :wiki_content, stored: true, boost: 8 do + text :wiki_content, stored: true do content.text.gsub(/[[:cntrl:]]/, ' ').scan(/[[:print:][:space:]]/).join unless content.nil? end