aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v2/db_sqltxt.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sisu/v2/db_sqltxt.rb')
-rw-r--r--lib/sisu/v2/db_sqltxt.rb45
1 files changed, 33 insertions, 12 deletions
diff --git a/lib/sisu/v2/db_sqltxt.rb b/lib/sisu/v2/db_sqltxt.rb
index f120b95f..17a92683 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]}/,"<br />\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')
@@ -71,22 +72,37 @@ 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~/
- 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:',@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:',@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!(/<br>/,' ')
- 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!(/<br>/m,' ')
+ en << s.scan(/~\{\s*(.+?)\s*\}~/m)
+ s.gsub!(/~\{.+?\}~/m,'')
+ s.gsub!(/ \s+/m,' ')
#special_character_escape(s)
s
end
@@ -109,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__