tighten up the logic of fuzzy search to eliminate redundant matches
This commit is contained in:
@@ -279,19 +279,23 @@ sub search_fuzzy {
|
|||||||
unless $q;
|
unless $q;
|
||||||
$q = "\%$q\%" if $q !~ m/\%/;
|
$q = "\%$q\%" if $q !~ m/\%/;
|
||||||
|
|
||||||
# basic IP check is a string match
|
# basic check is a string match
|
||||||
my $ip_clause = [
|
my @ip_clause = (
|
||||||
'me.ip::text' => { '-ilike' => $q },
|
'me.name' => { '-ilike' => $q },
|
||||||
|
'me.dns' => { '-ilike' => $q },
|
||||||
|
'me.ip::text' => { '-ilike' => $q },
|
||||||
|
'device_ips.dns' => { '-ilike' => $q },
|
||||||
'device_ips.alias::text' => { '-ilike' => $q },
|
'device_ips.alias::text' => { '-ilike' => $q },
|
||||||
];
|
);
|
||||||
|
|
||||||
# but also allow prefix search
|
# but also allow prefix search
|
||||||
(my $qc = $q) =~ s/\%//g;
|
(my $qc = $q) =~ s/\%//g;
|
||||||
if (my $ip = NetAddr::IP::Lite->new($qc)) {
|
if (my $ip = NetAddr::IP::Lite->new($qc)) {
|
||||||
$ip_clause = [
|
@ip_clause = (
|
||||||
|
# exclude check on name and dns fields
|
||||||
'me.ip' => { '<<=' => $ip->cidr },
|
'me.ip' => { '<<=' => $ip->cidr },
|
||||||
'device_ips.alias' => { '<<=' => $ip->cidr },
|
'device_ips.alias' => { '<<=' => $ip->cidr },
|
||||||
];
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $rs->search(
|
return $rs->search(
|
||||||
@@ -300,17 +304,12 @@ sub search_fuzzy {
|
|||||||
'me.contact' => { '-ilike' => $q },
|
'me.contact' => { '-ilike' => $q },
|
||||||
'me.serial' => { '-ilike' => $q },
|
'me.serial' => { '-ilike' => $q },
|
||||||
'me.location' => { '-ilike' => $q },
|
'me.location' => { '-ilike' => $q },
|
||||||
'me.name' => { '-ilike' => $q },
|
|
||||||
'me.description' => { '-ilike' => $q },
|
'me.description' => { '-ilike' => $q },
|
||||||
-or => [
|
@ip_clause,
|
||||||
'me.dns' => { '-ilike' => $q },
|
|
||||||
'device_ips.dns' => { '-ilike' => $q },
|
|
||||||
],
|
|
||||||
-or => $ip_clause,
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
order_by => [qw/ me.dns me.ip /],
|
order_by => { -desc => 'me.creation' },
|
||||||
join => 'device_ips',
|
join => 'device_ips',
|
||||||
distinct => 1,
|
distinct => 1,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user