xapian not indexing files/project #388
This commit is contained in:
parent
ac8f0693e0
commit
cc365c9af4
@ -32,9 +32,6 @@ class DmsfFile < ActiveRecord::Base
|
||||
|
||||
include RedmineDmsf::Lockable
|
||||
|
||||
attr_accessor :event_description
|
||||
attr_accessible :project
|
||||
|
||||
belongs_to :project
|
||||
belongs_to :folder, :class_name => 'DmsfFolder', :foreign_key => 'dmsf_folder_id'
|
||||
belongs_to :deleted_by_user, :class_name => 'User', :foreign_key => 'deleted_by_user_id'
|
||||
@ -90,6 +87,10 @@ class DmsfFile < ActiveRecord::Base
|
||||
: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',
|
||||
:date_column => "#{table_name}.updated_at"
|
||||
|
||||
before_create :default_values
|
||||
def default_values
|
||||
@notifications = Setting.plugin_redmine_dmsf['dmsf_default_notifications']
|
||||
@ -292,21 +293,22 @@ class DmsfFile < ActiveRecord::Base
|
||||
end
|
||||
|
||||
# To fulfill searchable module expectations
|
||||
def self.search(tokens, projects = nil, options = {})
|
||||
def self.search(tokens, user, projects = nil, options = {})
|
||||
tokens = [] << tokens unless tokens.is_a?(Array)
|
||||
projects = [] << projects unless projects.nil? || projects.is_a?(Array)
|
||||
|
||||
find_options = {}
|
||||
find_options[:order] = 'dmsf_files.updated_at ' + (options[:before] ? 'DESC' : 'ASC')
|
||||
|
||||
limit_options = {}
|
||||
limit_options[:limit] = options[:limit] if options[:limit]
|
||||
if options[:offset]
|
||||
limit_options[:conditions] = '(dmsf_files.updated_at ' + (options[:before] ? '<' : '>') + "'#{connection.quoted_date(options[:offset])}')"
|
||||
end
|
||||
|
||||
if options[:titles_only]
|
||||
columns = ['dmsf_file_revisions.title']
|
||||
else
|
||||
columns = %w(dmsf_files.name dmsf_file_revisions.title dmsf_file_revisions.description)
|
||||
columns = ['dmsf_file_revisions.title'] if options[:titles_only]
|
||||
end
|
||||
|
||||
token_clauses = columns.collect {|column| "(LOWER(#{column}) LIKE ?)"}
|
||||
|
||||
@ -314,16 +316,14 @@ class DmsfFile < ActiveRecord::Base
|
||||
find_options[:conditions] = [sql, * (tokens.collect {|w| "%#{w.downcase}%"} * token_clauses.size).sort]
|
||||
|
||||
project_conditions = []
|
||||
project_conditions << Project.allowed_to_condition(User.current, :view_dmsf_files)
|
||||
project_conditions << Project.allowed_to_condition(user, :view_dmsf_files)
|
||||
project_conditions << "#{DmsfFile.table_name}.project_id IN (#{projects.collect(&:id).join(',')})" unless projects.nil?
|
||||
|
||||
results = []
|
||||
results_count = 0
|
||||
|
||||
joins(:project, :revisions).
|
||||
where(project_conditions.join(' AND ') + " AND #{DmsfFile.table_name}.deleted = :false", {:false => false}).scoping do
|
||||
where(find_options[:conditions]).order(find_options[:order]).scoping do
|
||||
results_count = count
|
||||
where(find_options[:conditions]).scoping do
|
||||
results = where(limit_options)
|
||||
end
|
||||
end
|
||||
@ -381,7 +381,7 @@ class DmsfFile < ActiveRecord::Base
|
||||
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_file = DmsfFile.visible.where(limit_options[:conditions]).where(:id => id_attribute).first
|
||||
|
||||
if dmsf_file
|
||||
if options[:offset]
|
||||
@ -392,7 +392,7 @@ class DmsfFile < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
allowed = User.current.allowed_to?(:view_dmsf_files, dmsf_file.project)
|
||||
allowed = user.allowed_to?(:view_dmsf_files, dmsf_file.project)
|
||||
project_included = false
|
||||
project_included = true unless projects
|
||||
unless project_included
|
||||
@ -409,10 +409,10 @@ class DmsfFile < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
if (allowed && project_included)
|
||||
dmsf_file.event_description = dochash['sample'].force_encoding('UTF-8') if dochash['sample']
|
||||
results.push(dmsf_file)
|
||||
results_count += 1
|
||||
if allowed && project_included
|
||||
# TODO: It works no more :-(
|
||||
#dmsf_file.last_revision.description = dochash['sample'].force_encoding('UTF-8') if dochash['sample']
|
||||
results << dmsf_file
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -421,12 +421,12 @@ class DmsfFile < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
[results, results_count]
|
||||
results
|
||||
end
|
||||
|
||||
def self.search_result_ranks_and_ids(tokens, user = User.current, projects = nil, options = {})
|
||||
r = self.search(tokens, projects, options)[0]
|
||||
r.each_index { |x| [x, r[1][x]] }
|
||||
r = self.search(tokens, user, projects, options)
|
||||
r.map{ |f| [f.updated_at.to_i, f.id]}
|
||||
end
|
||||
|
||||
def display_name
|
||||
|
||||
@ -27,8 +27,6 @@ class DmsfFolder < ActiveRecord::Base
|
||||
cattr_reader :invalid_characters
|
||||
@@invalid_characters = /\A[^\/\\\?":<>]*\z/
|
||||
|
||||
attr_accessible :title, :description, :dmsf_folder_id, :project
|
||||
|
||||
belongs_to :project
|
||||
belongs_to :folder, :class_name => 'DmsfFolder', :foreign_key => 'dmsf_folder_id'
|
||||
belongs_to :deleted_by_user, :class_name => 'User', :foreign_key => 'deleted_by_user_id'
|
||||
@ -65,23 +63,20 @@ class DmsfFolder < ActiveRecord::Base
|
||||
:dependent => :destroy
|
||||
end
|
||||
|
||||
if (Rails::VERSION::MAJOR > 3)
|
||||
scope :visible, -> { where(deleted: false) }
|
||||
scope :deleted, -> { where(deleted: true) }
|
||||
else
|
||||
scope :visible, where(:deleted => false)
|
||||
scope :deleted, where(:deleted => true)
|
||||
end
|
||||
scope :visible, lambda { |*args|
|
||||
where(deleted: false)
|
||||
}
|
||||
scope :deleted, lambda { |*args|
|
||||
where(deleted: true)
|
||||
}
|
||||
|
||||
acts_as_customizable
|
||||
|
||||
validates :title, :presence => true
|
||||
validates_uniqueness_of :title, :scope => [:dmsf_folder_id, :project_id, :deleted]
|
||||
|
||||
validates_format_of :title, :with => @@invalid_characters,
|
||||
:message => l(:error_contains_invalid_character)
|
||||
|
||||
validate :check_cycle
|
||||
acts_as_searchable :columns => ["#{self.table_name}.title", "#{self.table_name}.description"],
|
||||
:project_key => 'project_id',
|
||||
:date_column => 'updated_at',
|
||||
:permission => :view_dmsf_files,
|
||||
:scope => self.joins(:project)
|
||||
|
||||
acts_as_event :title => Proc.new {|o| o.title},
|
||||
:description => Proc.new {|o| o.description },
|
||||
@ -89,6 +84,12 @@ class DmsfFolder < ActiveRecord::Base
|
||||
:datetime => Proc.new {|o| o.updated_at },
|
||||
:author => Proc.new {|o| o.user }
|
||||
|
||||
validates :title, :presence => true
|
||||
validates_uniqueness_of :title, :scope => [:dmsf_folder_id, :project_id, :deleted]
|
||||
validates_format_of :title, :with => @@invalid_characters,
|
||||
:message => l(:error_contains_invalid_character)
|
||||
validate :check_cycle
|
||||
|
||||
before_create :default_values
|
||||
def default_values
|
||||
@notifications = Setting.plugin_redmine_dmsf['dmsf_default_notifications']
|
||||
@ -281,49 +282,6 @@ class DmsfFolder < ActiveRecord::Base
|
||||
DmsfFileRevisionCustomField.all
|
||||
end
|
||||
|
||||
# To fullfill searchable module expectations
|
||||
def self.search(tokens, projects = nil, options = {})
|
||||
tokens = [] << tokens unless tokens.is_a?(Array)
|
||||
projects = [] << projects unless projects.nil? || projects.is_a?(Array)
|
||||
|
||||
find_options = {}
|
||||
find_options[:order] = 'dmsf_folders.updated_at ' + (options[:before] ? 'DESC' : 'ASC')
|
||||
|
||||
limit_options = {}
|
||||
limit_options[:limit] = options[:limit] if options[:limit]
|
||||
if options[:offset]
|
||||
limit_options[:conditions] = '(dmsf_folders.updated_at ' + (options[:before] ? '<' : '>') + "'#{connection.quoted_date(options[:offset])}')"
|
||||
end
|
||||
|
||||
columns = options[:titles_only] ? ['dmsf_folders.title'] : ['dmsf_folders.title', 'dmsf_folders.description']
|
||||
|
||||
token_clauses = columns.collect {|column| "(LOWER(#{column}) LIKE ?)"}
|
||||
|
||||
sql = (['(' + token_clauses.join(' OR ') + ')'] * tokens.size).join(options[:all_words] ? ' AND ' : ' OR ')
|
||||
find_options[:conditions] = [sql, * (tokens.collect {|w| "%#{w.downcase}%"} * token_clauses.size).sort]
|
||||
|
||||
project_conditions = []
|
||||
project_conditions << (Project.allowed_to_condition(User.current, :view_dmsf_files))
|
||||
project_conditions << "project_id IN (#{projects.collect(&:id).join(',')})" if projects
|
||||
|
||||
results = []
|
||||
results_count = 0
|
||||
|
||||
joins(:project).
|
||||
where(project_conditions.join(' AND ')).scoping do
|
||||
where(find_options[:conditions]).order(find_options[:order]).scoping do
|
||||
results_count = count
|
||||
results = where(limit_options)
|
||||
end
|
||||
end
|
||||
|
||||
[results, results_count]
|
||||
end
|
||||
|
||||
def self.search_result_ranks_and_ids(tokens, user = User.current, projects = nil, options = {})
|
||||
self.search(tokens, :user => user, :projects => projects, :options => options)
|
||||
end
|
||||
|
||||
def modified
|
||||
last_update = updated_at
|
||||
subfolders.each do |subfolder|
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user