Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ErrorListener
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
5
100.00% covered (success)
100.00%
1 / 1
 onSearchError
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
5
1<?php
2
3/**
4 * SOLR 3.x error listener.
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Villanova University 2013.
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  Search
25 * @author   David Maus <maus@hab.de>
26 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
27 * @link     https://vufind.org Main Site
28 */
29
30namespace VuFind\Search\Solr\V3;
31
32use Laminas\EventManager\EventInterface;
33use VuFind\Search\Solr\AbstractErrorListener;
34use VuFindSearch\Backend\Exception\HttpErrorException;
35
36/**
37 * SOLR 3.x error listener.
38 *
39 * @category VuFind
40 * @package  Search
41 * @author   David Maus <maus@hab.de>
42 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
43 * @link     https://vufind.org Main Site
44 */
45class ErrorListener extends AbstractErrorListener
46{
47    /**
48     * VuFindSearch.error
49     *
50     * @param EventInterface $event Event
51     *
52     * @return EventInterface
53     */
54    public function onSearchError(EventInterface $event)
55    {
56        $command = $event->getParam('command');
57        if ($this->listenForBackend($command->getTargetIdentifier())) {
58            $error = $event->getParam('error');
59            if ($error instanceof HttpErrorException) {
60                $reason = $error->getResponse()->getReasonPhrase();
61                if (
62                    stristr($reason, 'org.apache.lucene.queryParser.ParseException')
63                    || stristr($reason, 'undefined field')
64                ) {
65                    $error->addTag(self::TAG_PARSER_ERROR);
66                }
67            }
68        }
69        return $event;
70    }
71}