% if ($config->{search_dbi_args}) {

<% $config->{gallery_name} |h %>: search: <% $words || 'new' |h %>


Enter keywords (e.g.: dawn pablo)
all: >     any: >    
% if ($words) { % if (@bad) { The following keywords are not present in the database and were ignored: <% join(', ', @bad) |h %>

% } % if (@paths) { % for (@paths) { % $view = "../$_.html"; % ($thumb = $_) =~ s/\.[^.]+$/.jpg/; % }
<% basename($_) |h %>
% } else { No results found. Try removing keywords or checking "any". % } % }


% } else {

Search is not configured. Please read the README and edit the "config" component.

% } <%args> $bool => 'all' $words => undef $limit => 100 <%init> my ($dbh, $keyword, $row, @paths, $view, $sql, @terms, @bad, $thumb, $config); $limit = 100 unless $limit =~ /^\d+$/; $config = $m->comp('m/config'); if ($config->{search_dbi_args} && length $words) { $dbh = DBI->connect(@{$config->{search_dbi_args}}); @terms = split(/\s+/, lc($words)); $sql = 'select path from entries natural join keywords ' . 'natural join paths where ' . join(' or ', map { 'keyword = ' . $dbh->quote($_) } @terms); $sql .= " group by path having count(path) = " . scalar @terms if $bool eq 'all'; $sql .= " limit $limit"; @paths = sort { basename($a) cmp basename($b) } @{$dbh->selectcol_arrayref($sql)}; }