Labyrinth
view release on metacpan or search on metacpan
lib/Labyrinth/Metadata.pm view on Meta::CPAN
@EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
@EXPORT = ( @{ $EXPORT_TAGS{'all'} } );
#----------------------------------------------------------------------------
# Libraries
use Labyrinth::Audit;
use Labyrinth::Globals;
use Labyrinth::DBUtils;
use Labyrinth::Variables;
use HTML::TagCloud;
#----------------------------------------------------------------------------
# Variables
# type: 0 = optional, 1 = mandatory
# html: 0 = none, 1 = text, 2 = textarea
my %fields = (
title => { type => 1, html => 1 },
tagline => { type => 0, html => 1 },
);
#----------------------------------------------------------------------------
# Public Interface Functions
=head1 FUNCTIONS
=over 4
=item MetaSearch(%hash)
Provides the IDs for the given metadata search. The sqlkeys are one or more
keys into the phrasebook. Requires a hash of parameters:
keys => \@sqlkeys
meta => \@metadata
full => 1
limit => $limit
order => $order
sort => $sort_order
'key' and 'meta' are mandatory, all other key/value pairs are optional. If
'full' is provided with a non-zero value, a full text search is performed. If
a limit is given then only that number of records will be returned if more are
available. In order to suitably sort the records you can porovide the ORDER BY
string via the 'order' hash key.
=item MetaSave
Records the metadata with the given sqlkey for the name record id.
=item MetaGet
Gets the metadata for the given id.
=item MetaCloud
Returns the XHTML snippet to display a Metadata Tag Cloud.
=item MetaTags
Returns the list of tags attributed to a entry type and section ids.
=back
=cut
sub MetaSearch {
my %hash = @_;
my $keys = $hash{'keys'} || return ();
my $meta = lc join(",", map {"'$_'"} @{$hash{meta}});
my $data = lc join("|", @{$hash{meta}});
my $full = $hash{'full'} || 0;
LogDebug("MetaSearch: keys=[@$keys], meta=[$meta], full=$full");
return () unless(@$keys && $meta);
my $where = $hash{'where'} ? "AND $hash{'where'}" : '';
my $limit = $hash{'limit'} ? "LIMIT $hash{'limit'}" : '';
my $order = $hash{'order'} ? "ORDER BY $hash{'order'}" : '';
my %res;
for my $key (@$keys) {
if($full) {
# full text searching
my @rs = $dbi->GetQuery('hash',"MetaDetail$key",{meta=>$meta, data => $data, where => $where, limit => $limit, order => $order});
for(@rs) {$res{$_->{id}} = $_};
} else {
my @rs = $dbi->GetQuery('hash',"MetaSearch$key",{meta=>$meta, data => $data, where => $where, limit => $limit, order => $order});
for(@rs) {$res{$_->{id}} = $_};
}
}
my @res;
if($hash{'order'}) {
if($hash{'order'} eq 'createdate') {
@res = map {$res{$_}} sort {int($res{$a}->{createdate}) <=> int($res{$b}->{createdate})} keys %res;
} else {
@res = map {$res{$_}} sort {$res{$a}->{$hash{'order'}} cmp $res{$b}->{$hash{'order'}}} keys %res;
}
} else {
@res = map {$res{$_}} keys %res;
}
if($hash{'sort'} && $hash{'sort'} =~ /^desc/) {
@res = reverse @res;
}
if($hash{'limit'}) {
splice(@res,$hash{'limit'});
}
return @res;
}
sub MetaSave {
( run in 0.981 second using v1.01-cache-2.11-cpan-df04353d9ac )