Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
17 / 17 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
RawJsonSearchCommand | |
100.00% |
17 / 17 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 | |||
getArguments | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
finalizeExecution | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * Command to perform a Solr search and return a decoded JSON response |
5 | * free from additional processing. |
6 | * |
7 | * PHP version 8 |
8 | * |
9 | * Copyright (C) Villanova University 2021. |
10 | * |
11 | * This program is free software; you can redistribute it and/or modify |
12 | * it under the terms of the GNU General Public License version 2, |
13 | * as published by the Free Software Foundation. |
14 | * |
15 | * This program is distributed in the hope that it will be useful, |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | * GNU General Public License for more details. |
19 | * |
20 | * You should have received a copy of the GNU General Public License |
21 | * along with this program; if not, write to the Free Software |
22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
23 | * |
24 | * @category VuFind |
25 | * @package GeoFeatures |
26 | * @author Demian Katz <demian.katz@villanova.edu> |
27 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
28 | * @link https://vufind.org |
29 | */ |
30 | |
31 | namespace VuFindSearch\Backend\Solr\Command; |
32 | |
33 | use VuFindSearch\Backend\Solr\Backend; |
34 | use VuFindSearch\Command\CommandInterface; |
35 | use VuFindSearch\Command\Feature\QueryOffsetLimitTrait; |
36 | use VuFindSearch\ParamBag; |
37 | use VuFindSearch\Query\AbstractQuery; |
38 | |
39 | /** |
40 | * Command to perform a Solr search and return a decoded JSON response |
41 | * free from additional processing. |
42 | * |
43 | * @category VuFind |
44 | * @package GeoFeatures |
45 | * @author Demian Katz <demian.katz@villanova.edu> |
46 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
47 | * @link https://vufind.org |
48 | */ |
49 | class RawJsonSearchCommand extends \VuFindSearch\Command\CallMethodCommand |
50 | { |
51 | use QueryOffsetLimitTrait; |
52 | |
53 | /** |
54 | * If json should be returned as an array instead an object |
55 | * |
56 | * @var ?bool |
57 | */ |
58 | protected $asArray = null; |
59 | |
60 | /** |
61 | * Constructor |
62 | * |
63 | * @param string $backendId Search backend identifier |
64 | * @param AbstractQuery $query Search query string |
65 | * @param int $offset Search offset |
66 | * @param int $limit Search limit |
67 | * @param ?ParamBag $params Search backend parameters |
68 | * @param ?bool $asArray If json should be returned as an array instead an object |
69 | */ |
70 | public function __construct( |
71 | string $backendId, |
72 | AbstractQuery $query, |
73 | int $offset = 0, |
74 | int $limit = 100, |
75 | ParamBag $params = null, |
76 | ?bool $asArray = null |
77 | ) { |
78 | $this->query = $query; |
79 | $this->offset = $offset; |
80 | $this->limit = $limit; |
81 | $this->asArray = $asArray; |
82 | parent::__construct( |
83 | $backendId, |
84 | Backend::class, |
85 | 'rawJsonSearch', |
86 | $params |
87 | ); |
88 | } |
89 | |
90 | /** |
91 | * Return search backend interface method arguments. |
92 | * |
93 | * @return array |
94 | */ |
95 | public function getArguments(): array |
96 | { |
97 | return [ |
98 | $this->getQuery(), |
99 | $this->getOffset(), |
100 | $this->getLimit(), |
101 | $this->getSearchParameters(), |
102 | ]; |
103 | } |
104 | |
105 | /** |
106 | * Save a result, flag the command as executed, and return the command object; |
107 | * useful as the final step in execute() implementations. |
108 | * |
109 | * @param mixed $result Result of execution. |
110 | * |
111 | * @return CommandInterface |
112 | */ |
113 | protected function finalizeExecution($result): CommandInterface |
114 | { |
115 | // We should JSON-decode the result when we save it, for convenience: |
116 | return parent::finalizeExecution(json_decode($result, $this->asArray)); |
117 | } |
118 | } |