aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v5/db_sqltxt.rb
diff options
context:
space:
mode:
authorRalph Amissah <ralph@amissah.com>2014-10-19 21:19:47 -0400
committerRalph Amissah <ralph@amissah.com>2014-10-19 21:19:47 -0400
commitfa19bd4cdb7f9f9db99c99604250ceda77e527a8 (patch)
tree3689106b15c764c720d11fbe6da0d25418094d69 /lib/sisu/v5/db_sqltxt.rb
parentdebian/changelog (5.7.0-1) (diff)
parentv5 v6: cgi, sample search form, find & display endnotes from parent text object (diff)
Merge tag 'sisu_5.7.1' into debian/sid
SiSU 5.7.1
Diffstat (limited to 'lib/sisu/v5/db_sqltxt.rb')
-rw-r--r--lib/sisu/v5/db_sqltxt.rb38
1 files changed, 27 insertions, 11 deletions
diff --git a/lib/sisu/v5/db_sqltxt.rb b/lib/sisu/v5/db_sqltxt.rb
index ffb5966b..3f6cf951 100644
--- a/lib/sisu/v5/db_sqltxt.rb
+++ b/lib/sisu/v5/db_sqltxt.rb
@@ -60,13 +60,13 @@
module SiSU_DbText
class Prepare
def special_character_escape(str)
- str=str.gsub(/'/,"''"). #string.gsub!(/'/,"\047") #string.gsub!(/'/,"\\'")
+ str=str.gsub(/'/m,"''"). #string.gsub!(/'/,"\047") #string.gsub!(/'/,"\\'")
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
- gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,"<br />\n").
- gsub(/#{Mx[:tag_o]}\S+?#{Mx[:tag_c]}/,''). #check
- gsub(/#{Mx[:lnk_o]}\s*(\S+?\.(?:png|jpg))(?:\s+\d+x\d+)?(.+?)#{Mx[:lnk_c]}\S+/,'[image: \1] \2').
- gsub(/#{Mx[:lnk_o]}\s*(.+?)\s*#{Mx[:lnk_c]}(?:file|ftp):\/\/\S+?([.,!?]?(?:\s|$))/,'\1\2').
- gsub(/#{Mx[:lnk_o]}\s*(.+?)\s*#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/,'\1')
+ gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/m,"<br>\n").
+ gsub(/#{Mx[:tag_o]}\S+?#{Mx[:tag_c]}/m,''). #check
+ gsub(/#{Mx[:lnk_o]}\s*(\S+?\.(?:png|jpg))(?:\s+\d+x\d+)?(.+?)#{Mx[:lnk_c]}\S+/m,'[image: \1] \2').
+ gsub(/#{Mx[:lnk_o]}\s*(.+?)\s*#{Mx[:lnk_c]}(?:file|ftp):\/\/\S+?([.,!?]?(?:\s|$))/m,'\1\2').
+ gsub(/#{Mx[:lnk_o]}\s*(.+?)\s*#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m,'\1')
end
def clean_searchable_text_from_document_objects(arr)
txt_arr,en=[],[]
@@ -80,13 +80,29 @@ module SiSU_DbText
gsub(/#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]}/m,'').
gsub(/ \s+/m,' ')
#p s if s =~/[^ \nA-Za-z0-9'"`?!#@$%^&*=+,.;:\[\]()<>{}‹›|\\\/~_-]/
- s
+ txt_arr << s
end
- txt_arr << arr << en
- #txt_arr=txt_arr.flatten
+ txt_arr=txt_arr << en
txt=txt_arr.flatten.join("\n")
- txt=special_character_escape(txt)
- txt
+ special_character_escape(txt)
+ end
+ def clean_document_objects_body(arr)
+ txt_arr,en,en_arr=[],[],[]
+ arr=(arr.is_a?(String)) ? [ arr ] : arr
+ arr.each do |s|
+ en << s.scan(/#{Mx[:en_a_o]}\s*(.+?)\s*#{Mx[:en_a_c]}/m)
+ s=s.gsub(/#{Mx[:en_a_o]}\s*(\d+).+?#{Mx[:en_a_c]}/m,'<sup>\1</sup>').
+ gsub(/#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]}/m,'').
+ gsub(/ \s+/m,' ')
+ txt_arr << s
+ end
+ en.flatten.each do |e|
+ e=e.sub(/^(\d+)\s*/,'<sup>\1</sup> ')
+ en_arr << e
+ end
+ txt_arr=txt_arr << en_arr
+ txt=txt_arr.flatten.join("\n<br>")
+ special_character_escape(txt)
end
def clean_searchable_text_from_document_source(arr)
txt_arr,en=[],[]