1<?php
2
3/**
4 * phpMyFAQ SQlite based search classes.
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public License,
7 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
8 * obtain one at http://mozilla.org/MPL/2.0/.
9 *
10 * @package phpMyFAQ
11 *
12 * @author    Thorsten Rinne <thorsten@phpmyfaq.de>
13 * @copyright 2012-2020 phpMyFAQ Team
14 * @license   http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
15 *
16 * @link  https://www.phpmyfaq.de
17 * @since 2012-12-26
18 */
19
20namespace phpMyFAQ\Search\Database;
21
22use phpMyFAQ\Configuration;
23use phpMyFAQ\Search\SearchDatabase;
24
25/**
26 * Class Sqlite3
27 *
28 * @package phpMyFAQ\Search\Database
29 */
30class Sqlite3 extends SearchDatabase
31{
32    /**
33     * Constructor.
34     *
35     * @param Configuration $config
36     */
37    public function __construct(Configuration $config)
38    {
39        parent::__construct($config);
40    }
41
42    /**
43     * Prepares the search and executes it.
44     *
45     * @param  string $searchTerm Search ter
46     * @throws
47     * @return resource
48     */
49    public function search(string $searchTerm)
50    {
51        if (is_numeric($searchTerm) && $this->config->get('search.searchForSolutionId')) {
52            parent::search($searchTerm);
53        } else {
54            $query = sprintf(
55                '
56                SELECT
57                    %s
58                FROM
59                    %s %s %s
60                WHERE
61                    %s
62                    %s',
63                $this->getResultColumns(),
64                $this->getTable(),
65                $this->getJoinedTable(),
66                $this->getJoinedColumns(),
67                $this->getMatchClause($searchTerm),
68                $this->getConditions()
69            );
70
71            $this->resultSet = $this->config->getDb()->query($query);
72        }
73
74        return $this->resultSet;
75    }
76}
77