strips the html tags from fearch query

This commit is contained in:
zmagod 2016-11-11 11:41:23 +01:00
parent 19433850c8
commit 630724df2b

View file

@ -21,17 +21,33 @@ module SearchableModel
end
if query.is_a? Array
if (attrs.length > 0)
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'<.strong>|<.href>|<.div>|" \
"<.link>|<.span>|<(.*)class(.*)>|<(.*)href(.*)>|" \
"<(.*)data(.*)>|<.sub>|<.sup>|<.blockquote>|<.li>|" \
"<.ol>|<.ul>|<.pre>','', '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'<.strong>|<.href>|<.div>|" \
"<.link>|<.span>|<(.*)class(.*)>|<(.*)href(.*)>|<(.*)data(.*)>|" \
"<.sub>|<.sup>|<.blockquote>|<.li>|<.ol>|<.ul>|<.pre>'," \
" '', '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 +55,4 @@ module SearchableModel
end
end
end
end
end