xapian not indexing files/project #388
This commit is contained in:
parent
ac8f0693e0
commit
cc365c9af4
@ -29,11 +29,8 @@ end
|
|||||||
|
|
||||||
class DmsfFile < ActiveRecord::Base
|
class DmsfFile < ActiveRecord::Base
|
||||||
unloadable
|
unloadable
|
||||||
|
|
||||||
include RedmineDmsf::Lockable
|
include RedmineDmsf::Lockable
|
||||||
|
|
||||||
attr_accessor :event_description
|
|
||||||
attr_accessible :project
|
|
||||||
|
|
||||||
belongs_to :project
|
belongs_to :project
|
||||||
belongs_to :folder, :class_name => 'DmsfFolder', :foreign_key => 'dmsf_folder_id'
|
belongs_to :folder, :class_name => 'DmsfFolder', :foreign_key => 'dmsf_folder_id'
|
||||||
@ -89,6 +86,10 @@ class DmsfFile < ActiveRecord::Base
|
|||||||
:url => Proc.new {|o| {:controller => 'dmsf_files', :action => 'show', :id => o}},
|
:url => Proc.new {|o| {:controller => 'dmsf_files', :action => 'show', :id => o}},
|
||||||
:datetime => Proc.new {|o| o.updated_at },
|
:datetime => Proc.new {|o| o.updated_at },
|
||||||
:author => Proc.new {|o| o.last_revision.user }
|
: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
|
before_create :default_values
|
||||||
def default_values
|
def default_values
|
||||||
@ -177,7 +178,7 @@ class DmsfFile < ActiveRecord::Base
|
|||||||
|
|
||||||
def description
|
def description
|
||||||
self.last_revision ? self.last_revision.description : ''
|
self.last_revision ? self.last_revision.description : ''
|
||||||
end
|
end
|
||||||
|
|
||||||
def version
|
def version
|
||||||
self.last_revision ? self.last_revision.version : '0'
|
self.last_revision ? self.last_revision.version : '0'
|
||||||
@ -292,38 +293,37 @@ class DmsfFile < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
# To fulfill searchable module expectations
|
# 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)
|
tokens = [] << tokens unless tokens.is_a?(Array)
|
||||||
projects = [] << projects unless projects.nil? || projects.is_a?(Array)
|
projects = [] << projects unless projects.nil? || projects.is_a?(Array)
|
||||||
|
|
||||||
find_options = {}
|
find_options = {}
|
||||||
find_options[:order] = 'dmsf_files.updated_at ' + (options[:before] ? 'DESC' : 'ASC')
|
|
||||||
|
|
||||||
limit_options = {}
|
limit_options = {}
|
||||||
limit_options[:limit] = options[:limit] if options[:limit]
|
limit_options[:limit] = options[:limit] if options[:limit]
|
||||||
if options[:offset]
|
if options[:offset]
|
||||||
limit_options[:conditions] = '(dmsf_files.updated_at ' + (options[:before] ? '<' : '>') + "'#{connection.quoted_date(options[:offset])}')"
|
limit_options[:conditions] = '(dmsf_files.updated_at ' + (options[:before] ? '<' : '>') + "'#{connection.quoted_date(options[:offset])}')"
|
||||||
end
|
end
|
||||||
|
|
||||||
columns = %w(dmsf_files.name dmsf_file_revisions.title dmsf_file_revisions.description)
|
if options[:titles_only]
|
||||||
columns = ['dmsf_file_revisions.title'] if options[:titles_only]
|
columns = ['dmsf_file_revisions.title']
|
||||||
|
else
|
||||||
|
columns = %w(dmsf_files.name dmsf_file_revisions.title dmsf_file_revisions.description)
|
||||||
|
end
|
||||||
|
|
||||||
token_clauses = columns.collect {|column| "(LOWER(#{column}) LIKE ?)"}
|
token_clauses = columns.collect {|column| "(LOWER(#{column}) LIKE ?)"}
|
||||||
|
|
||||||
sql = (['(' + token_clauses.join(' OR ') + ')'] * tokens.size).join(options[:all_words] ? ' AND ' : ' OR ')
|
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]
|
find_options[:conditions] = [sql, * (tokens.collect {|w| "%#{w.downcase}%"} * token_clauses.size).sort]
|
||||||
|
|
||||||
project_conditions = []
|
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?
|
project_conditions << "#{DmsfFile.table_name}.project_id IN (#{projects.collect(&:id).join(',')})" unless projects.nil?
|
||||||
|
|
||||||
results = []
|
results = []
|
||||||
results_count = 0
|
|
||||||
|
|
||||||
joins(:project, :revisions).
|
joins(:project, :revisions).
|
||||||
where(project_conditions.join(' AND ') + " AND #{DmsfFile.table_name}.deleted = :false", {:false => false}).scoping do
|
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
|
where(find_options[:conditions]).scoping do
|
||||||
results_count = count
|
|
||||||
results = where(limit_options)
|
results = where(limit_options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -381,7 +381,7 @@ class DmsfFile < ActiveRecord::Base
|
|||||||
next if dmsf_attrs.length == 0 || id_attribute == 0
|
next if dmsf_attrs.length == 0 || id_attribute == 0
|
||||||
next unless results.select{|f| f.id.to_s == id_attribute}.empty?
|
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 dmsf_file
|
||||||
if options[:offset]
|
if options[:offset]
|
||||||
@ -392,7 +392,7 @@ class DmsfFile < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
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 = false
|
||||||
project_included = true unless projects
|
project_included = true unless projects
|
||||||
unless project_included
|
unless project_included
|
||||||
@ -409,10 +409,10 @@ class DmsfFile < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if (allowed && project_included)
|
if allowed && project_included
|
||||||
dmsf_file.event_description = dochash['sample'].force_encoding('UTF-8') if dochash['sample']
|
# TODO: It works no more :-(
|
||||||
results.push(dmsf_file)
|
#dmsf_file.last_revision.description = dochash['sample'].force_encoding('UTF-8') if dochash['sample']
|
||||||
results_count += 1
|
results << dmsf_file
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -420,14 +420,14 @@ class DmsfFile < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
[results, results_count]
|
results
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.search_result_ranks_and_ids(tokens, user = User.current, projects = nil, options = {})
|
def self.search_result_ranks_and_ids(tokens, user = User.current, projects = nil, options = {})
|
||||||
r = self.search(tokens, projects, options)[0]
|
r = self.search(tokens, user, projects, options)
|
||||||
r.each_index { |x| [x, r[1][x]] }
|
r.map{ |f| [f.updated_at.to_i, f.id]}
|
||||||
end
|
end
|
||||||
|
|
||||||
def display_name
|
def display_name
|
||||||
if self.name.length > 50
|
if self.name.length > 50
|
||||||
@ -436,4 +436,4 @@ class DmsfFile < ActiveRecord::Base
|
|||||||
self.name
|
self.name
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -25,9 +25,7 @@ class DmsfFolder < ActiveRecord::Base
|
|||||||
include RedmineDmsf::Lockable
|
include RedmineDmsf::Lockable
|
||||||
|
|
||||||
cattr_reader :invalid_characters
|
cattr_reader :invalid_characters
|
||||||
@@invalid_characters = /\A[^\/\\\?":<>]*\z/
|
@@invalid_characters = /\A[^\/\\\?":<>]*\z/
|
||||||
|
|
||||||
attr_accessible :title, :description, :dmsf_folder_id, :project
|
|
||||||
|
|
||||||
belongs_to :project
|
belongs_to :project
|
||||||
belongs_to :folder, :class_name => 'DmsfFolder', :foreign_key => 'dmsf_folder_id'
|
belongs_to :folder, :class_name => 'DmsfFolder', :foreign_key => 'dmsf_folder_id'
|
||||||
@ -64,31 +62,34 @@ class DmsfFolder < ActiveRecord::Base
|
|||||||
:conditions => {:entity_type => 1},
|
:conditions => {:entity_type => 1},
|
||||||
:dependent => :destroy
|
:dependent => :destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
if (Rails::VERSION::MAJOR > 3)
|
scope :visible, lambda { |*args|
|
||||||
scope :visible, -> { where(deleted: false) }
|
where(deleted: false)
|
||||||
scope :deleted, -> { where(deleted: true) }
|
}
|
||||||
else
|
scope :deleted, lambda { |*args|
|
||||||
scope :visible, where(:deleted => false)
|
where(deleted: true)
|
||||||
scope :deleted, where(:deleted => true)
|
}
|
||||||
end
|
|
||||||
|
|
||||||
acts_as_customizable
|
acts_as_customizable
|
||||||
|
|
||||||
|
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 },
|
||||||
|
:url => Proc.new {|o| {:controller => 'dmsf', :action => 'show', :id => o.project, :folder_id => o}},
|
||||||
|
:datetime => Proc.new {|o| o.updated_at },
|
||||||
|
:author => Proc.new {|o| o.user }
|
||||||
|
|
||||||
validates :title, :presence => true
|
validates :title, :presence => true
|
||||||
validates_uniqueness_of :title, :scope => [:dmsf_folder_id, :project_id, :deleted]
|
validates_uniqueness_of :title, :scope => [:dmsf_folder_id, :project_id, :deleted]
|
||||||
|
|
||||||
validates_format_of :title, :with => @@invalid_characters,
|
validates_format_of :title, :with => @@invalid_characters,
|
||||||
:message => l(:error_contains_invalid_character)
|
:message => l(:error_contains_invalid_character)
|
||||||
|
|
||||||
validate :check_cycle
|
validate :check_cycle
|
||||||
|
|
||||||
acts_as_event :title => Proc.new {|o| o.title},
|
|
||||||
:description => Proc.new {|o| o.description },
|
|
||||||
:url => Proc.new {|o| {:controller => 'dmsf', :action => 'show', :id => o.project, :folder_id => o}},
|
|
||||||
:datetime => Proc.new {|o| o.updated_at },
|
|
||||||
:author => Proc.new {|o| o.user }
|
|
||||||
|
|
||||||
before_create :default_values
|
before_create :default_values
|
||||||
def default_values
|
def default_values
|
||||||
@notifications = Setting.plugin_redmine_dmsf['dmsf_default_notifications']
|
@notifications = Setting.plugin_redmine_dmsf['dmsf_default_notifications']
|
||||||
@ -280,50 +281,7 @@ class DmsfFolder < ActiveRecord::Base
|
|||||||
def available_custom_fields
|
def available_custom_fields
|
||||||
DmsfFileRevisionCustomField.all
|
DmsfFileRevisionCustomField.all
|
||||||
end
|
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
|
def modified
|
||||||
last_update = updated_at
|
last_update = updated_at
|
||||||
subfolders.each do |subfolder|
|
subfolders.each do |subfolder|
|
||||||
@ -364,4 +322,4 @@ class DmsfFolder < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
Loading…
x
Reference in New Issue
Block a user