Added search by location to the Gallery (RFE 11504)
This commit is contained in:
parent
426cc209ac
commit
387942e68d
8 changed files with 446 additions and 30 deletions
|
|
@ -379,6 +379,7 @@ sub indexContent {
|
|||
my $self = shift;
|
||||
my $indexer = $self->SUPER::indexContent;
|
||||
$indexer->addFile($self->getStorageLocation->getPath($self->get("filename")));
|
||||
return $indexer;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -372,6 +372,22 @@ sub getThumbnailUrl {
|
|||
);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 indexContent ( )
|
||||
|
||||
Indexing the content of the Photo. See WebGUI::Asset::indexContent() for
|
||||
additonal details.
|
||||
|
||||
=cut
|
||||
|
||||
sub indexContent {
|
||||
my $self = shift;
|
||||
my $indexer = $self->SUPER::indexContent;
|
||||
$indexer->addKeywords($self->get("location"));
|
||||
return $indexer;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 makeResolutions ( [resolutions] )
|
||||
|
|
|
|||
|
|
@ -13,12 +13,15 @@ package WebGUI::Asset::Wobject::Gallery;
|
|||
use strict;
|
||||
use Class::C3;
|
||||
use base qw(WebGUI::AssetAspect::RssFeed WebGUI::Asset::Wobject);
|
||||
|
||||
use JSON;
|
||||
use Tie::IxHash;
|
||||
use WebGUI::HTML;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Search;
|
||||
use WebGUI::Utility;
|
||||
use XML::Simple;
|
||||
use WebGUI::HTML;
|
||||
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -29,6 +32,7 @@ use WebGUI::HTML;
|
|||
=head1 DIAGNOSTICS
|
||||
|
||||
=head1 METHODS
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
@ -391,7 +395,13 @@ sub appendTemplateVarsSearchForm {
|
|||
name => "keywords",
|
||||
value => $form->get("keywords"),
|
||||
});
|
||||
|
||||
|
||||
$var->{ searchForm_location }
|
||||
= WebGUI::Form::text( $session, {
|
||||
name => "location",
|
||||
value => $form->get("location"),
|
||||
});
|
||||
|
||||
# Search classes
|
||||
tie my %searchClassOptions, 'Tie::IxHash', (
|
||||
'WebGUI::Asset::File::GalleryFile::Photo' => $i18n->get("search class photo"),
|
||||
|
|
@ -766,6 +776,7 @@ Other keys are valid, see C<WebGUI::Search::search()> for details.
|
|||
sub getSearchPaginator {
|
||||
my $self = shift;
|
||||
my $rules = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
$rules->{ lineage } = [ $self->get("lineage") ];
|
||||
|
||||
|
|
@ -1344,45 +1355,61 @@ sub www_listAlbumsService {
|
|||
return JSON->new->pretty->encode($document);
|
||||
}
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_search ( )
|
||||
=head2 search ( )
|
||||
|
||||
Search through the GalleryAlbums and files in this gallery. Show the form to
|
||||
search and display the results if necessary.
|
||||
Helper method for C<www_search> containing all the search logic. Executes a
|
||||
search depending on search form parameters. Returns undef if no search was
|
||||
executed. Otherwise an array is returned containing the following elements:
|
||||
|
||||
=head3 paginator
|
||||
|
||||
A paginator object containing the search results.
|
||||
|
||||
=head3 keywords
|
||||
|
||||
Search keywords assembled from search form fields.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_search {
|
||||
sub search {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
my $form = $session->form;
|
||||
my $db = $session->db;
|
||||
my $columns;
|
||||
|
||||
my $var = $self->getTemplateVars;
|
||||
# NOTE: Search form is added as part of getTemplateVars()
|
||||
|
||||
# Get search results, if necessary.
|
||||
# Check whether we have to do a search
|
||||
my $doSearch
|
||||
= (
|
||||
$form->get( 'basicSearch' ) || $form->get( 'keywords' )
|
||||
|| $form->get( 'title' ) || $form->get( 'description' )
|
||||
|| $form->get( 'userId' ) || $form->get( 'className' )
|
||||
|| $form->get( 'creationDate_after' ) || $form->get( 'creationDate_before' )
|
||||
$form->get( 'basicSearch' ) || $form->get( 'keywords' )
|
||||
|| $form->get( 'location' ) || $form->get( 'title' )
|
||||
|| $form->get( 'description' ) || $form->get( 'userId' )
|
||||
|| $form->get( 'className' ) || $form->get( 'creationDate_after' )
|
||||
|| $form->get( 'creationDate_before' )
|
||||
);
|
||||
|
||||
if ( $doSearch ) {
|
||||
# Keywords to search on
|
||||
# Do not add a space to the
|
||||
if ( $doSearch ) {
|
||||
# Keywords to search on.
|
||||
my $keywords;
|
||||
FORMVAR: foreach my $formVar (qw/ basicSearch keywords title description /) {
|
||||
FORMVAR: foreach my $formVar (qw/ basicSearch keywords location title description /) {
|
||||
my $var = $form->get($formVar);
|
||||
next FORMVAR unless $var;
|
||||
$keywords = join ' ', $keywords, $var;
|
||||
}
|
||||
# Remove leading whitespace
|
||||
$keywords =~ s/^\s+//;
|
||||
|
||||
# Build a where clause from the advanced options
|
||||
# Lineage search can capture gallery
|
||||
# Note that adding criteria to the where clause alone will not work. If
|
||||
# you want to cover additional properties you need to make sure that
|
||||
# - the property is added to $keywords above
|
||||
# - the property is included in index keywords by overriding the indexContent method of respective classes (usually Photo or GalleryFile)
|
||||
# - the respective table is joined in (usually via joinClass parameter of getSearchPaginator)
|
||||
# - the column containing the property is included in the query (usually via column parameter of getSearchPaginator)
|
||||
my $where = q{assetIndex.assetId <> '} . $self->getId . q{'};
|
||||
if ( $form->get("title") ) {
|
||||
$where .= q{ AND assetData.title LIKE }
|
||||
|
|
@ -1394,11 +1421,18 @@ sub www_search {
|
|||
. $db->quote( '%' . $form->get("description") . '%' )
|
||||
;
|
||||
}
|
||||
if ( $form->get("location") && ( $form->get("className") eq 'WebGUI::Asset::File::GalleryFile::Photo'
|
||||
|| $form->get("className") eq '' ) ) {
|
||||
$where .= q{ AND Photo.location LIKE }
|
||||
. $db->quote( '%' . $form->get("location") . '%' )
|
||||
;
|
||||
push (@{$columns}, 'Photo.location');
|
||||
}
|
||||
if ( $form->get("userId") ) {
|
||||
$where .= q{ AND assetData.ownerUserId = }
|
||||
. $db->quote( $form->get("userId") )
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
my $oneYearAgo = WebGUI::DateTime->new( $session, time )->add( years => -1 )->epoch;
|
||||
my $dateAfter = $form->get("creationDate_after", "dateTime", $oneYearAgo);
|
||||
|
|
@ -1412,45 +1446,76 @@ sub www_search {
|
|||
}
|
||||
|
||||
# Classes
|
||||
my $joinClass = [
|
||||
my $classes = [
|
||||
'WebGUI::Asset::Wobject::GalleryAlbum',
|
||||
'WebGUI::Asset::File::GalleryFile::Photo',
|
||||
];
|
||||
if ( $form->get("className") ) {
|
||||
$joinClass = [ $form->get('className') ];
|
||||
$classes = [ $form->get('className') ];
|
||||
}
|
||||
$where .= q{ AND assetIndex.className IN ( } . $db->quoteAndJoin( $joinClass ) . q{ ) };
|
||||
|
||||
|
||||
# Build a URL for the pagination
|
||||
my $url
|
||||
= $self->getUrl(
|
||||
'func=search;'
|
||||
. 'basicSearch=' . $form->get('basicSearch') . ';'
|
||||
. 'keywords=' . $form->get('keywords') . ';'
|
||||
. 'location=' . $form->get('location') . ';'
|
||||
. 'title=' . $form->get('title') . ';'
|
||||
. 'description=' . $form->get('description') . ';'
|
||||
. 'creationDate_after=' . $dateAfter . ';'
|
||||
. 'creationDate_before=' . $dateBefore . ';'
|
||||
. 'userId=' . $form->get("userId") . ';'
|
||||
);
|
||||
for my $class ( @$joinClass ) {
|
||||
for my $class ( @$classes ) {
|
||||
$url .= 'className=' . $class . ';';
|
||||
}
|
||||
|
||||
my $p
|
||||
|
||||
my $paginator
|
||||
= $self->getSearchPaginator( {
|
||||
url => $url,
|
||||
keywords => $keywords,
|
||||
where => $where,
|
||||
joinClass => $joinClass,
|
||||
classes => $classes,
|
||||
joinClass => $classes,
|
||||
columns => $columns,
|
||||
creationDate => $creationDate,
|
||||
} );
|
||||
} );
|
||||
|
||||
return ( $paginator, $keywords );
|
||||
}
|
||||
|
||||
# Return undef to indicate that no search was executed
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_search ( )
|
||||
|
||||
Search through the GalleryAlbums and files in this gallery. Show the form to
|
||||
search and display the results if necessary.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_search {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
my $var = $self->getTemplateVars;
|
||||
# NOTE: Search form is added as part of getTemplateVars()
|
||||
|
||||
# Execute search and retrieve search result paginator and keywords
|
||||
my ( $paginator, $keywords ) = $self->search;
|
||||
|
||||
if( $paginator ) {
|
||||
# Provide search keywords as template variable
|
||||
$var->{ keywords } = $keywords;
|
||||
|
||||
$p->appendTemplateVars( $var );
|
||||
for my $result ( @{ $p->getPageData } ) {
|
||||
# Add search results
|
||||
$paginator->appendTemplateVars( $var );
|
||||
for my $result ( @{ $paginator->getPageData } ) {
|
||||
my $asset = WebGUI::Asset->newByDynamicClass( $session, $result->{assetId} );
|
||||
push @{ $var->{search_results} }, {
|
||||
%{ $asset->getTemplateVars },
|
||||
|
|
|
|||
|
|
@ -29,6 +29,10 @@ our $HELP = {
|
|||
name => 'searchForm_keywords',
|
||||
description => 'helpvar searchForm_keywords',
|
||||
},
|
||||
{
|
||||
name => 'searchForm_location',
|
||||
description => 'helpvar searchForm_location',
|
||||
},
|
||||
{
|
||||
name => 'searchForm_className',
|
||||
description => 'helpvar searchForm_className',
|
||||
|
|
|
|||
|
|
@ -419,6 +419,11 @@ our $I18N = {
|
|||
message => 'Search by keyword.',
|
||||
lastUpdated => 0,
|
||||
},
|
||||
|
||||
'helpvar searchForm_location' => {
|
||||
message => 'Search by location.',
|
||||
lastUpdated => 0,
|
||||
},
|
||||
|
||||
'helpvar searchForm_className' => {
|
||||
message => 'Search by class name.',
|
||||
|
|
@ -616,6 +621,12 @@ our $I18N = {
|
|||
lastUpdated => 0,
|
||||
context => "Label for the 'Keywords' input for the search form. 'Tags' is used because Keywords may be confused with the generic, all-inclusive search box.",
|
||||
},
|
||||
|
||||
'template search field location' => {
|
||||
message => "Location",
|
||||
lastUpdated => 0,
|
||||
context => "Label for the 'Location' input for the search form.",
|
||||
},
|
||||
|
||||
'template search field className' => {
|
||||
message => "Search Type",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue