/usr/share/perl5/Catmandu/Searchable.pm is in libcatmandu-perl 0.9505-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | package Catmandu::Searchable;
use Catmandu::Sane;
our $VERSION = '0.9505';
use Catmandu::Util qw(:is);
use Moo::Role;
use namespace::clean;
requires 'translate_sru_sortkeys';
requires 'translate_cql_query';
requires 'search';
requires 'searcher';
requires 'delete_by_query';
has default_limit => (is => 'ro', builder => 'default_default_limit');
has maximum_limit => (is => 'ro', builder => 'default_maximum_limit');
sub default_default_limit { 10 }
sub default_maximum_limit { 1000 }
sub normalize_query { $_[1] }
my $AROUND_SEARCH = sub {
my ($orig, $self, %args) = @_;
$args{limit} = $self->default_limit unless is_natural($args{limit});
$args{start} = 0 unless is_natural($args{start});
$args{start}+=0;
$args{limit}+=0;
if ($args{limit} > $self->maximum_limit) {
$args{limit} = $self->maximum_limit;
}
if (is_positive(my $page = delete $args{page})) {
$args{start} = ($page - 1) * $args{limit};
}
if (my $sru_sortkeys = delete $args{sru_sortkeys}) {
$args{sort} = $self->translate_sru_sortkeys($sru_sortkeys);
}
if (my $cql_query = delete $args{cql_query}) {
$args{query} = $self->translate_cql_query($cql_query);
}
$args{query} = $self->normalize_query($args{query});
$orig->($self, %args);
};
around search => $AROUND_SEARCH;
around searcher => $AROUND_SEARCH;
around delete_by_query => sub {
my ($orig, $self, %args) = @_;
if (my $cql = delete $args{cql_query}) {
$args{query} = $self->translate_cql_query($cql);
}
$args{query} = $self->normalize_query($args{query});
$orig->($self, %args);
return;
};
1;
__END__
=pod
=head1 NAME
Catmandu::Searchable - Base class for all searchable Catmandu classes
=head1 SYNOPSIS
my $store = Catmandu::Store::Solr->new();
# Return one page of search results (page size = 1000)
my $hits = $store->bag->search(
query => 'dna' ,
start => 0 ,
limit => 100 ,
sort => 'title desc',
);
# Return all the search results as iterator
my $it = $store->bag->searcher(query => 'dna');
$it->each(sub { ...});
$store->bag->delete_by_query(query => 'dna');
=head1 METHODS
=head2 search(query => $query, start => $start, page => $page, limit => $num, sort => $sort, cql_query => $cql)
Search the database and returns a L<Catmandu::Hits> on success. The Hits represents one
result page of at most $num results. The $query and $sort should implement the
query and sort syntax of the underlying search engine. If the CQL language is supported
by the Store, then optionally a $cql_query search can be excuted on the Searchable.
Optionally provide the index of the first result using the C<start> option, or the starting page using
the C<page> option. The number of records in a result page can be set using the C<limit> option. Sorting
options are being sent verbatim to the underlying search engine.
=head2 searcher(query => $query, start => $start, limit => $num, sort => $sort, cql_query => $cql)
Search the database and return a L<Catmandu::Iterable> on success. This iterator can be
used to loop over the complete result set. The $query and $sort should implement the
query and sort syntax of the underlying search engine. If the CQL language is supported
by the Store, then optionally a $cql_query search can be excuted on the Searchable.
Optionally provide the index of the first result using the C<start> option. The number of records in
a page can be set using the C<limit> option. Sorting options are being sent verbatim to the underlying
search engine.
=head2 delete_by_query(query => $query)
Delete items from the database that match $query
=head1 SEE ALSO
L<Catmandu::Hits>, L<Catmandu::Paged>
=cut
|