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