blib/lib/ElasticSearchX/Model/Scroll.pm

filter: Statementstmt 66.6% 4 / 6 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 2 / 2 Podpod n/a totaltotal 75.0% 6 / 8 CC 1 SCAR 1.4
CC
1
Cov
67%
BEGIN
1.3
BEGIN
1.0
CRAP 1.1
« blib/lib/ElasticSearchX/Model/Document/Trait/Field/Timestamp.pm ↑ Summary blib/lib/ElasticSearchX/Model.pm »
1 #
2 # This file is part of ElasticSearchX-Model
3 #
4 # This software is Copyright (c) 2018 by Moritz Onken.
5 #
6 # This is free software, licensed under:
7 #
8 # The (three-clause) BSD License
9 #
10 package ElasticSearchX::Model::Scroll;
11 $ElasticSearchX::Model::Scroll::VERSION = '1.0.3';
12 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Search::Elasticsearch::Scroll;
Subroutine BEGIN: called CC=1 SCAR=2.6
14  
15 has scroll => ( is => 'ro', isa => 'Str', required => 1, default => '1m' );
16  
17 has set => (
18 is => 'ro',
19 isa => 'ElasticSearchX::Model::Document::Set',
20 required => 1,
21 handles => [qw(type index inflate inflate_result)],
22 );
23  
24 has _scrolled_search => (
25 is => 'ro',
26 isa => 'Search::Elasticsearch::Scroll',
27 lazy_build => 1,
28 handles => {
29 _next => 'next',
30 total => 'total',
31 max_score => 'max_score'
32 }
33 );
34  
35 has qs => (
36 is => 'ro',
37 isa => 'HashRef',
38 );
39  
40 sub _build__scrolled_search {
41 my $self = shift;
42 Search::Elasticsearch::Scroll->new(
43 {
44 es => $self->set->es,
45 body => $self->set->_build_query,
46 scroll => $self->scroll,
47 index => $self->index->name,
48 type => $self->type->short_name,
49 %{ $self->qs || {} },
50 }
51 );
52 }
53  
54 sub next {
55 my $self = shift;
56 return undef unless ( my $next = $self->_next );
57 return $next unless ( $self->inflate );
58 return $self->inflate_result($next);
59 }
60  
61 __PACKAGE__->meta->make_immutable;
62  
63 __END__
64  
65 =pod
66  
67 =encoding UTF-8
68  
69 =head1 NAME
70  
71 ElasticSearchX::Model::Scroll
72  
73 =head1 VERSION
74  
75 version 1.0.3
76  
77 =head1 SYNOPSIS
78  
79 my $iterator = $twitter->type('tweet')->scroll( '5m' );
80 while(my $tweet = $iterator->next) {
81 # do something with $tweet
82 }
83
84 my $iterator = $twitter->type('tweet')->raw->scroll;
85 $iterator->max_score;
86 $iterator->total;
87  
88 =head1 ATTRIBUTES
89  
90 =head2 scroll
91  
92 This string indicated how long ElasticSearch should keep the scrolled
93 search around. This attribute is set by passing it to
94 L<ElasticSearchX::Model::Document::Set/scroll>.
95  
96 =head2 set
97  
98 The L<ElasticSearchX::Model::Document::Set> this instance was build
99 from.
100  
101 =head1 METHODS
102  
103 =head2 total
104  
105 =head2 eof
106  
107 =head2 max_score
108  
109 Delegates to L<Elasticsearch::Scroll>.
110  
111 =head2 next
112  
113 Returns the next result in the search. If you set the query to not
114 inflate the results (e.g. using L<ElasticSearchX::Model::Document::Set/raw>)
115 it returns the raw HashRef, otherwise the result is inflated to
116 the correct document class.
117  
118 =head1 AUTHOR
119  
120 Moritz Onken
121  
122 =head1 COPYRIGHT AND LICENSE
123  
124 This software is Copyright (c) 2018 by Moritz Onken.
125  
126 This is free software, licensed under:
127  
128 The (three-clause) BSD License
129  
130 =cut
« blib/lib/ElasticSearchX/Model/Document/Trait/Field/Timestamp.pm ↑ Summary blib/lib/ElasticSearchX/Model.pm »