mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-28 19:24:10 +08:00
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:
commit
914bd42448
1 changed files with 23 additions and 6 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue