Issues (1270)

plugins/search_sphinx/init.php (5 issues)

1
<?php
2
3
class Search_Sphinx extends Plugin {
4
    public function about() {
5
        return array(1.0,
6
            "Delegate searching for articles to Sphinx (don't forget to set options in config.php)",
7
            "hoelzro",
8
            true,
9
            "https://git.tt-rss.org/fox/tt-rss/wiki/SphinxSearch");
10
    }
11
12
    public function init($host) {
13
        $host->add_hook($host::HOOK_SEARCH, $this);
14
15
        // idk if that would work but checking for the class being loaded is somehow not enough
16
        if (class_exists("SphinxClient") && !defined('SEARCHD_COMMAND_SEARCH')) {
17
            user_error("Your PHP has a separate systemwide Sphinx client installed which conflicts with the client library used by tt-rss. Either remove the system library or disable Sphinx support.");
18
        }
19
20
        require_once __DIR__."/sphinxapi.php";
21
    }
22
23
    public function hook_search($search) {
24
        $offset = 0;
25
        $limit  = 500;
26
27
        $sphinxClient = new SphinxClient();
0 ignored issues
show
The type SphinxClient was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
28
29
        $sphinxpair = explode(":", SPHINX_SERVER, 2);
0 ignored issues
show
The constant SPHINX_SERVER was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
30
31
        $sphinxClient->SetServer($sphinxpair[0], (int) $sphinxpair[1]);
32
        $sphinxClient->SetConnectTimeout(1);
33
34
        $sphinxClient->SetFieldWeights(array('title' => 70, 'content' => 30,
35
            'feed_title' => 20));
36
37
        $sphinxClient->SetMatchMode(SPH_MATCH_EXTENDED2);
0 ignored issues
show
The constant SPH_MATCH_EXTENDED2 was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
38
        $sphinxClient->SetRankingMode(SPH_RANK_PROXIMITY_BM25);
0 ignored issues
show
The constant SPH_RANK_PROXIMITY_BM25 was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
39
        $sphinxClient->SetLimits($offset, $limit, 1000);
40
        $sphinxClient->SetArrayResult(false);
41
        $sphinxClient->SetFilter('owner_uid', array($_SESSION['uid']));
42
43
        $result = $sphinxClient->Query($search, SPHINX_INDEX);
0 ignored issues
show
The constant SPHINX_INDEX was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
44
45
        $ids = array();
46
47
        if (is_array($result['matches'])) {
48
            foreach (array_keys($result['matches']) as $int_id) {
49
                $ref_id = $result['matches'][$int_id]['attrs']['ref_id'];
50
                array_push($ids, $ref_id);
51
            }
52
        }
53
54
        $ids = join(",", $ids);
55
56
        if ($ids) {
57
                    return array("ref_id IN ($ids)", array());
58
        } else {
59
                    return array("ref_id = -1", array());
60
        }
61
    }
62
63
    public function api_version() {
64
        return 2;
65
    }
66
}
67