From 32c9435430e71c2657bcd2526b4c1d718d466e2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Pi=C4=8Dman?= Date: Tue, 30 May 2023 12:04:49 +0200 Subject: [PATCH] gem xapian-ruby --- Gemfile | 2 ++ app/models/dmsf_file.rb | 23 ++------------ app/views/settings/_dmsf_settings.html.erb | 37 ++++++++-------------- config/locales/cs.yml | 1 - config/locales/de.yml | 1 - config/locales/en.yml | 1 - config/locales/es.yml | 1 - config/locales/fa.yml | 1 - config/locales/fr.yml | 1 - config/locales/hu.yml | 1 - config/locales/it.yml | 1 - config/locales/ja.yml | 1 - config/locales/ko.yml | 1 - config/locales/nl.yml | 1 - config/locales/pl.yml | 1 - config/locales/pt-BR.yml | 1 - config/locales/sl.yml | 1 - config/locales/zh-TW.yml | 1 - config/locales/zh.yml | 1 - extra/xapian_indexer.rb | 4 --- 20 files changed, 19 insertions(+), 63 deletions(-) diff --git a/Gemfile b/Gemfile index 3df41955..5541eab2 100644 --- a/Gemfile +++ b/Gemfile @@ -23,7 +23,9 @@ source 'https://rubygems.org' do gem 'active_record_union' gem 'ox' # Dav4Rack + gem 'rake' gem 'uuidtools' + gem 'xapian-ruby' gem 'zip-zip' # Redmine extensions diff --git a/app/models/dmsf_file.rb b/app/models/dmsf_file.rb index 160851db..273a1c8e 100644 --- a/app/models/dmsf_file.rb +++ b/app/models/dmsf_file.rb @@ -19,6 +19,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +require 'xapian' + # File class DmsfFile < ApplicationRecord include RedmineDmsf::Lockable @@ -80,25 +82,6 @@ class DmsfFile < ApplicationRecord attr_writer :last_revision - class << self - def xapian_bindings_available? - unless @xapian_bindings_available - begin - require 'xapian' - @xapian_bindings_available = true - rescue LoadError => e - Rails.logger.warn do - %{No Xapian search engine interface for Ruby installed => Full-text search won't be available. - Install a ruby-xapian package or an alternative Xapian binding (https://xapian.org).} - end - Rails.logger.warn { e.message } - @xapian_bindings_available = false - end - end - @xapian_bindings_available - end - end - def self.previews_storage_path Rails.root.join 'tmp/dmsf_previews' end @@ -383,7 +366,7 @@ class DmsfFile < ApplicationRecord results = scope.where(find_options).uniq.to_a results.delete_if { |x| !DmsfFolder.permissions?(x.dmsf_folder) } - if !options[:titles_only] && xapian_bindings_available? # $xapian_bindings_available + if !options[:titles_only] database = nil begin lang = Setting.plugin_redmine_dmsf['dmsf_stemming_lang'].strip diff --git a/app/views/settings/_dmsf_settings.html.erb b/app/views/settings/_dmsf_settings.html.erb index 426108ff..b3599f72 100644 --- a/app/views/settings/_dmsf_settings.html.erb +++ b/app/views/settings/_dmsf_settings.html.erb @@ -324,36 +324,24 @@
-<% begin %> - <% require 'xapian' %> - <% xapian_disabled = false %> -<% rescue LoadError => e %> - <% Rails.logger.warn e.message %> - <% xapian_disabled = true %> -<% end %> - <%= l(:label_full_text) %>

<%= content_tag :label, l(:label_index_database) %> - <%= text_field_tag 'settings[dmsf_index_database]', @settings['dmsf_index_database'], disabled: xapian_disabled, - size: 50 %> - <% if xapian_disabled %> - <%= l(:warning_xapian_not_available) %> - <% end %> + <%= text_field_tag 'settings[dmsf_index_database]', @settings['dmsf_index_database'], size: 50 %> <%= l(:label_default) %>: <%= File.expand_path('dmsf_index', Rails.root) %>

-<% stem_langs = %w(danish dutch english finnish french german hungarian italian norwegian portuguese romanian russian spanish swedish turkish) %> +<% stem_langs = %w(danish dutch english finnish french german hungarian italian norwegian portuguese romanian russian + spanish swedish turkish) %>

<%= content_tag :label, l(:label_stemming_language) %> - <%= select_tag 'settings[dmsf_stemming_lang]', options_for_select(stem_langs, @settings['dmsf_stemming_lang']), - disabled: xapian_disabled %> + <%= select_tag 'settings[dmsf_stemming_lang]', options_for_select(stem_langs, @settings['dmsf_stemming_lang']) %> <%= l(:note_possible_values) %>: <%= stem_langs.join(', ') %>. <%= "#{l(:label_default)}: #{stem_langs[2]}" %> @@ -361,12 +349,15 @@

<%= content_tag :label, l(:label_stem_strategy) %> - <%= radio_button_tag 'settings[dmsf_stemming_strategy]', 'STEM_NONE', @settings['dmsf_stemming_strategy'] == 'STEM_NONE', - disabled: xapian_disabled, checked: true %> <%= l(:option_stem_none) %>
- <%= radio_button_tag 'settings[dmsf_stemming_strategy]', 'STEM_SOME', @settings['dmsf_stemming_strategy'] == 'STEM_SOME', - disabled: xapian_disabled %> <%= l(:option_stem_some) %>
- <%= radio_button_tag 'settings[dmsf_stemming_strategy]', 'STEM_ALL', @settings['dmsf_stemming_strategy'] == 'STEM_ALL', - disabled: xapian_disabled %> <%= l(:option_stem_all) %>
+ <%= radio_button_tag 'settings[dmsf_stemming_strategy]', 'STEM_NONE', + @settings['dmsf_stemming_strategy'] == 'STEM_NONE', checked: true %> <%= l(:option_stem_none) %> +
+ <%= radio_button_tag 'settings[dmsf_stemming_strategy]', 'STEM_SOME', + @settings['dmsf_stemming_strategy'] == 'STEM_SOME' %> <%= l(:option_stem_some) %> +
+ <%= radio_button_tag 'settings[dmsf_stemming_strategy]', 'STEM_ALL', + @settings['dmsf_stemming_strategy'] == 'STEM_ALL' %> <%= l(:option_stem_all) %> +
<%= l(:text_stemming_info) %> @@ -374,7 +365,7 @@

<%= content_tag :label, l(:label_enable_cjk_ngrams) %> - <%= check_box_tag 'settings[dmsf_enable_cjk_ngrams]', true, @settings['dmsf_enable_cjk_ngrams'], disabled: xapian_disabled %> + <%= check_box_tag 'settings[dmsf_enable_cjk_ngrams]', true, @settings['dmsf_enable_cjk_ngrams'] %> <%= l(:text_enable_cjk_ngrams) %> diff --git a/config/locales/cs.yml b/config/locales/cs.yml index e9a223cc..88e2a584 100644 --- a/config/locales/cs.yml +++ b/config/locales/cs.yml @@ -179,7 +179,6 @@ cs: error_file_can_not_be_created: Nelze vytvořit soubor v cílové složce error_wrong_zip_encoding: Chybné kódování Zipu - warning_xapian_not_available: Xapian není k dostupný menu_dmsf: DMS # Project tab title label_physical_file_delete: Fyzické smazání souboru user_is_not_project_member: Nejste členem projektu diff --git a/config/locales/de.yml b/config/locales/de.yml index 41504540..6c4b4627 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -176,7 +176,6 @@ de: erstellt werden. error_file_can_not_be_created: Datei kann nicht in dem gewählten Ordner erstellt werden. error_wrong_zip_encoding: Falsche ZIP-Kodierung - warning_xapian_not_available: Xapian steht nicht zur Verfügung menu_dmsf: DMS # Project tab title label_physical_file_delete: Datei physisch löschen user_is_not_project_member: Sie sind kein Projektmitglied diff --git a/config/locales/en.yml b/config/locales/en.yml index 6c02dd99..82675fee 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -179,7 +179,6 @@ en: error_file_can_not_be_created: "Files can't be created in storage directory" error_wrong_zip_encoding: Wrong Zip encoding - warning_xapian_not_available: Xapian not available menu_dmsf: DMS # Project tab title label_physical_file_delete: Physical file delete user_is_not_project_member: You are not a member of the project diff --git a/config/locales/es.yml b/config/locales/es.yml index 1a86063a..9487e7b1 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -179,7 +179,6 @@ es: error_file_can_not_be_created: "El archivo no puede ser creado en el directorio destino" error_wrong_zip_encoding: Codificación erronea de Zip - warning_xapian_not_available: Xapian no disponible menu_dmsf: DMS # Project tab title label_physical_file_delete: Eliminar archivos físicos user_is_not_project_member: No es miemo del proyecto diff --git a/config/locales/fa.yml b/config/locales/fa.yml index 7c1211e5..9c7b3ba6 100644 --- a/config/locales/fa.yml +++ b/config/locales/fa.yml @@ -173,7 +173,6 @@ fa: error_file_can_not_be_created: "پرونده‌ها نمی‌توانند در پوشه‌ی ذخیره‌سازی ساخته شوند." error_wrong_zip_encoding: رمزگذاری اشتباه zip - warning_xapian_not_available: Xapian در دسترس نیست menu_dmsf: اسناد پیش‌رفته # Project tab title label_physical_file_delete: پرونده فیزیکی حذف شود user_is_not_project_member: شما عضو این پروژه نیستید diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 2431c5ac..c86e557f 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -179,7 +179,6 @@ fr: créé error_file_can_not_be_created: "Le fichier n'a pas pu être enregistré dans le répertoire de stockage" error_wrong_zip_encoding: Mauvais jeu de caractères pour la transformation du nom du ZIP - warning_xapian_not_available: Le module Xapian est indisponible menu_dmsf: DMS # Project tab title label_physical_file_delete: Suppression des fichiers user_is_not_project_member: "Vous n'êtes pas un membre du projet" diff --git a/config/locales/hu.yml b/config/locales/hu.yml index 227483a2..d2db82e9 100644 --- a/config/locales/hu.yml +++ b/config/locales/hu.yml @@ -179,7 +179,6 @@ hu: error_file_can_not_be_created: A fájl nem hozható létre a tárolómappában error_wrong_zip_encoding: Nem megfelelő Zip kódolás - warning_xapian_not_available: Xapian nem elérhető menu_dmsf: DMS # Project tab title label_physical_file_delete: Fizikai fájl törölve lett user_is_not_project_member: Ön nem tagja a csoportnak diff --git a/config/locales/it.yml b/config/locales/it.yml index 4297b0fe..1bf3b8d1 100644 --- a/config/locales/it.yml +++ b/config/locales/it.yml @@ -179,7 +179,6 @@ it: # Italian strings thx 2 Matteo Arceci! error_file_can_not_be_created: "Il documento non può essere creato nella cartella di archiviazione" error_wrong_zip_encoding: Errato encoding dello Zip - warning_xapian_not_available: Xapian non disponibile menu_dmsf: Documenti # Project tab title label_physical_file_delete: File fisico eliminato user_is_not_project_member: Non sei un membro del progetto diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 2509b020..98c3edd8 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -179,7 +179,6 @@ ja: error_file_can_not_be_created: ファイルを保存フォルダに作成できません error_wrong_zip_encoding: Zip エンコーディングが正しくありません - warning_xapian_not_available: Xapian は利用できません menu_dmsf: 文書管理 # Project tab title label_physical_file_delete: 物理ファイルの削除 user_is_not_project_member: あなたはプロジェクトのメンバーではありません diff --git a/config/locales/ko.yml b/config/locales/ko.yml index 4a71a004..244e0b1d 100644 --- a/config/locales/ko.yml +++ b/config/locales/ko.yml @@ -179,7 +179,6 @@ ko: error_file_can_not_be_created: 저장 공간에 파일을 생성할 수 없습니다 error_wrong_zip_encoding: 올바르지 않은 Zip 인코딩 - warning_xapian_not_available: Xapian을 사용할 수 없습니다 menu_dmsf: DMS label_physical_file_delete: 파일 삭제됨 user_is_not_project_member: 이 프로젝트의 구성원이 아닙니다 diff --git a/config/locales/nl.yml b/config/locales/nl.yml index 26397a75..c39cb201 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -179,7 +179,6 @@ nl: error_file_can_not_be_created: Bestand kan niet aangemaakt worden in opslag directory error_wrong_zip_encoding: Onjuiste Zip encoding - warning_xapian_not_available: Xapian niet beschikbaar menu_dmsf: Easy DMS label_physical_file_delete: Fysiek bestand verwijderen user_is_not_project_member: U bent geen lid van het project diff --git a/config/locales/pl.yml b/config/locales/pl.yml index efac3539..4484d620 100644 --- a/config/locales/pl.yml +++ b/config/locales/pl.yml @@ -179,7 +179,6 @@ pl: error_file_can_not_be_created: "Plik nie może zostać utworzony w folderze przechowywania" error_wrong_zip_encoding: Złe kodowanie Zip - warning_xapian_not_available: Xapian niedostępny menu_dmsf: DMS # Project tab title label_physical_file_delete: Fizyczne usuwanie plików user_is_not_project_member: Nie jesteś przypisany do tego projektu diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index 2284ffdc..12879f89 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -179,7 +179,6 @@ pt-BR: criado" error_file_can_not_be_created: "O arquivo não pode ser criado" error_wrong_zip_encoding: Código Zip errado - warning_xapian_not_available: Xapian não disponível menu_dmsf: DMS label_physical_file_delete: Excluir fisicamente arquivo user_is_not_project_member: Você não é um membro do projeto diff --git a/config/locales/sl.yml b/config/locales/sl.yml index 3321e7bb..19cc1864 100644 --- a/config/locales/sl.yml +++ b/config/locales/sl.yml @@ -179,7 +179,6 @@ sl: error_file_can_not_be_created: Datoteke se ne da kreirat v mapi error_wrong_zip_encoding: Napačen Zip nabor znakov - warning_xapian_not_available: Xapian ni na voljo menu_dmsf: Arhiv # Project tab title label_physical_file_delete: Brisanje datoteke (fizično) user_is_not_project_member: Niste član projekta diff --git a/config/locales/zh-TW.yml b/config/locales/zh-TW.yml index 6f73938c..bf2dc901 100644 --- a/config/locales/zh-TW.yml +++ b/config/locales/zh-TW.yml @@ -179,7 +179,6 @@ zh-TW: error_file_can_not_be_created: 在存儲目錄裡,無法建立檔案。 error_wrong_zip_encoding: 不正確的Zip encoding - warning_xapian_not_available: Xapian not available menu_dmsf: 文件總管 # Project tab title label_physical_file_delete: 永久刪除檔案 user_is_not_project_member: 您不是專案的成員之一 diff --git a/config/locales/zh.yml b/config/locales/zh.yml index b5392ebd..22300611 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -179,7 +179,6 @@ zh: error_file_can_not_be_created: 文件未能在存储目录中创建 error_wrong_zip_encoding: 不正确的Zip编码 - warning_xapian_not_available: Xapian not available menu_dmsf: 文档管家 # Project tab title label_physical_file_delete: 物理删除文件 user_is_not_project_member: 您不是该项目的成员 diff --git a/extra/xapian_indexer.rb b/extra/xapian_indexer.rb index 7a7d742e..ba3e67e4 100644 --- a/extra/xapian_indexer.rb +++ b/extra/xapian_indexer.rb @@ -125,10 +125,6 @@ end log "Redmine environment [RAILS_ENV=#{env}] correctly loaded ...", verbose # Indexing documents -# unless File.exist?($omindex) -# log "#{$omindex} does not exist, exiting...", true -# exit 1 -# end stem_langs.each do |lang| filespath = Setting.plugin_redmine_dmsf['dmsf_storage_directory'] || File.join(REDMINE_ROOT, FILES) unless File.directory?(filespath)