]> git.wh0rd.org Git - tt-rss.git/blob - plugins/search_sphinx/init.php
mention config.php settings in search_sphinx plugin description
[tt-rss.git] / plugins / search_sphinx / init.php
1 <?php
2
3 class Search_Sphinx extends Plugin {
4         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         }
10
11         function init($host) {
12                 $host->add_hook($host::HOOK_SEARCH, $this);
13
14                 require_once __DIR__ . "/sphinxapi.php";
15         }
16
17         function hook_search($search) {
18                 $offset = 0;
19                 $limit  = 500;
20
21                 $sphinxClient = new SphinxClient();
22
23                 $sphinxpair = explode(":", SPHINX_SERVER, 2);
24
25                 $sphinxClient->SetServer($sphinxpair[0], (int)$sphinxpair[1]);
26                 $sphinxClient->SetConnectTimeout(1);
27
28                 $sphinxClient->SetFieldWeights(array('title' => 70, 'content' => 30,
29                         'feed_title' => 20));
30
31                 $sphinxClient->SetMatchMode(SPH_MATCH_EXTENDED2);
32                 $sphinxClient->SetRankingMode(SPH_RANK_PROXIMITY_BM25);
33                 $sphinxClient->SetLimits($offset, $limit, 1000);
34                 $sphinxClient->SetArrayResult(false);
35                 $sphinxClient->SetFilter('owner_uid', array($_SESSION['uid']));
36
37                 $result = $sphinxClient->Query($search, SPHINX_INDEX);
38
39                 $ids = array();
40
41                 if (is_array($result['matches'])) {
42                         foreach (array_keys($result['matches']) as $int_id) {
43                                 $ref_id = $result['matches'][$int_id]['attrs']['ref_id'];
44                                 array_push($ids, $ref_id);
45                         }
46                 }
47
48                 $ids = join(",", $ids);
49
50                 if ($ids)
51                         return array("ref_id IN ($ids)", array());
52                 else
53                         return array("ref_id = -1", array());
54         }
55
56         function api_version() {
57                 return 2;
58         }
59 }
60 ?>