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