Skip to content

Commit feb1c48

Browse files
author
GomoR
committed
- bugfix: function::search,function::where: filter keywords may contain alphanumerical chars too and placeholders can now take a different field string that the original one
1 parent d293617 commit feb1c48

File tree

2 files changed

+42
-15
lines changed

2 files changed

+42
-15
lines changed

lib/Metabrik/Client/Onyphe/Function/Search.pm

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,29 @@ sub run {
2929
my $cb = sub {
3030
my ($this, $state, $new, $search) = @_;
3131

32-
# Update search clause with placeholder values
3332
my $copy = $search;
34-
while ($copy =~
35-
s{([\w\.]+)\s*:\s*\$([\w\.]+)}{$1:@{[$self->value($this, $2)]}}) {
33+
my (@holders) = $copy =~ m{[\w\.]+\s*:\s*\$([\w\.]+)}g;
34+
35+
# Update where clause with placeholder values
36+
my %searches = ();
37+
for my $holder (@holders) {
38+
my $values = $self->value_as_array($this, $holder);
39+
for my $value (@$values) {
40+
while ($copy =~
41+
s{(\S+)\s*:\s*\$$holder}{$1:$value}) {
42+
}
43+
$searches{$copy}++; # Make them unique
44+
}
3645
}
3746
38-
my $this_page = $self->search($copy, 1, 1) or return;
39-
if (defined($this_page->{count}) && $this_page->{count} > 0) {
40-
# Keep this page results if matches were found.
41-
push @$new, @{$this_page->{results}};
47+
my @searches = keys %searches;
48+
for my $search (@searches) {
49+
$self->log->verbose("search[$search]");
50+
my $this_page = $self->search($search, 1, 1) or return;
51+
if (defined($this_page->{count}) && $this_page->{count} > 0) {
52+
# Keep this page results if matches were found.
53+
push @$new, @{$this_page->{results}};
54+
}
4255
}
4356

4457
return 1;

lib/Metabrik/Client/Onyphe/Function/Where.pm

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,31 @@ sub run {
2727
$self->brik_help_run_undef_arg('run', $where) or return;
2828

2929
my $cb = sub {
30-
my ($this, $state, $new, $where) = @_;
30+
my ($this, $state, $new, $search) = @_;
31+
32+
my $copy = $search;
33+
my (@holders) = $copy =~ m{[\w\.]+\s*:\s*\$([\w\.]+)}g;
3134

3235
# Update where clause with placeholder values
33-
my $copy = $where;
34-
while ($copy =~
35-
s{([\w\.]+)\s*:\s*\$([\w\.]+)}{$1:@{[$self->value($this, $2)]}}) {
36-
#$self->log->debug("1[$1] 2[$2] value[".$self->value($this, $2)."]");
36+
my %searches = ();
37+
for my $holder (@holders) {
38+
my $values = $self->value_as_array($this, $holder);
39+
for my $value (@$values) {
40+
while ($copy =~
41+
s{(\S+)\s*:\s*\$$holder}{$1:$value}) {
42+
}
43+
$searches{$copy}++; # Make them unique
44+
}
3745
}
38-
my $this_page = $self->search($copy, 1, 1) or return;
39-
if ($this_page->{count} > 0) {
40-
push @$new, $this; # Keep this page if matches were found.
46+
47+
my @searches = keys %searches;
48+
for my $search (@searches) {
49+
$self->log->verbose("where[$search]");
50+
my $this_page = $self->search($search, 1, 1) or return;
51+
if (defined($this_page->{count}) && $this_page->{count} > 0) {
52+
# Keep this result if matches were found:
53+
push @$new, $this;
54+
}
4155
}
4256

4357
return 1;

0 commit comments

Comments
 (0)