From 3ae376c8ff39492d5cd51e9445b126dd2df89606 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Sat, 17 Apr 2010 21:09:10 -0400 Subject: db_sqltxt, issue with: escaping backslashes (that works for both pgsql & sqlite); missing author and/or title (where called in first heading) --- lib/sisu/v2/db_sqltxt.rb | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'lib/sisu/v2/db_sqltxt.rb') diff --git a/lib/sisu/v2/db_sqltxt.rb b/lib/sisu/v2/db_sqltxt.rb index f120b95f..68e9ef8a 100644 --- a/lib/sisu/v2/db_sqltxt.rb +++ b/lib/sisu/v2/db_sqltxt.rb @@ -62,6 +62,7 @@ module SiSU_DB_text class Prepare def special_character_escape(str) str.gsub!(/'/,"''") #string.gsub!(/'/,"\047") #string.gsub!(/'/,"\\'") + str.gsub!(/(\\)/m,'\1\1') #ok but with warnings, double backslash on sqlite #str.gsub!(/[\\]/m,'\\x5C') #ok but with warnings, but not for sqlite #str.gsub!(/(\\)/m,'\1') #ok for sqlite not for pgsql str.gsub!(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,"
\n") str.gsub!(/#{Mx[:tag_o]}\S+?#{Mx[:tag_c]}/,'') #check str.gsub!(/#{Mx[:lnk_o]}\s*(\S+?\.(?:png|jpg))(?:\s+\d+x\d+)?(.+?)#{Mx[:lnk_c]}\S+/,'[image: \1] \2') @@ -76,8 +77,22 @@ module SiSU_DB_text s.gsub!(/^(?:group|poem|code)\{/,''); s.gsub!(/^\}(?:group|poem|code)/,'') s.gsub!(/\A(?:@\S+:\s+.+)\Z/m,'') if s =~/^:A~/ - s.gsub!(/@author/,@md.creator.author) - s.gsub!(/@title/,@md.title.full) + if defined? @md.creator \ + and defined? @md.creator.author \ + and not @md.creator.author.empty? + s.gsub!(/@author/,@md.creator.author) + else + tell=SiSU_Screen::Ansi.new('v','WARNING Document Author information missing; provide @creator: :author:') + tell.warn + end + if defined? @md.title \ + and defined? @md.title.full \ + and not @md.title.full.empty? + s.gsub!(/@title/,@md.title.full) + else + tell=SiSU_Screen::Ansi.new('v','WARNING Document Title missing; provide @title:') + tell.warn + end end s.gsub!(/^(?:_[1-9]\*?|_\*)\s+/,'') s.gsub!(/^(?:[1-9]\~(\S+)?)\s+/,'') -- cgit v1.2.3 From 63c5a3cead1fb5cbd9b1bff653f269dce8d8052c Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Tue, 20 Apr 2010 19:01:55 -0400 Subject: db name, tables, columns, indexes changes, review (need another version bump 2.2.0) * db (sql) table structure, further review and changes (hence breakage & version bump) * new pgsql db name prefix "sisu_v2b_" * new table column words in doc_objects & endnotes, VARCHAR 3000 to contain list of unique sorted words in object * increase use of VARCHAR * constants takes on related additions * param, extensive db column size checks for metadata --- lib/sisu/v2/db_sqltxt.rb | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'lib/sisu/v2/db_sqltxt.rb') diff --git a/lib/sisu/v2/db_sqltxt.rb b/lib/sisu/v2/db_sqltxt.rb index 68e9ef8a..17a92683 100644 --- a/lib/sisu/v2/db_sqltxt.rb +++ b/lib/sisu/v2/db_sqltxt.rb @@ -72,9 +72,10 @@ module SiSU_DB_text end def clean_searchable_text(arr) #produce clean, searchable, plaintext from document source txt_arr,en=[],[] + arr=arr.class==String ? arr.split(/\n+/m) : arr arr.each do |s| - s.gsub!(/([*\/_-])\{(.+?)\}\1/,'\2') - s.gsub!(/^(?:group|poem|code)\{/,''); s.gsub!(/^\}(?:group|poem|code)/,'') + s.gsub!(/([*\/_-])\{(.+?)\}\1/m,'\2') + s.gsub!(/^(?:group|poem|code)\{/m,''); s.gsub!(/^\}(?:group|poem|code)/m,'') s.gsub!(/\A(?:@\S+:\s+.+)\Z/m,'') if s =~/^:A~/ if defined? @md.creator \ @@ -82,26 +83,26 @@ module SiSU_DB_text and not @md.creator.author.empty? s.gsub!(/@author/,@md.creator.author) else - tell=SiSU_Screen::Ansi.new('v','WARNING Document Author information missing; provide @creator: :author:') - tell.warn + tell=SiSU_Screen::Ansi.new('v','WARNING Document Author information missing; provide @creator: :author:',@md.fnb) + tell.warn unless @md.cmd.inspect =~/q/ end if defined? @md.title \ and defined? @md.title.full \ and not @md.title.full.empty? s.gsub!(/@title/,@md.title.full) else - tell=SiSU_Screen::Ansi.new('v','WARNING Document Title missing; provide @title:') - tell.warn + tell=SiSU_Screen::Ansi.new('v','WARNING Document Title missing; provide @title:',@md.fnb) + tell.warn unless @md.cmd.inspect =~/q/ end end - s.gsub!(/^(?:_[1-9]\*?|_\*)\s+/,'') - s.gsub!(/^(?:[1-9]\~(\S+)?)\s+/,'') - s.gsub!(/^(?::?[A-C]\~(\S+)?)\s+/,'') - s.gsub!(/^%{1,3} .+/,'') #removed even if contained in code block - s.gsub!(/
/,' ') - en << s.scan(/~\{\s*(.+?)\s*\}~/) - s.gsub!(/~\{.+?\}~/,'') - s.gsub!(/ \s+/,' ') + s.gsub!(/^(?:_[1-9]\*?|_\*)\s+/m,'') + s.gsub!(/^(?:[1-9]\~(\S+)?)\s+/m,'') + s.gsub!(/^(?::?[A-C]\~(\S+)?)\s+/m,'') + s.gsub!(/^%{1,3} .+/m,'') #removed even if contained in code block + s.gsub!(/
/m,' ') + en << s.scan(/~\{\s*(.+?)\s*\}~/m) + s.gsub!(/~\{.+?\}~/m,'') + s.gsub!(/ \s+/m,' ') #special_character_escape(s) s end @@ -124,6 +125,11 @@ module SiSU_DB_text str.strip! str end + def unique_words(str) + a=str.scan(/[a-zA-Z0-9\\\/_-]{2,}/) #a=str.scan(/\S+{2,}/) + str=a.uniq.sort.join(' ') + str + end end end __END__ -- cgit v1.2.3