Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
Similar
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
3 / 3
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 init
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 getResults
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * Related Records: Solr-based similarity
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Villanova University 2009, 2022.
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  Related_Records
25 * @author   Demian Katz <demian.katz@villanova.edu>
26 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
27 * @link     https://vufind.org/wiki/development:plugins:related_records_modules Wiki
28 */
29
30namespace VuFind\Related;
31
32use VuFindSearch\Command\SimilarCommand;
33
34/**
35 * Related Records: Solr-based similarity
36 *
37 * @category VuFind
38 * @package  Related_Records
39 * @author   Demian Katz <demian.katz@villanova.edu>
40 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
41 * @link     https://vufind.org/wiki/development:plugins:related_records_modules Wiki
42 */
43class Similar implements RelatedInterface
44{
45    /**
46     * Similar records
47     *
48     * @var array
49     */
50    protected $results;
51
52    /**
53     * Search service
54     *
55     * @var \VuFindSearch\Service
56     */
57    protected $searchService;
58
59    /**
60     * Constructor
61     *
62     * @param \VuFindSearch\Service $search Search service
63     */
64    public function __construct(\VuFindSearch\Service $search)
65    {
66        $this->searchService = $search;
67    }
68
69    /**
70     * Establishes base settings for making recommendations.
71     *
72     * @param string                            $settings Settings from config.ini
73     * @param \VuFind\RecordDriver\AbstractBase $driver   Record driver object
74     *
75     * @return void
76     */
77    public function init($settings, $driver)
78    {
79        $command = new SimilarCommand(
80            $driver->getSourceIdentifier(),
81            $driver->getUniqueId()
82        );
83        $this->results = $this->searchService->invoke($command)->getResult();
84    }
85
86    /**
87     * Get an array of Record Driver objects representing items similar to the one
88     * passed to the constructor.
89     *
90     * @return array
91     */
92    public function getResults()
93    {
94        return $this->results;
95    }
96}