]>
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 // idk if that would work but checking for the class being loaded is somehow not enough
15 if ( class_exists ( "SphinxClient" ) && ! defined ( 'SEARCHD_COMMAND_SEARCH' )) {
16 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." );
19 require_once __DIR__
. "/sphinxapi.php" ;
22 function hook_search ( $search ) {
26 $sphinxClient = new SphinxClient ();
28 $sphinxpair = explode ( ":" , SPHINX_SERVER
, 2 );
30 $sphinxClient -> SetServer ( $sphinxpair [ 0 ], ( int ) $sphinxpair [ 1 ]);
31 $sphinxClient -> SetConnectTimeout ( 1 );
33 $sphinxClient -> SetFieldWeights ( array ( 'title' => 70 , 'content' => 30 ,
36 $sphinxClient -> SetMatchMode ( SPH_MATCH_EXTENDED2
);
37 $sphinxClient -> SetRankingMode ( SPH_RANK_PROXIMITY_BM25
);
38 $sphinxClient -> SetLimits ( $offset , $limit , 1000 );
39 $sphinxClient -> SetArrayResult ( false );
40 $sphinxClient -> SetFilter ( 'owner_uid' , array ( $_SESSION [ 'uid' ]));
42 $result = $sphinxClient -> Query ( $search , SPHINX_INDEX
);
46 if ( is_array ( $result [ 'matches' ])) {
47 foreach ( array_keys ( $result [ 'matches' ]) as $int_id ) {
48 $ref_id = $result [ 'matches' ][ $int_id ][ 'attrs' ][ 'ref_id' ];
49 array_push ( $ids , $ref_id );
53 $ids = join ( "," , $ids );
56 return array ( "ref_id IN ( $ids )" , array ());
58 return array ( "ref_id = -1" , array ());
61 function api_version () {