* finished Issue 48: Database Error WHen Searching With Redmine Search
* fixed minor errors in fulltext search git-svn-id: http://redmine-dmsf.googlecode.com/svn/trunk/redmine_dmsf@76 5e329b0b-a2ee-ea63-e329-299493fc886d
This commit is contained in:
parent
0c8250220a
commit
f733d05a5b
@ -64,9 +64,13 @@ class DmsfController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def download_file
|
def download_file
|
||||||
@revision = @file.last_revision
|
if @file.deleted
|
||||||
Rails.logger.info "#{Time.now} from #{request.remote_ip}/#{request.env["HTTP_X_FORWARDED_FOR"]}: #{User.current.login} downloaded #{@project.identifier}://#{@file.dmsf_path_str} revision #{@revision.id}"
|
render_404
|
||||||
send_revision
|
else
|
||||||
|
@revision = @file.last_revision
|
||||||
|
Rails.logger.info "#{Time.now} from #{request.remote_ip}/#{request.env["HTTP_X_FORWARDED_FOR"]}: #{User.current.login} downloaded #{@project.identifier}://#{@file.dmsf_path_str} revision #{@revision.id}"
|
||||||
|
send_revision
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def download_revision
|
def download_revision
|
||||||
|
|||||||
@ -278,17 +278,19 @@ class DmsfDetailController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
if new_revision.save
|
if new_revision.save
|
||||||
new_revision.copy_file_content(file_upload)
|
|
||||||
file_upload.close
|
|
||||||
File.delete(commited_disk_filepath)
|
|
||||||
|
|
||||||
if file.locked?
|
if file.locked?
|
||||||
DmsfFileLock.file_lock_state(file, false)
|
DmsfFileLock.file_lock_state(file, false)
|
||||||
flash[:notice] = l(:notice_file_unlocked)
|
flash[:notice] = l(:notice_file_unlocked)
|
||||||
end
|
end
|
||||||
file.save
|
file.save!
|
||||||
file.reload
|
file.reload
|
||||||
|
|
||||||
|
# Need to save file first to generate id for it in case of creation.
|
||||||
|
# File id is needed to properly generate revision disk filename
|
||||||
|
new_revision.copy_file_content(file_upload)
|
||||||
|
file_upload.close
|
||||||
|
File.delete(commited_disk_filepath)
|
||||||
|
|
||||||
files.push(file)
|
files.push(file)
|
||||||
else
|
else
|
||||||
failed_uploads.push(commited_file)
|
failed_uploads.push(commited_file)
|
||||||
|
|||||||
@ -189,70 +189,78 @@ class DmsfFile < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
if !options[:titles_only] && $xapian_bindings_available
|
if !options[:titles_only] && $xapian_bindings_available
|
||||||
database = Xapian::Database.new(Setting.plugin_redmine_dmsf["dmsf_index_database"].strip)
|
database = nil
|
||||||
enquire = Xapian::Enquire.new(database)
|
begin
|
||||||
|
database = Xapian::Database.new(Setting.plugin_redmine_dmsf["dmsf_index_database"].strip)
|
||||||
queryString = tokens.join(' ')
|
rescue
|
||||||
qp = Xapian::QueryParser.new()
|
Rails.logger.warn "REDMAIN_XAPIAN ERROR: Xapian database is not properly set or initiated or is corrupted."
|
||||||
stemmer = Xapian::Stem.new(Setting.plugin_redmine_dmsf['dmsf_stemming_lang'].strip)
|
|
||||||
qp.stemmer = stemmer
|
|
||||||
qp.database = database
|
|
||||||
|
|
||||||
case Setting.plugin_redmine_dmsf['dmsf_stemming_strategy'].strip
|
|
||||||
when "STEM_NONE" then qp.stemming_strategy = Xapian::QueryParser::STEM_NONE
|
|
||||||
when "STEM_SOME" then qp.stemming_strategy = Xapian::QueryParser::STEM_SOME
|
|
||||||
when "STEM_ALL" then qp.stemming_strategy = Xapian::QueryParser::STEM_ALL
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if options[:all_words]
|
|
||||||
qp.default_op = Xapian::Query::OP_AND
|
|
||||||
else
|
|
||||||
qp.default_op = Xapian::Query::OP_OR
|
|
||||||
end
|
|
||||||
|
|
||||||
query = qp.parse_query(queryString)
|
|
||||||
|
|
||||||
enquire.query = query
|
unless database.nil?
|
||||||
matchset = enquire.mset(0, 1000)
|
enquire = Xapian::Enquire.new(database)
|
||||||
|
|
||||||
|
queryString = tokens.join(' ')
|
||||||
|
qp = Xapian::QueryParser.new()
|
||||||
|
stemmer = Xapian::Stem.new(Setting.plugin_redmine_dmsf['dmsf_stemming_lang'].strip)
|
||||||
|
qp.stemmer = stemmer
|
||||||
|
qp.database = database
|
||||||
|
|
||||||
|
case Setting.plugin_redmine_dmsf['dmsf_stemming_strategy'].strip
|
||||||
|
when "STEM_NONE" then qp.stemming_strategy = Xapian::QueryParser::STEM_NONE
|
||||||
|
when "STEM_SOME" then qp.stemming_strategy = Xapian::QueryParser::STEM_SOME
|
||||||
|
when "STEM_ALL" then qp.stemming_strategy = Xapian::QueryParser::STEM_ALL
|
||||||
|
end
|
||||||
|
|
||||||
|
if options[:all_words]
|
||||||
|
qp.default_op = Xapian::Query::OP_AND
|
||||||
|
else
|
||||||
|
qp.default_op = Xapian::Query::OP_OR
|
||||||
|
end
|
||||||
|
|
||||||
|
query = qp.parse_query(queryString)
|
||||||
|
|
||||||
if !matchset.nil?
|
enquire.query = query
|
||||||
matchset.matches.each {|m|
|
matchset = enquire.mset(0, 1000)
|
||||||
docdata = m.document.data{url}
|
|
||||||
dochash = Hash[*docdata.scan(/(url|sample|modtime|type|size)=\/?([^\n\]]+)/).flatten]
|
unless matchset.nil?
|
||||||
filename = dochash["url"]
|
matchset.matches.each {|m|
|
||||||
if !filename.nil?
|
docdata = m.document.data{url}
|
||||||
dmsf_attrs = filename.split("_")
|
dochash = Hash[*docdata.scan(/(url|sample|modtime|type|size)=\/?([^\n\]]+)/).flatten]
|
||||||
next unless results.select{|f| f.id.to_s == dmsf_attrs[1]}.empty?
|
filename = dochash["url"]
|
||||||
|
if !filename.nil?
|
||||||
find_conditions = DmsfFile.merge_conditions(limit_options[:conditions], :id => dmsf_attrs[1] )
|
dmsf_attrs = filename.split("_")
|
||||||
dmsf_file = DmsfFile.find(:first, :conditions => find_conditions )
|
next unless results.select{|f| f.id.to_s == dmsf_attrs[1]}.empty?
|
||||||
|
|
||||||
|
find_conditions = DmsfFile.merge_conditions(limit_options[:conditions], :id => dmsf_attrs[1], :deleted => false )
|
||||||
|
dmsf_file = DmsfFile.find(:first, :conditions => find_conditions )
|
||||||
|
|
||||||
|
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 !dmsf_file.nil?
|
if (allowed && project_included)
|
||||||
if options[:offset]
|
results.push(dmsf_file)
|
||||||
if options[:before]
|
results_count += 1
|
||||||
next if dmsf_file.updated_at < options[:offset]
|
|
||||||
else
|
|
||||||
next if dmsf_file.updated_at > options[:offset]
|
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
[results, results_count]
|
[results, results_count]
|
||||||
|
|||||||
@ -155,7 +155,7 @@ class DmsfFileRevision < ActiveRecord::Base
|
|||||||
while File.exist?(File.join(DmsfFile.storage_path, "#{timestamp}_#{self.id}_#{filename}"))
|
while File.exist?(File.join(DmsfFile.storage_path, "#{timestamp}_#{self.id}_#{filename}"))
|
||||||
timestamp.succ!
|
timestamp.succ!
|
||||||
end
|
end
|
||||||
"#{timestamp}_#{id}_#{filename}"
|
"#{timestamp}_#{file.id}_#{filename}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def copy_file_content(open_file)
|
def copy_file_content(open_file)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user