Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
SolrCN
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 2
12
0.00% covered (danger)
0.00%
0 / 1
 setConfig
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 mungeQuery
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3/**
4 * Solr Call Number Autocomplete 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  Autocomplete
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:autosuggesters Wiki
29 */
30
31namespace VuFind\Autocomplete;
32
33/**
34 * Solr Call Number Autocomplete Module
35 *
36 * This class provides smart call number suggestions by using the local Solr index.
37 *
38 * @category VuFind
39 * @package  Autocomplete
40 * @author   Demian Katz <demian.katz@villanova.edu>
41 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
42 * @link     https://vufind.org/wiki/development:plugins:autosuggesters Wiki
43 */
44class SolrCN extends Solr
45{
46    /**
47     * Set parameters that affect the behavior of the autocomplete handler.
48     * These values normally come from the search configuration file.
49     *
50     * @param string $params Parameters to set
51     *
52     * @return void
53     */
54    public function setConfig($params)
55    {
56        // Ignore incoming configuration and force CallNumber settings.
57        parent::setConfig('CallNumber');
58    }
59
60    /**
61     * Process the user query to make it suitable for a Solr query.
62     *
63     * @param string $query Incoming user query
64     *
65     * @return string       Processed query
66     */
67    protected function mungeQuery($query)
68    {
69        // Modify the query so it makes a nice, truncated autocomplete query:
70        $forbidden = [':', '(', ')', '*', '+', '"'];
71        $query = str_replace($forbidden, ' ', $query);
72
73        // Assign display fields and sort order based on the query -- if the
74        // first character is a number, give Dewey priority; otherwise, give
75        // LC priority:
76        if (is_numeric(substr(trim($query), 0, 1))) {
77            $this->setDisplayField(['dewey-full', 'callnumber-raw']);
78            $this->setSortField('dewey-sort,callnumber-sort');
79        } else {
80            $this->setDisplayField(['callnumber-raw', 'dewey-full']);
81            $this->setSortField('callnumber-sort,dewey-sort');
82        }
83
84        return $query;
85    }
86}