* 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
|
||||
|
||||
def download_file
|
||||
@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
|
||||
if @file.deleted
|
||||
render_404
|
||||
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
|
||||
|
||||
def download_revision
|
||||
|
||||
@ -278,17 +278,19 @@ class DmsfDetailController < ApplicationController
|
||||
end
|
||||
|
||||
if new_revision.save
|
||||
new_revision.copy_file_content(file_upload)
|
||||
file_upload.close
|
||||
File.delete(commited_disk_filepath)
|
||||
|
||||
if file.locked?
|
||||
DmsfFileLock.file_lock_state(file, false)
|
||||
flash[:notice] = l(:notice_file_unlocked)
|
||||
end
|
||||
file.save
|
||||
file.save!
|
||||
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)
|
||||
else
|
||||
failed_uploads.push(commited_file)
|
||||
|
||||
@ -189,69 +189,77 @@ class DmsfFile < ActiveRecord::Base
|
||||
end
|
||||
|
||||
if !options[:titles_only] && $xapian_bindings_available
|
||||
database = Xapian::Database.new(Setting.plugin_redmine_dmsf["dmsf_index_database"].strip)
|
||||
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
|
||||
database = nil
|
||||
begin
|
||||
database = Xapian::Database.new(Setting.plugin_redmine_dmsf["dmsf_index_database"].strip)
|
||||
rescue
|
||||
Rails.logger.warn "REDMAIN_XAPIAN ERROR: Xapian database is not properly set or initiated or is corrupted."
|
||||
end
|
||||
|
||||
if options[:all_words]
|
||||
qp.default_op = Xapian::Query::OP_AND
|
||||
else
|
||||
qp.default_op = Xapian::Query::OP_OR
|
||||
end
|
||||
unless database.nil?
|
||||
enquire = Xapian::Enquire.new(database)
|
||||
|
||||
query = qp.parse_query(queryString)
|
||||
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
|
||||
|
||||
enquire.query = query
|
||||
matchset = enquire.mset(0, 1000)
|
||||
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 !matchset.nil?
|
||||
matchset.matches.each {|m|
|
||||
docdata = m.document.data{url}
|
||||
dochash = Hash[*docdata.scan(/(url|sample|modtime|type|size)=\/?([^\n\]]+)/).flatten]
|
||||
filename = dochash["url"]
|
||||
if !filename.nil?
|
||||
dmsf_attrs = filename.split("_")
|
||||
next unless results.select{|f| f.id.to_s == dmsf_attrs[1]}.empty?
|
||||
if options[:all_words]
|
||||
qp.default_op = Xapian::Query::OP_AND
|
||||
else
|
||||
qp.default_op = Xapian::Query::OP_OR
|
||||
end
|
||||
|
||||
find_conditions = DmsfFile.merge_conditions(limit_options[:conditions], :id => dmsf_attrs[1] )
|
||||
dmsf_file = DmsfFile.find(:first, :conditions => find_conditions )
|
||||
query = qp.parse_query(queryString)
|
||||
|
||||
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]
|
||||
enquire.query = query
|
||||
matchset = enquire.mset(0, 1000)
|
||||
|
||||
unless matchset.nil?
|
||||
matchset.matches.each {|m|
|
||||
docdata = m.document.data{url}
|
||||
dochash = Hash[*docdata.scan(/(url|sample|modtime|type|size)=\/?([^\n\]]+)/).flatten]
|
||||
filename = dochash["url"]
|
||||
if !filename.nil?
|
||||
dmsf_attrs = filename.split("_")
|
||||
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 (allowed && project_included)
|
||||
results.push(dmsf_file)
|
||||
results_count += 1
|
||||
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
|
||||
|
||||
|
||||
@ -155,7 +155,7 @@ class DmsfFileRevision < ActiveRecord::Base
|
||||
while File.exist?(File.join(DmsfFile.storage_path, "#{timestamp}_#{self.id}_#{filename}"))
|
||||
timestamp.succ!
|
||||
end
|
||||
"#{timestamp}_#{id}_#{filename}"
|
||||
"#{timestamp}_#{file.id}_#{filename}"
|
||||
end
|
||||
|
||||
def copy_file_content(open_file)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user