diff --git a/app/models/concerns/searchable_model.rb b/app/models/concerns/searchable_model.rb index eda69282f..c20be637f 100644 --- a/app/models/concerns/searchable_model.rb +++ b/app/models/concerns/searchable_model.rb @@ -21,17 +21,34 @@ module SearchableModel end if query.is_a? Array - if (attrs.length > 0) + + 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 { |a,i| "#{a} ILIKE ANY (array[ :t#{i}]) OR " }).join[0..-5] - vals = (attrs.map.with_index { |a,i| [ "t#{i}".to_sym, query ] }).to_h + (attrs.map.with_index do |a, i| + "REGEXP_REPLACE(#{a}, E'#{rich_text_regex}','', 'g')" \ + "ILIKE ANY (array[ :t#{i}]) OR " + end + ).join[0..-5] + vals = (attrs.map.with_index do |a, i| + ["t#{i}".to_sym, query] + end + ).to_h return where(where_str, vals) end else - if (attrs.length > 0) + if attrs.length > 0 where_str = - (attrs.map.with_index { |a,i| "#{a} ILIKE :t#{i} OR " }).join[0..-5] + (attrs.map.with_index do |a, i| + "REGEXP_REPLACE(#{a}, E'#{rich_text_regex}'," \ + " '', 'g' ) ILIKE :t#{i} OR " + end + ).join[0..-5] vals = (attrs.map.with_index { |a,i| [ "t#{i}".to_sym, "%#{query}%" ] }).to_h return where(where_str, vals) @@ -39,4 +56,4 @@ module SearchableModel end end end -end \ No newline at end of file +end