File Coverage

blib/lib/Catmandu/CQLSearchable.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1             package Catmandu::CQLSearchable;
2              
3 1     1   106511 use Catmandu::Sane;
  1         3  
  1         7  
4              
5             our $VERSION = '1.2020';
6              
7 1     1   8 use Moo::Role;
  1         2  
  1         6  
8 1     1   389 use namespace::clean;
  1         3  
  1         5  
9              
10             with 'Catmandu::Searchable';
11              
12             requires 'translate_sru_sortkeys';
13             requires 'translate_cql_query';
14              
15             my $AROUND_SEARCH = sub {
16             my ($orig, $self, %args) = @_;
17              
18             if (my $sru_sortkeys = delete $args{sru_sortkeys}) {
19             $args{sort} = $self->translate_sru_sortkeys($sru_sortkeys);
20             }
21             if (my $cql_query = delete $args{cql_query}) {
22             $args{query} = $self->translate_cql_query($cql_query);
23             }
24              
25             $orig->($self, %args);
26             };
27              
28             around search => $AROUND_SEARCH;
29             around searcher => $AROUND_SEARCH;
30              
31             around delete_by_query => sub {
32             my ($orig, $self, %args) = @_;
33              
34             if (my $cql = delete $args{cql_query}) {
35             $args{query} = $self->translate_cql_query($cql);
36             }
37              
38             $orig->($self, %args);
39             return;
40             };
41              
42             1;
43              
44             __END__
45              
46             =pod
47              
48             =head1 NAME
49              
50             Catmandu::CQLSearchable - Optional role for CQL searchable stores
51              
52             =head1 SYNOPSIS
53              
54             my $hits = $store->bag->search(
55             cql_query => 'keyword any dna',
56             sru_sortkeys => 'title,,0',
57             limit => 100,
58             );
59              
60             =head1 METHODS
61              
62             =head2 search(cql_query => $cql, sru_sortkeys => $sort, ...)
63              
64             This method behaves exactly like the C<search> method in L<Catmandu::Searchable> but with extra C<cql_query> and C<sru_sortkeys> arguments.
65              
66             =head2 searcher(cql_query => $cql, sru_sortkeys => $sort, ...)
67              
68             This method behaves exactly like the C<searcher> method in L<Catmandu::Searchable> but with extra C<cql_query> and C<sru_sortkeys> arguments.
69              
70             =head2 delete_by_query(cql_query => $cql, ...)
71              
72             This method behaves exactly like the C<delete_by_query> method in L<Catmandu::Searchable> but with an extra C<cql_query> argument.
73              
74             =head1 SEE ALSO
75              
76             L<Catmandu::Searchable>
77              
78             =cut
79