From 6ee086548d44d8855bac1ca54e8f19a8e90a7974 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Pi=C4=8Dman?= Date: Fri, 15 May 2015 10:46:13 +0200 Subject: [PATCH] xapian not indexing files/project #388 --- app/models/dmsf_file.rb | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/app/models/dmsf_file.rb b/app/models/dmsf_file.rb index 5460e18a..b3e58e65 100644 --- a/app/models/dmsf_file.rb +++ b/app/models/dmsf_file.rb @@ -81,11 +81,19 @@ class DmsfFile < ActiveRecord::Base existing_file.nil? || existing_file.id == self.id end - acts_as_event :title => Proc.new {|o| "#{o.title} - #{o.name}"}, - :description => Proc.new {|o| o.description }, - :url => Proc.new {|o| {:controller => 'dmsf_files', :action => 'show', :id => o}}, - :datetime => Proc.new {|o| o.updated_at }, - :author => Proc.new {|o| o.last_revision.user } + acts_as_event :title => Proc.new { |o| o.name }, + :description => Proc.new { |o| + desc = Redmine::Search.cache_store.fetch("DmsfFile-#{o.id}") + if desc + Redmine::Search.cache_store.delete("DmsfFile-#{o.id}") + desc + else + o.description + end + }, + :url => Proc.new { |o| {:controller => 'dmsf_files', :action => 'show', :id => o} }, + :datetime => Proc.new { |o| o.updated_at }, + :author => Proc.new { |o| o.last_revision.user } acts_as_searchable :columns => ["#{table_name}.name", "#{DmsfFileRevision}.title", "#{DmsfFileRevision}.description"], :project_key => 'project_id', @@ -177,7 +185,7 @@ class DmsfFile < ActiveRecord::Base end def description - self.last_revision ? self.last_revision.description : '' + self.last_revision ? self.last_revision.description : '' end def version @@ -394,9 +402,9 @@ class DmsfFile < ActiveRecord::Base end if user.allowed_to?(:view_dmsf_files, dmsf_file.project) && - (project_ids.empty? || (project_ids.include?(dmsf_file.project.id))) - # TODO: It works no more :-( - #dmsf_file.last_revision.description = dochash['sample'].force_encoding('UTF-8') if dochash['sample'] + (project_ids.empty? || (project_ids.include?(dmsf_file.project.id))) + Redmine::Search.cache_store.write("DmsfFile-#{dmsf_file.id}", + dochash['sample'].force_encoding('UTF-8')) if dochash['sample'] results << dmsf_file end end