| 1 | package Interchange::Search::Solr::Builder; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 14 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 14 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 14 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 14 | ▶ | use Types::Standard qw/ArrayRef HashRef Int/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 NAME | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | Interchange::Search::Solr::Builder | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | L<WebService::Solr::Response> subclass for building url. | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =head1 ACCESSORS | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =head2 terms | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | An arrayref contains search terms | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =cut | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 14 | has terms => ( | |||||||||||||||||||||||||||
| 26 | is => 'rw', | ||||||||||||||||||||||||||||
| 27 | isa => ArrayRef | ||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =head2 filters | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | A hashref which key is a feild of data and the value is keyword | ||||||||||||||||||||||||||||
| 33 | that needs to filter. | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | =cut | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 14 | has filters => ( | |||||||||||||||||||||||||||
| 38 | is => 'rw', | ||||||||||||||||||||||||||||
| 39 | isa => HashRef | ||||||||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =head2 facets | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | A string or an arrayref with the fields which will generate a facet. | ||||||||||||||||||||||||||||
| 45 | Defaults to | ||||||||||||||||||||||||||||
| 46 | [qw/suchbegriffe manufacturer/] | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =cut | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | has facets => ( | ||||||||||||||||||||||||||||
| 51 | is => 'rw', | ||||||||||||||||||||||||||||
| 52 | isa => ArrayRef, | ||||||||||||||||||||||||||||
| 53 | default => sub { | ||||||||||||||||||||||||||||
| 54 | 1 | ▶ | return [qw/suchbegriffe manufacturer/]; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | 14 | ); | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | =head2 page | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | A number of page and must be positive number (>= 1) | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | =cut | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | has page => ( | ||||||||||||||||||||||||||||
| 65 | is => 'rw', | ||||||||||||||||||||||||||||
| 66 | isa => sub { | ||||||||||||||||||||||||||||
| 67 | 3 | ▶ | if (defined $_[0]){ | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 3 | ▶ | die "$_[0] is not integer" if $_[0] !~ /^\d+$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 2 | ▶ | die "must be positive number" unless $_[0] >= 1 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | 14 | ); | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =head1 METHODS | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | In addition to all the L<WebService::Solr::Response> methods this | ||||||||||||||||||||||||||||
| 77 | class have the following methods: | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =head2 url_builder; | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | Build a query url with the parameter passed | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =cut | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | sub url_builder { | ||||||||||||||||||||||||||||
| 86 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
url_builder: called CC=7 SCAR=19.9
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 1 | my @fragments; | |||||||||||||||||||||||||||
| 89 | 1 | ▶ | if (@{$self->terms}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 1 | push @fragments, 'words', @{$self->terms}; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 1 | ▶ | if (%{$self->filters}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 1 | foreach my $facet (@{ $self->facets }) { | |||||||||||||||||||||||||||
| 95 | 2 | ▶ | if (my $terms = $self->filters->{$facet}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 1 | push @fragments, $facet, @$terms; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | 1 | ▶ | if ($self->page and $self->page > 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->page and $self->page > 1
MC/DC0%0/2
$self->page and $self->page > 1
$self->page
$self->page > 1
Truth table33%1/3
A and B
A= $self->pageB= $self->page > 1
| |||||||||||||||||||||||||||||
| 101 | 1 | push @fragments, page => $self->page; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | 1 | return join ('/', @fragments); | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 14 | 1; | |||||||||||||||||||||||||||