Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 18 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
AuthorFacets | |
0.00% |
0 / 18 |
|
0.00% |
0 / 7 |
90 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setConfig | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
init | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
process | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getResults | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getSearchTerm | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
getSimilarAuthors | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | /** |
4 | * AuthorFacets Recommendations Module |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Villanova University 2010. |
9 | * |
10 | * This program is free software; you can redistribute it and/or modify |
11 | * it under the terms of the GNU General Public License version 2, |
12 | * as published by the Free Software Foundation. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | * GNU General Public License for more details. |
18 | * |
19 | * You should have received a copy of the GNU General Public License |
20 | * along with this program; if not, write to the Free Software |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | * |
23 | * @category VuFind |
24 | * @package Recommendations |
25 | * @author Demian Katz <demian.katz@villanova.edu> |
26 | * @author Chris Hallberg <challber@villanova.edu> |
27 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
28 | * @link https://vufind.org/wiki/development:plugins:recommendation_modules Wiki |
29 | */ |
30 | |
31 | namespace VuFind\Recommend; |
32 | |
33 | use Laminas\Http\Request; |
34 | use Laminas\Stdlib\Parameters; |
35 | use VuFindSearch\Query\Query; |
36 | |
37 | /** |
38 | * AuthorFacets Recommendations Module |
39 | * |
40 | * This class provides recommendations displaying authors on top of the page. Default |
41 | * on author searches. |
42 | * |
43 | * @category VuFind |
44 | * @package Recommendations |
45 | * @author Demian Katz <demian.katz@villanova.edu> |
46 | * @author Chris Hallberg <challber@villanova.edu> |
47 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
48 | * @link https://vufind.org/wiki/development:plugins:recommendation_modules Wiki |
49 | */ |
50 | class AuthorFacets implements RecommendInterface |
51 | { |
52 | /** |
53 | * Configuration settings |
54 | * |
55 | * @var string |
56 | */ |
57 | protected $settings; |
58 | |
59 | /** |
60 | * Search results object |
61 | * |
62 | * @var \VuFind\Search\Base\Results |
63 | */ |
64 | protected $results; |
65 | |
66 | /** |
67 | * Results plugin manager |
68 | * |
69 | * @var \VuFind\Search\Results\PluginManager |
70 | */ |
71 | protected $resultsManager; |
72 | |
73 | /** |
74 | * Constructor |
75 | * |
76 | * @param \VuFind\Search\Results\PluginManager $results Results plugin manager |
77 | */ |
78 | public function __construct(\VuFind\Search\Results\PluginManager $results) |
79 | { |
80 | $this->resultsManager = $results; |
81 | } |
82 | |
83 | /** |
84 | * Store the configuration of the recommendation module. |
85 | * |
86 | * @param string $settings Settings from searches.ini. |
87 | * |
88 | * @return void |
89 | */ |
90 | public function setConfig($settings) |
91 | { |
92 | // Save the basic parameters: |
93 | $this->settings = $settings; |
94 | } |
95 | |
96 | /** |
97 | * Called before the Search Results object performs its main search |
98 | * (specifically, in response to \VuFind\Search\SearchRunner::EVENT_CONFIGURED). |
99 | * This method is responsible for setting search parameters needed by the |
100 | * recommendation module and for reading any existing search parameters that may |
101 | * be needed. |
102 | * |
103 | * @param \VuFind\Search\Base\Params $params Search parameter object |
104 | * @param Parameters $request Parameter object representing user |
105 | * request. |
106 | * |
107 | * @return void |
108 | */ |
109 | public function init($params, $request) |
110 | { |
111 | // No action needed here. |
112 | } |
113 | |
114 | /** |
115 | * Called after the Search Results object has performed its main search. This |
116 | * may be used to extract necessary information from the Search Results object |
117 | * or to perform completely unrelated processing. |
118 | * |
119 | * @param \VuFind\Search\Base\Results $results Search results object |
120 | * |
121 | * @return void |
122 | */ |
123 | public function process($results) |
124 | { |
125 | $this->results = $results; |
126 | } |
127 | |
128 | /** |
129 | * Get results stored in the object. |
130 | * |
131 | * @return \VuFind\Search\Base\Results |
132 | */ |
133 | public function getResults() |
134 | { |
135 | return $this->results; |
136 | } |
137 | |
138 | /** |
139 | * Returns search term. |
140 | * |
141 | * @return string |
142 | */ |
143 | public function getSearchTerm() |
144 | { |
145 | $search = $this->results->getParams()->getQuery(); |
146 | return ($search instanceof Query) ? $search->getString() : ''; |
147 | } |
148 | |
149 | /** |
150 | * Process similar authors from an author search |
151 | * |
152 | * @return array Facets data arrays |
153 | */ |
154 | public function getSimilarAuthors() |
155 | { |
156 | // Do not provide recommendations for blank searches: |
157 | $lookfor = $this->getSearchTerm(); |
158 | if (empty($lookfor)) { |
159 | return ['count' => 0, 'list' => []]; |
160 | } |
161 | |
162 | // Start configuring the results object: |
163 | $results = $this->resultsManager->get('SolrAuthorFacets'); |
164 | |
165 | // Set up a special limit for the AuthorFacets search object: |
166 | $results->getOptions()->setLimitOptions([10]); |
167 | |
168 | // Initialize object using parameters from the current Solr search object. |
169 | $results->getParams() |
170 | ->initFromRequest(new Parameters(['lookfor' => $lookfor])); |
171 | |
172 | // Send back the results: |
173 | return [ |
174 | // Total authors (currently there is no way to calculate this without |
175 | // risking out-of-memory errors or slow results, so we set this to |
176 | // false; if we are able to find this information out in the future, |
177 | // we can fill it in here and the templates will display it). |
178 | 'count' => false, |
179 | 'list' => $results->getResults(), |
180 | ]; |
181 | } |
182 | } |