| 1 | package Interchange::Search::Solr::UpdateIndex; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 2 | ▶ | use Moo; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 2 | ▶ | use Sub::Quote; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 2 | ▶ | use LWP::UserAgent; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | =head1 NAME | ||||||||||||||
| 11 | |||||||||||||||
| 12 | Interchange::Search::Solr::UpdateIndex | ||||||||||||||
| 13 | |||||||||||||||
| 14 | =head1 DESCRIPTION | ||||||||||||||
| 15 | |||||||||||||||
| 16 | Updates your Solr index. | ||||||||||||||
| 17 | |||||||||||||||
| 18 | =head2 ACCESSORS | ||||||||||||||
| 19 | |||||||||||||||
| 20 | =head3 url | ||||||||||||||
| 21 | |||||||||||||||
| 22 | Solr URL for your collection, e.g. | ||||||||||||||
| 23 | |||||||||||||||
| 24 | http://localhost:9059/solr/collection1 | ||||||||||||||
| 25 | |||||||||||||||
| 26 | =cut | ||||||||||||||
| 27 | |||||||||||||||
| 28 | 2 | has url => ( | |||||||||||||
| 29 | is => 'rw', | ||||||||||||||
| 30 | ); | ||||||||||||||
| 31 | |||||||||||||||
| 32 | |||||||||||||||
| 33 | =head3 agent | ||||||||||||||
| 34 | |||||||||||||||
| 35 | HTTP user agent object, defaults to a LWP::UserAgent instance. | ||||||||||||||
| 36 | |||||||||||||||
| 37 | =cut | ||||||||||||||
| 38 | |||||||||||||||
| 39 | has agent => ( | ||||||||||||||
| 40 | is => 'rw', | ||||||||||||||
| 41 | lazy => 1, | ||||||||||||||
| 42 | 0 | ▶ | default => sub {LWP::UserAgent->new;}, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 43 | 2 | ); | |||||||||||||
| 44 | |||||||||||||||
| 45 | =head3 status_line | ||||||||||||||
| 46 | |||||||||||||||
| 47 | HTTP status line. | ||||||||||||||
| 48 | |||||||||||||||
| 49 | =cut | ||||||||||||||
| 50 | |||||||||||||||
| 51 | 2 | has status_line => ( | |||||||||||||
| 52 | is => 'rwp', | ||||||||||||||
| 53 | lazy => 1, | ||||||||||||||
| 54 | default => quote_sub q{return '';}, | ||||||||||||||
| 55 | ); | ||||||||||||||
| 56 | |||||||||||||||
| 57 | =head2 METHODS | ||||||||||||||
| 58 | |||||||||||||||
| 59 | =head3 update | ||||||||||||||
| 60 | |||||||||||||||
| 61 | Updates index. Returns 1 on success. | ||||||||||||||
| 62 | |||||||||||||||
| 63 | Requires C<$mode> parameter which is either I<full> | ||||||||||||||
| 64 | or I<delta>. | ||||||||||||||
| 65 | |||||||||||||||
| 66 | =cut | ||||||||||||||
| 67 | |||||||||||||||
| 68 | sub update { | ||||||||||||||
| 69 | 0 | ▶ | my ($self, $mode) = @_; | ||||||||||||
|
Subroutine
update: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||
| 70 | 0 | my ($update_url, $command, $request, $response); | |||||||||||||
| 71 | |||||||||||||||
| 72 | # reset status line | ||||||||||||||
| 73 | 0 | $self->_set_status_line(''); | |||||||||||||
| 74 | |||||||||||||||
| 75 | # construct url and request | ||||||||||||||
| 76 | 0 | $update_url = $self->_construct_url($mode); | |||||||||||||
| 77 | 0 | $response = $self->agent->get($update_url); | |||||||||||||
| 78 | |||||||||||||||
| 79 | # save status line | ||||||||||||||
| 80 | 0 | $self->_set_status_line($response->status_line); | |||||||||||||
| 81 | |||||||||||||||
| 82 | 0 | ▶ | unless ($response->is_success) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 83 | 0 | return; | |||||||||||||
| 84 | } | ||||||||||||||
| 85 | |||||||||||||||
| 86 | 0 | return $response; | |||||||||||||
| 87 | } | ||||||||||||||
| 88 | |||||||||||||||
| 89 | =head3 query | ||||||||||||||
| 90 | |||||||||||||||
| 91 | Queries index. | ||||||||||||||
| 92 | |||||||||||||||
| 93 | =cut | ||||||||||||||
| 94 | |||||||||||||||
| 95 | sub query { | ||||||||||||||
| 96 | 0 | ▶ | my ($self, $query) = @_; | ||||||||||||
|
Subroutine
query: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 97 | 0 | my $url = $self->url . '/select?wt=json&'.$query; | |||||||||||||
| 98 | 0 | my $response = $self->agent->get($url); | |||||||||||||
| 99 | 0 | print $url."\n\r---------------\n\r"; | |||||||||||||
| 100 | 0 | return $response; | |||||||||||||
| 101 | } | ||||||||||||||
| 102 | |||||||||||||||
| 103 | sub _construct_url { | ||||||||||||||
| 104 | 0 | ▶ | my ($self, $mode) = @_; | ||||||||||||
|
Subroutine
_construct_url: not called CC=4 SCAR=30.0
| |||||||||||||||
| 105 | |||||||||||||||
| 106 | 0 | my $update_url; | |||||||||||||
| 107 | |||||||||||||||
| 108 | |||||||||||||||
| 109 | 0 | ▶ | if ($mode eq 'clear') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 110 | 0 | return $self->url . '/update?stream.body=<delete><query>*:*</query></delete>&commit=true'; | |||||||||||||
| 111 | } | ||||||||||||||
| 112 | |||||||||||||||
| 113 | 0 | $update_url = $self->url . '/dataimport?command='; | |||||||||||||
| 114 | |||||||||||||||
| 115 | 0 | ▶ | if ($mode eq 'full') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 116 | 0 | $update_url .= 'full-import'; | |||||||||||||
| 117 | } | ||||||||||||||
| 118 | elsif ($mode eq 'delta') { | ||||||||||||||
| 119 | 0 | $update_url .= 'delta-import'; | |||||||||||||
| 120 | } | ||||||||||||||
| 121 | #$update_url .= '&commit=true'; | ||||||||||||||
| 122 | } | ||||||||||||||
| 123 | |||||||||||||||
| 124 | =head1 AUTHOR | ||||||||||||||
| 125 | |||||||||||||||
| 126 | Stefan Hornburg (Racke), <racke@linuxia.de> | ||||||||||||||
| 127 | |||||||||||||||
| 128 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||
| 129 | |||||||||||||||
| 130 | Copyright 2013 Stefan Hornburg (Racke) <racke@linuxia.de>. | ||||||||||||||
| 131 | |||||||||||||||
| 132 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||
| 133 | under the terms of either: the GNU General Public License as published | ||||||||||||||
| 134 | by the Free Software Foundation; or the Artistic License. | ||||||||||||||
| 135 | |||||||||||||||
| 136 | See http://dev.perl.org/licenses/ for more information. | ||||||||||||||
| 137 | |||||||||||||||
| 138 | =cut | ||||||||||||||
| 139 | |||||||||||||||
| 140 | 2 | 1; | |||||||||||||