Merge pull request #278 from ZmagoD/zd_search_bug_with_rich_text_editor

strips the html tags from fearch query
This commit is contained in:
Zmago Devetak 2016-11-15 10:30:29 +01:00 committed by GitHub
commit 914bd42448

View file

@ -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
end