Skip to content

Instantly share code, notes, and snippets.

@akiko-pusu
Last active August 28, 2018 06:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akiko-pusu/62cb2e726da685b32ed08c9394d2ff27 to your computer and use it in GitHub Desktop.
Save akiko-pusu/62cb2e726da685b32ed08c9394d2ff27 to your computer and use it in GitHub Desktop.
FullTextSearch Pluginの検証
require_dependency "full_text_search/hooks/search_index_options_content_bottom_hook"
require_dependency "full_text_search/hooks/issues_show_description_bottom_hook"
require_dependency "full_text_search/hooks/similar_issues_helper"
# これも追加?
require_dependency "full_text_search/hooks/search_helper"
require "full_text_search/searcher"
Redmine::Plugin.register :full_text_search do
name 'Full Text Search plugin'
author 'Kenji Okimoto'
description 'This plugin provides full text search for Redmine'
version '0.7.2'
url 'https://github.com/okkez/redmine_full_text_search'
author_url 'https://github.com/okkez/redmine_full_text_search'
settings default: { display_score: "0" }, partial: "settings/full_text_search"
end
Rails.configuration.to_prepare do
case
when Redmine::Database.postgresql?
require "full_text_search/pgroonga"
FullTextSearch::SearcherRecord.prepend(FullTextSearch::PGroonga)
when Redmine::Database.mysql?
require "full_text_search/mroonga"
FullTextSearch::SearcherRecord.prepend(FullTextSearch::Mroonga)
else
# Do nothing
end
[Project, News, Issue, Document, Changeset, Message, Journal, WikiPage, WikiContent, CustomValue, Attachment].each do |klass|
klass.include(FullTextSearch::Model)
end
Issue.include(FullTextSearch::SimilarSearcher::Model)
Journal.include(FullTextSearch::SimilarSearcher::Model)
# SearchHelper.prepend(FullTextSearch::Hooks::SearchHelper) # ここをコメントアウト
SearchController.prepend(FullTextSearch::Hooks::ControllerSearchIndex)
# IssuesHelper.include(FullTextSearch::Hooks::SimilarIssuesHelper) # ここをコメントアウト
end
module FullTextSearch
module Hooks
module SearchHelper
include FullTextSearch::Hooks::SettingsHelper
# Overwrite SearchHelper#render_results_by_type to add order_target and order_type
def render_results_by_type(results_by_type)
links = []
# Sorts types by results count
results_by_type.keys.sort {|a, b| results_by_type[b] <=> results_by_type[a]}.each do |t|
c = results_by_type[t]
next if c == 0
text = "#{type_label(t)} (#{c})"
links << link_to(h(text),
:q => params[:q],
:titles_only => params[:titles_only],
:all_words => params[:all_words],
:scope => params[:scope],
:order_target => params[:order_target],
:order_type => params[:order_type],
t => 1)
end
('<ul>'.html_safe +
links.map {|link| content_tag('li', link)}.join(' ').html_safe +
'</ul>'.html_safe) unless links.empty?
end
end
end
end
# init.rb の代わりにここを追加
SearchHelper.prepend(FullTextSearch::Hooks::SearchHelper)
module FullTextSearch
module Hooks
module SimilarIssuesHelper
include FullTextSearch::Hooks::SettingsHelper
def render_similar_issues(issue)
s = '<table class="list issues odd-even">'
issue.similar_issues.each do |similar_issue|
css = "list issue issue-#{similar_issue.id} #{similar_issue.css_classes}"
s << content_tag(
"tr",
content_tag("td", link_to_issue(similar_issue, project: (issue.project_id != similar_issue.project_id)), class: "subject", style: "width: 50%", data: { rank: similar_issue.similarity_score }) +
content_tag("td", h(similar_issue.status), class: "status") +
content_tag("td", link_to_user(similar_issue.assigned_to), class: "assigned_to") +
content_tag("td", similar_issue.disabled_core_fields.include?("done_ratio") ? "" : progress_bar(similar_issue.done_ratio), class: "done_ratio"),
class: css
)
end
s << '</table>'
s.html_safe
end
end
end
end
# この一文をinit.rbの代わりに差し込む
# prepend でOKな場合と、includeでOKな場合とがちょっとわからないので検証しながら
IssuesHelper.prepend(FullTextSearch::Hooks::SimilarIssuesHelper)
@akiko-pusu
Copy link
Author

akiko-pusu commented Aug 28, 2018

init.rb での Helperへのincludeをやめる、もしくはprependにする。
まずはコメントアウト。

IssuesHelper.include(FullTextSearch::Hooks::SimilarIssuesHelper) のところが一番可能性ありなので。。

@yassan
Copy link

yassan commented Aug 28, 2018

上記のようにやってみましたが、500エラーのままで、ログも変わりなかったです

@akiko-pusu
Copy link
Author

了解です!

@yassan
Copy link

yassan commented Aug 28, 2018

redmine_persist_wfmtを維持したまま、full_text_searchの利用が出来ました 🙌
ありがとうございます 🙏

一応環境も載せておきます。

nvironment:
  Redmine version                3.4.6.stable.17473
  Ruby version                   2.3.7-p456 (2018-03-28) [x86_64-linux]
  Rails version                  4.2.8
  Environment                    production
  Database adapter               PostgreSQL
SCM:
  Subversion                     1.7.14
  Git                            2.16.4
  Filesystem                     
Redmine plugins:
  clipboard_image_paste          1.12
  full_text_search               0.7.2
  periodictask                   3.2.1
  redmine_banner                 0.1.2
  redmine_checklists             3.1.11
  redmine_default_custom_query   1.3.0
  redmine_favorite_projects      2.0.3
  redmine_issue_badge            0.0.6
  redmine_issue_templates        0.2.0
  redmine_local_avatars          1.0.3
  redmine_logs                   0.1.1
  redmine_niko_cale              1.1.3-dev
  redmine_people                 1.3.2
  redmine_persist_wfmt           1.1.0
  redmine_pivot_table            0.0.6
  redmine_theme_changer          0.3.1
  redmine_wiki_extensions        0.8.1
  redmine_wiki_lists             0.0.9
  redmine_work_time              0.3.4
  sidebar_hide                   0.0.8
  view_customize                 1.1.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment