Project

General

Profile

« Previous | Next » 

Revision 8658fa37

Added by Imri Zvik over 8 years ago

Fixes #11282 - Search on numeric facts is broken if using "~"

View differences:

app/models/concerns/scoped_search_extensions.rb
# Once Postgresql 8 support is removed (used in CentOS 6), this could be replaced to only keep the first form (working well with PG 9)
if (is_int && !is_pg)
casted = "CAST(fact_values.value AS DECIMAL) #{operator} #{value}"
elsif (is_int && is_pg)
elsif (is_int && is_pg && operator !~ /LIKE/i)
casted = "fact_values.value ~ E'^\\\\d+$' AND CAST(fact_values.value AS DECIMAL) #{operator} #{value}"
else
casted = "fact_values.value #{operator} '#{value}'"
test/unit/host_test.rb
assert_equal hosts.count, 1
assert_equal ["num001.example.com"], hosts.map { |h| h.name }.sort
hosts = Host::Managed.search_for("facts.memory_mb ~ 64498")
assert_equal hosts.count, 1
assert_equal ["num001.example.com"], hosts.map { |h| h.name }.sort
hosts = Host::Managed.search_for("facts.custom_fact = find_me")
assert_equal hosts.count, 1
assert_equal ["num001.example.com"], hosts.map { |h| h.name }.sort

Also available in: Unified diff