line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Fix::search_in_store; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
107016
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
18
|
|
4
|
1
|
|
|
1
|
|
530
|
use Catmandu::Util::Path qw(as_path); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
55
|
|
5
|
1
|
|
|
1
|
|
436
|
use Catmandu; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
5
|
|
6
|
1
|
|
|
1
|
|
259
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
7
|
1
|
|
|
1
|
|
931
|
use Catmandu::Fix::Has; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
6
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
with 'Catmandu::Fix::Builder'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
#options/arguments |
12
|
|
|
|
|
|
|
has path => (fix_arg => 1); |
13
|
|
|
|
|
|
|
has store_name => (fix_opt => 1, init_arg => 'store'); |
14
|
|
|
|
|
|
|
has bag_name => (fix_opt => 1, init_arg => 'bag'); |
15
|
|
|
|
|
|
|
has limit => (fix_opt => 1, init_arg => undef, default => sub {20}); |
16
|
|
|
|
|
|
|
has start => (fix_opt => 1, init_arg => undef, default => sub {0}); |
17
|
|
|
|
|
|
|
has sort => (fix_opt => 1, init_arg => undef, default => sub {''}); |
18
|
|
|
|
|
|
|
has store_args => (fix_opt => 'collect'); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
#internal |
21
|
|
|
|
|
|
|
has store => (is => 'lazy', init_arg => undef, builder => '_build_store'); |
22
|
|
|
|
|
|
|
has bag => (is => 'lazy', init_arg => undef, builder => '_build_bag'); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _build_store { |
25
|
5
|
|
|
5
|
|
39
|
my $self = $_[0]; |
26
|
5
|
|
|
|
|
11
|
Catmandu->store($self->store_name, %{$self->store_args}); |
|
5
|
|
|
|
|
25
|
|
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _build_bag { |
30
|
5
|
|
|
5
|
|
38
|
my ($self) = @_; |
31
|
5
|
100
|
|
|
|
90
|
defined $self->bag_name |
32
|
|
|
|
|
|
|
? $self->store->bag($self->bag_name) |
33
|
|
|
|
|
|
|
: $self->store->bag; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _build_fixer { |
37
|
5
|
|
|
5
|
|
48
|
my ($self) = @_; |
38
|
5
|
|
|
|
|
82
|
my $bag = $self->bag; |
39
|
5
|
|
|
|
|
36
|
my $limit = $self->limit; |
40
|
5
|
|
|
|
|
11
|
my $start = $self->start; |
41
|
5
|
|
|
|
|
10
|
my $sort = $self->sort; |
42
|
|
|
|
|
|
|
as_path($self->path)->updater( |
43
|
|
|
|
|
|
|
sub { |
44
|
5
|
|
|
5
|
|
11
|
my $val = $_[0]; |
45
|
5
|
|
|
|
|
100
|
my $hits = $bag->search( |
46
|
|
|
|
|
|
|
query => $val, |
47
|
|
|
|
|
|
|
start => $start, |
48
|
|
|
|
|
|
|
limit => $limit, |
49
|
|
|
|
|
|
|
sort => $sort |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
+{ |
52
|
5
|
|
|
|
|
2163
|
start => $start, |
53
|
|
|
|
|
|
|
limit => $limit, |
54
|
|
|
|
|
|
|
total => $hits->total, |
55
|
|
|
|
|
|
|
hits => $hits->to_array |
56
|
|
|
|
|
|
|
}; |
57
|
|
|
|
|
|
|
} |
58
|
5
|
|
|
|
|
23
|
); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 NAME |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Catmandu::Fix::search_in_store - use the value as query, and replace it by a search object |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 SYNTAX |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
search_in_store(path) |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
search_in_store(path,store: 'store', bag: 'bag', limit: 0, start: 0, sort: 'title desc') |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 RETURN VALUE |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
{ |
74
|
|
|
|
|
|
|
start: 0, |
75
|
|
|
|
|
|
|
limit: 0, |
76
|
|
|
|
|
|
|
hits: [], |
77
|
|
|
|
|
|
|
total: 1000 |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
cf. L<Catmandu::Hits> |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 PARAMETERS |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 path |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
The location in the perl hash where the query is stored. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
See L<Catmandu::Fix/"PATHS"> for more information about paths. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 store |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
The name of the store. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
This store MUST be an implementation of L<Catmandu::Searchable>. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
There are several ways to refer to a store: |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
* by full package name ( e.g. 'Catmandu::Store::Solr' ) |
99
|
|
|
|
|
|
|
* by short package name ( e.g. 'Solr' ) |
100
|
|
|
|
|
|
|
* by name defined in the Catmandu configuration |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
See L<Catmandu/store-NAME> for more information. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Default is 'default'. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head2 bag |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Name of bag. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Default is 'data'. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 limit |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
only return $limit number of records. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head2 start |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
offset of records to return |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head2 sort |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sort records before slicing them. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
This parameter is store specific. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 OTHER PARAMETERS |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
other parameters are given to the contructor of the L<Catmandu::Store> |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
e.g. catmandu.yml: |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
store: |
134
|
|
|
|
|
|
|
catalog: |
135
|
|
|
|
|
|
|
package: "Catmandu::Store::Solr" |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
e.g. fix: |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
search_in_store('foo.query', store:'catalog', bag: 'data', url: 'http://localhost:8983/solr/catalog') |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 EXAMPLES |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
#search in Catmandu->store->bag, and store first 20 results in the foo.query.hits |
144
|
|
|
|
|
|
|
search_in_store('foo.query') |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
#search in Catmandu->store->bag, and store first 20 results in the foo.query.hits |
147
|
|
|
|
|
|
|
search_in_store('foo.query', store:'default') |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
#search in Catmandu->store->bag; limit number of results to 10 |
150
|
|
|
|
|
|
|
search_in_store('foo.query', store:'default', limit: 10) |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
#search in Catmandu->store->bag; limit number of result to 10, starting from 15 |
153
|
|
|
|
|
|
|
search_in_store('foo.query', store:'default', limit: 10, start: 15) |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
#search in Catmandu->store->bag('persons'); sort by year descending, and by title ascending |
156
|
|
|
|
|
|
|
search_in_store('foo.query', store:'default', bag:'persons', sort: 'year desc,title asc') |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 AUTHORS |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Nicolas Franck C<< <nicolas.franck at ugent.be> >> |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 SEE ALSO |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
L<Catmandu::Fix> |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
L<Catmandu::Store> |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=cut |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
1; |