From 3728a6cef96c96393f295d9b1ca223eb679ac5e6 Mon Sep 17 00:00:00 2001 From: zmagod Date: Mon, 14 Nov 2016 12:32:41 +0100 Subject: [PATCH] fixed sql regex --- app/models/concerns/searchable_model.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/models/concerns/searchable_model.rb b/app/models/concerns/searchable_model.rb index 38728db79..c20be637f 100644 --- a/app/models/concerns/searchable_model.rb +++ b/app/models/concerns/searchable_model.rb @@ -21,13 +21,16 @@ module SearchableModel end if query.is_a? Array + + rich_text_regex = '<*strong>|<*href>|<*div>|' \ + '<*link>|<*span>|<(.*)class(.*)>|<(.*)href(.*)>|' \ + '<(.*)data(.*)>|<*sub>|<*sup>|<*blockquote>|<*li>|' \ + '<(.*)style(.*)>|<*ol>|<*ul>|<*pre>' + if attrs.length > 0 where_str = (attrs.map.with_index do |a, i| - "REGEXP_REPLACE(#{a}, E'<.strong>|<.href>|<.div>|" \ - "<.link>|<.span>|<(.*)class(.*)>|<(.*)href(.*)>|" \ - "<(.*)data(.*)>|<.sub>|<.sup>|<.blockquote>|<.li>|" \ - "<.ol>|<.ul>|<.pre>','', 'g')" \ + "REGEXP_REPLACE(#{a}, E'#{rich_text_regex}','', 'g')" \ "ILIKE ANY (array[ :t#{i}]) OR " end ).join[0..-5] @@ -42,9 +45,7 @@ module SearchableModel if attrs.length > 0 where_str = (attrs.map.with_index do |a, i| - "REGEXP_REPLACE(#{a}, E'<.strong>|<.href>|<.div>|" \ - "<.link>|<.span>|<(.*)class(.*)>|<(.*)href(.*)>|<(.*)data(.*)>|" \ - "<.sub>|<.sup>|<.blockquote>|<.li>|<.ol>|<.ul>|<.pre>'," \ + "REGEXP_REPLACE(#{a}, E'#{rich_text_regex}'," \ " '', 'g' ) ILIKE :t#{i} OR " end ).join[0..-5]