プラグインDMSFの検索エンジンをHyper Estraierへ替える について
Added by Anonymous about 12 years ago
はじめまして。どこに質問すれば良いかもわからぬ初心者なのですが、
Scimpr(さん?) Blog の
Redmine2.0のDMSFファイルをHyper Estraierで全文検索
を見て、DMSFファイルを全文検索したいと思い、挑戦していますがうまくいきません。
上記Blogの元になっているのがこちらのWikiにあります
プラグインDMSFの検索エンジンをHyper Estraierへ替える
でしたので、こちらに質問させていただきました。Wiki書いてある通りに変更したつもりなのですが、検索結果はゼロとなってしまいます。
環境は以下の通りです。
Centos6.3
Redmine2.1.0
redmine_dmsf1.4.5
・Hyper Estraier単体としては、コマンドでインデックスの作成、検索ができるので、正常と思います。
・Rubyのサンプルプログラムでも検索できているので、Rubyからの制御もできていると思います。
Redmineの検索機能が働いていないと考えられ、database.nil以下の変更で、
filename = uri.sub(/.*\//, '')
以降(Wikiでは修正対象外)に問題があるのではと思っているのですが、具体的にどこがマズイのか分かりません。
変更後のコードが下記です。勝手なお願いですが、もし何か分かることがあれば教えてください。
app/models/dmsf_file.rb の database.nil 以下
unless database.nil? # create a search condition object cond = Estraier::Condition::new # set the search phrase to the search condition object queryString = tokens.join(options[:all_words] ? ' AND ': ' OR ') cond.set_phrase(queryString ) # get the result of search result = database.search(cond) if result # for each document in the result dnum = result.doc_num for i in 0...dnum # retrieve the document object doc = database.get_doc(result.get_doc_id(i), 0) next unless doc # display attributes uri = doc.attr("@uri") if uri filename = uri.sub(/.*\//, '') #dmsf_attrs = filename.split("_") #next if dmsf_attrs[1].blank? #next unless results.select{|f| f.id.to_s == dmsf_attrs[1]}.empty? dmsf_attrs = filename.scan(/^([^\/]+\/[^_]+)_([\d]+)_(.*)$/) id_attribute = 0 id_attribute = dmsf_attrs[0][1] if dmsf_attrs.length > 0 next if dmsf_attrs.length == 0 || id_attribute == 0 next unless results.select{|f| f.id.to_s == id_attribute}.empty? dmsf_file = DmsfFile.where(limit_options[:conditions]).where(:id => id_attribute, :deleted => false).first if !dmsf_file.nil? if options[:offset] if options[:before] next if dmsf_file.updated_at < options[:offset] else next if dmsf_file.updated_at > options[:offset] end end allowed = User.current.allowed_to?(:view_dmsf_files, dmsf_file.project) project_included = false project_included = true if projects.nil? if !project_included projects.each {|x| project_included = true if x[:id] == dmsf_file.project.id } end if (allowed && project_included) results.push(dmsf_file) results_count += 1 end end end end end # close the database unless database.close Rails.logger.warn(database.err_msg(database.error)) end end # unless database.nil? end [results, results_count] end end
Replies (4)
RE: プラグインDMSFの検索エンジンをHyper Estraierへ替える について - Added by Masanori Machii about 12 years ago
例のWikiを書いたものです.(仕事の合間に)当該コードを見てみます.
RE: プラグインDMSFの検索エンジンをHyper Estraierへ替える について - Added by Nobu Toyofuku about 12 years ago
dmsfプラグインの redmine-2対応版が出ていたことに気づいていませんでした。
提示されたコードの
#dmsf_attrs = filename.split("_") #next if dmsf_attrs[1].blank? #next unless results.select{|f| f.id.to_s == dmsf_attrs[1]}.empty? dmsf_attrs = filename.scan(/^([^\/]+\/[^_]+)_([\d]+)_(.*)$/) id_attribute = 0 id_attribute = dmsf_attrs[0][1] if dmsf_attrs.length > 0 next if dmsf_attrs.length == 0 || id_attribute == 0 next unless results.select{|f| f.id.to_s == id_attribute}.empty? dmsf_file = DmsfFile.where(limit_options[:conditions]).where(:id => id_attribute, :deleted => false).first
の部分を
dmsf_attrs = filename.split("_") next if dmsf_attrs[1].blank? next unless results.select{|f| f.id.to_s == dmsf_attrs[1]}.empty? dmsf_file = DmsfFile.where(limit_options[:conditions]).where(:id => dmsf_attrs[1], :deleted => false).first
に変更したら検索できました。
取りあえずこれで試してみてください。
RE: プラグインDMSFの検索エンジンをHyper Estraierへ替える について - Added by Anonymous about 12 years ago
おおおおお、検索できました!ありがとうございます。これでRedmaineの活用範囲が広がりました。
もっと日本語全文検索機能の追加が簡単になればいいんですけどね。今後RedmineやOSその他の
バージョンアップで同じことになってしまうんでしょうね。
RE: プラグインDMSFの検索エンジンをHyper Estraierへ替える について - Added by Masanori Machii about 12 years ago
すでに 2.x 系が主流になりそうなので,例のWikiを編集し直します.社内にテスト環境を作ってからですが.