| 1 | package Dancer::SearchApp::Entry; | ||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 3 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 3 | ▶ | use vars qw($VERSION $es $server); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 3 | $VERSION = '0.06'; | |||||||||
| 7 | |||||||||||
| 8 | =head1 NAME | ||||||||||
| 9 | |||||||||||
| 10 | Dancer::SearchApp::Entry - a search index entry | ||||||||||
| 11 | |||||||||||
| 12 | =head1 SYNOPSIS | ||||||||||
| 13 | |||||||||||
| 14 | my $entry = Dancer::SearchApp::Entry->new({ | ||||||||||
| 15 | url => 'http://www.example.com/', | ||||||||||
| 16 | title => 'An Example', | ||||||||||
| 17 | content => '<html>...</html>', | ||||||||||
| 18 | language => 'en', | ||||||||||
| 19 | mime_type => 'text/html', | ||||||||||
| 20 | author => 'A. U. Thor', | ||||||||||
| 21 | }); | ||||||||||
| 22 | |||||||||||
| 23 | This is a aonvenience package to hold the information on an entry in the index. | ||||||||||
| 24 | This should basically match whatever you have in the index, like an ORM | ||||||||||
| 25 | or a glorified hash. | ||||||||||
| 26 | |||||||||||
| 27 | =head1 METHODS | ||||||||||
| 28 | |||||||||||
| 29 | =head2 C<< ->url >> | ||||||||||
| 30 | |||||||||||
| 31 | =head2 C<< ->id >> | ||||||||||
| 32 | |||||||||||
| 33 | =head2 C<< ->mime_type >> | ||||||||||
| 34 | |||||||||||
| 35 | =head2 C<< ->author >> | ||||||||||
| 36 | |||||||||||
| 37 | =head2 C<< ->creation_date >> | ||||||||||
| 38 | |||||||||||
| 39 | =head2 C<< ->content >> | ||||||||||
| 40 | |||||||||||
| 41 | =head2 C<< ->title >> | ||||||||||
| 42 | |||||||||||
| 43 | =head2 C<< ->folder >> | ||||||||||
| 44 | |||||||||||
| 45 | =head2 C<< ->language >> | ||||||||||
| 46 | |||||||||||
| 47 | =cut | ||||||||||
| 48 | |||||||||||
| 49 | # Canonical URL | ||||||||||
| 50 | 3 | has url => ( | |||||||||
| 51 | is => 'ro', | ||||||||||
| 52 | #isa => 'Str', | ||||||||||
| 53 | ); | ||||||||||
| 54 | |||||||||||
| 55 | { | ||||||||||
| 56 | 3 | ▶ | no warnings 'once'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 57 | 3 | *id = \*url; | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | 3 | has mime_type => ( | |||||||||
| 61 | is => 'ro', | ||||||||||
| 62 | #isa => 'Str', | ||||||||||
| 63 | ); | ||||||||||
| 64 | |||||||||||
| 65 | 3 | has author => ( | |||||||||
| 66 | is => 'ro', | ||||||||||
| 67 | #isa => 'Str', | ||||||||||
| 68 | ); | ||||||||||
| 69 | |||||||||||
| 70 | 3 | has creation_date => ( | |||||||||
| 71 | is => 'ro', | ||||||||||
| 72 | #isa => 'Str', | ||||||||||
| 73 | ); | ||||||||||
| 74 | |||||||||||
| 75 | 3 | has content => ( | |||||||||
| 76 | is => 'ro', | ||||||||||
| 77 | #isa => 'Str', # HTML-String | ||||||||||
| 78 | ); | ||||||||||
| 79 | |||||||||||
| 80 | 3 | has title => ( | |||||||||
| 81 | is => 'ro', | ||||||||||
| 82 | #isa => 'Str', | ||||||||||
| 83 | ); | ||||||||||
| 84 | |||||||||||
| 85 | 3 | has folder => ( | |||||||||
| 86 | is => 'ro', | ||||||||||
| 87 | #isa => 'Str', | ||||||||||
| 88 | ); | ||||||||||
| 89 | |||||||||||
| 90 | 3 | has language => ( | |||||||||
| 91 | is => 'ro', | ||||||||||
| 92 | #isa => 'Str', # 'de', not (yet) de-DE | ||||||||||
| 93 | ); | ||||||||||
| 94 | |||||||||||
| 95 | =head2 C<< ->from_es >> | ||||||||||
| 96 | |||||||||||
| 97 | Parses the elements as returned from Elasticsearch. | ||||||||||
| 98 | |||||||||||
| 99 | =cut | ||||||||||
| 100 | |||||||||||
| 101 | 0 | ▶ | sub from_es { | ||||||||
|
Subroutine
from_es: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 102 | 0 | my( $class, $result ) = @_; | |||||||||
| 103 | 0 | my %args = %{ $result->{_source} }; | |||||||||
| 104 | 0 | ▶ | if( $args{ "Content-Type" } ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 105 | 0 | $args{ mime_type } = delete $args{ "Content-Type" }; | |||||||||
| 106 | }; | ||||||||||
| 107 | 0 | my $self = $class->new( %args ); | |||||||||
| 108 | 0 | $self | |||||||||
| 109 | } | ||||||||||
| 110 | |||||||||||
| 111 | =head2 C<< ->basic_mime_type >> | ||||||||||
| 112 | |||||||||||
| 113 | if( 'text/plain' eq $item->basic_mime_type ) { | ||||||||||
| 114 | print "<pre>" . $item->content . "</pre>" | ||||||||||
| 115 | } | ||||||||||
| 116 | |||||||||||
| 117 | Converts | ||||||||||
| 118 | |||||||||||
| 119 | text/plain; encoding=Latin-1 | ||||||||||
| 120 | |||||||||||
| 121 | to | ||||||||||
| 122 | |||||||||||
| 123 | text/plain | ||||||||||
| 124 | |||||||||||
| 125 | =cut | ||||||||||
| 126 | |||||||||||
| 127 | 0 | ▶ | sub basic_mime_type { | ||||||||
|
Subroutine
basic_mime_type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 128 | 0 | my( $self ) = @_; | |||||||||
| 129 | 0 | my $mt = $self->mime_type; | |||||||||
| 130 | |||||||||||
| 131 | 0 | $mt =~ s!;.*!!; | |||||||||
| 132 | |||||||||||
| 133 | 0 | $mt | |||||||||
| 134 | } | ||||||||||
| 135 | |||||||||||
| 136 | 3 | 1; | |||||||||
| 137 | |||||||||||
| 138 | =head1 REPOSITORY | ||||||||||
| 139 | |||||||||||
| 140 | The public repository of this module is | ||||||||||
| 141 | L<https://github.com/Corion/dancer-searchapp>. | ||||||||||
| 142 | |||||||||||
| 143 | =head1 SUPPORT | ||||||||||
| 144 | |||||||||||
| 145 | The public support forum of this module is | ||||||||||
| 146 | L<https://perlmonks.org/>. | ||||||||||
| 147 | |||||||||||
| 148 | =head1 TALKS | ||||||||||
| 149 | |||||||||||
| 150 | I've given a talk about this module at Perl conferences: | ||||||||||
| 151 | |||||||||||
| 152 | L<German Perl Workshop 2016, German|http://corion.net/talks/dancer-searchapp/dancer-searchapp.html> | ||||||||||
| 153 | |||||||||||
| 154 | =head1 BUG TRACKER | ||||||||||
| 155 | |||||||||||
| 156 | Please report bugs in this module via the RT CPAN bug queue at | ||||||||||
| 157 | L<https://rt.cpan.org/Public/Dist/Display.html?Name=Dancer-SearchApp> | ||||||||||
| 158 | or via mail to L<dancer-searchapp-Bugs@rt.cpan.org>. | ||||||||||
| 159 | |||||||||||
| 160 | =head1 AUTHOR | ||||||||||
| 161 | |||||||||||
| 162 | Max Maischein C<corion@cpan.org> | ||||||||||
| 163 | |||||||||||
| 164 | =head1 COPYRIGHT (c) | ||||||||||
| 165 | |||||||||||
| 166 | Copyright 2014-2016 by Max Maischein C<corion@cpan.org>. | ||||||||||
| 167 | |||||||||||
| 168 | =head1 LICENSE | ||||||||||
| 169 | |||||||||||
| 170 | This module is released under the same terms as Perl itself. | ||||||||||
| 171 | |||||||||||
| 172 | =cut | ||||||||||