Admin Panel asset search extension: allow searching by assetId with the inclusion of a helper keyword:
assetid: <an_asset_id> assetId search is performed using a logical OR so multiple helper:key pairs can be applied and normal keywords can also be used in the same query
This commit is contained in:
parent
c91676b1ad
commit
d6696f8a7e
2 changed files with 39 additions and 6 deletions
|
|
@ -131,6 +131,7 @@ sub getSearchPaginator {
|
|||
|
||||
my $s = WebGUI::Search->new( $session, 0 );
|
||||
$s->search( {
|
||||
assetIds => $query->{ assetIds },
|
||||
keywords => $query->{ keywords },
|
||||
classes => $query->{ classes },
|
||||
} );
|
||||
|
|
@ -611,7 +612,18 @@ sub www_search {
|
|||
my $keywords = $session->form->get( 'keywords' );
|
||||
my @classes = $session->form->get( 'class' );
|
||||
|
||||
my $p = getSearchPaginator( $session, {
|
||||
# Detect a helper word key
|
||||
my @assetIds = ($keywords =~ /assetid:\s*([^\s]+)/gi);
|
||||
|
||||
# purge helper word keys
|
||||
if (@assetIds) {
|
||||
$keywords =~ s/\bassetid:\s*[^\s]+//gi;
|
||||
}
|
||||
$keywords =~ s/^\s+//g;
|
||||
$keywords =~ s/\s+$//g;
|
||||
|
||||
my $p = getSearchPaginator( $session, {
|
||||
assetIds => \@assetIds,
|
||||
keywords => $keywords,
|
||||
classes => \@classes,
|
||||
orderByColumn => $session->form->get( 'orderByColumn' ),
|
||||
|
|
|
|||
|
|
@ -360,9 +360,11 @@ sub search {
|
|||
croak "'lineage' rule must be array reference"
|
||||
if ( $rules->{lineage} && ref $rules->{lineage} ne "ARRAY" );
|
||||
|
||||
my @params = ();
|
||||
my @params;
|
||||
my @orParams;
|
||||
my $query = "";
|
||||
my @clauses = ();
|
||||
my @clauses;
|
||||
my @orClauses;
|
||||
if ($rules->{keywords}) {
|
||||
my $keywords = $rules->{keywords};
|
||||
unless ($keywords =~ m/"|\*/) { # do wildcards for people, like they'd expect
|
||||
|
|
@ -402,6 +404,15 @@ sub search {
|
|||
}
|
||||
push(@clauses, join(" or ", @phrases)) if (scalar(@phrases));
|
||||
}
|
||||
if ($rules->{assetIds}) {
|
||||
my @phrases = ();
|
||||
foreach my $assetId (@{$rules->{assetIds}}) {
|
||||
next unless $assetId;
|
||||
push(@orParams, $assetId);
|
||||
push(@phrases, "assetId like ?");
|
||||
}
|
||||
push(@orClauses, join(" or ", @phrases)) if (scalar(@phrases));
|
||||
}
|
||||
if ($rules->{classes}) {
|
||||
my @phrases = ();
|
||||
foreach my $class (@{$rules->{classes}}) {
|
||||
|
|
@ -457,9 +468,19 @@ sub search {
|
|||
unless (ref $rules->{columns} eq "ARRAY");
|
||||
$self->{_columns} = $rules->{columns};
|
||||
}
|
||||
|
||||
$self->{_params} = \@params;
|
||||
$self->{_where} = "(".join(") and (", @clauses).")";
|
||||
|
||||
push @{$self->{_params}}, @params;
|
||||
push @{$self->{_params}}, @orParams;
|
||||
|
||||
if (@clauses) {
|
||||
$self->{_where} .= "(".join(") and (", @clauses).")";
|
||||
}
|
||||
if (@orClauses) {
|
||||
if (length( $self->{_where} )) {
|
||||
$self->{_where} .= ' or ';
|
||||
}
|
||||
$self->{_where} .= "(".join(") or (", @orClauses).")";
|
||||
}
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue