Merge pull request #8894 from artoscinote/ma_SCI_12277

Fix search for combination of NOT and searching by NULL columns [SCI-12277]
This commit is contained in:
Martin Artnik 2025-09-23 13:25:43 +02:00 committed by GitHub
commit 04ade3970d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -124,13 +124,13 @@ module SearchableModel
if attribute == :children
"\"#{table_name}\".\"id\" IN (#{where_children_attributes_like(token[:value]).select(:id).to_sql}) OR "
elsif SEARCH_NUMBER_ATTRIBUTES.include?(attribute)
"(#{attribute}::text #{like} ?) OR "
"(#{attribute} IS NOT NULL AND #{attribute}::text #{like} ?) OR "
elsif defined?(model::PREFIXED_ID_SQL) && attribute == model::PREFIXED_ID_SQL
"#{attribute} #{like} ? OR "
"(#{attribute} IS NOT NULL AND #{attribute} #{like} ?) OR "
elsif SEARCH_DATA_VECTOR_ATTRIBUTES.include?(attribute)
"#{attribute} @@ plainto_tsquery(?) OR "
"(#{attribute} IS NOT NULL AND #{attribute} @@ plainto_tsquery(?)) OR "
else
"trim_html_tags(#{attribute}) #{like} ? OR "
"(#{attribute} IS NOT NULL AND trim_html_tags(#{attribute}) #{like} ?) OR "
end
end).join[0..-5]