]>
git.wh0rd.org - tt-rss.git/blob - plugins/search_sphinx/init.php
3 class Search_Sphinx
extends Plugin
{
6 "Delegate searching for articles to Sphinx (don't forget to set options in config.php)" ,
11 function init ( $host ) {
12 $host -> add_hook ( $host :: HOOK_SEARCH
, $this );
14 if ( class_exists ( "SphinxClient" )) {
15 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 require_once __DIR__
. "/sphinxapi.php" ;
21 function hook_search ( $search ) {
25 $sphinxClient = new SphinxClient ();
27 $sphinxpair = explode ( ":" , SPHINX_SERVER
, 2 );
29 $sphinxClient -> SetServer ( $sphinxpair [ 0 ], ( int ) $sphinxpair [ 1 ]);
30 $sphinxClient -> SetConnectTimeout ( 1 );
32 $sphinxClient -> SetFieldWeights ( array ( 'title' => 70 , 'content' => 30 ,
35 $sphinxClient -> SetMatchMode ( SPH_MATCH_EXTENDED2
);
36 $sphinxClient -> SetRankingMode ( SPH_RANK_PROXIMITY_BM25
);
37 $sphinxClient -> SetLimits ( $offset , $limit , 1000 );
38 $sphinxClient -> SetArrayResult ( false );
39 $sphinxClient -> SetFilter ( 'owner_uid' , array ( $_SESSION [ 'uid' ]));
41 $result = $sphinxClient -> Query ( $search , SPHINX_INDEX
);
45 if ( is_array ( $result [ 'matches' ])) {
46 foreach ( array_keys ( $result [ 'matches' ]) as $int_id ) {
47 $ref_id = $result [ 'matches' ][ $int_id ][ 'attrs' ][ 'ref_id' ];
48 array_push ( $ids , $ref_id );
52 $ids = join ( "," , $ids );
55 return array ( "ref_id IN ( $ids )" , array ());
57 return array ( "ref_id = -1" , array ());
60 function api_version () {