\tconnect to searchd at host HOST\n" ); print ( "-p, --port\t\tconnect to searchd at port PORT\n" ); print ( "-i, --index \tsearch through index(es) specified by IDX\n" ); print ( "-s, --sortby \tsort matches by 'CLAUSE' in sort_extended mode\n" ); print ( "-S, --sortexpr \tsort matches by 'EXPR' DESC in sort_expr mode\n" ); print ( "-a, --any\t\tuse 'match any word' matching mode\n" ); print ( "-b, --boolean\t\tuse 'boolean query' matching mode\n" ); print ( "-e, --extended\t\tuse 'extended query' matching mode\n" ); print ( "-ph,--phrase\t\tuse 'exact phrase' matching mode\n" ); print ( "-f, --filter \tfilter by attribute 'ATTR' (default is 'group_id')\n" ); print ( "-v, --value \tadd VAL to allowed 'group_id' values list\n" ); print ( "-g, --groupby \tgroup matches by 'EXPR'\n" ); print ( "-gs,--groupsort \tsort groups by 'EXPR'\n" ); print ( "-d, --distinct \tcount distinct values of 'ATTR''\n" ); print ( "-l, --limit \tretrieve COUNT matches (default: 20)\n" ); exit; } $args = array(); foreach ( $_SERVER["argv"] as $arg ) $args[] = $arg; $q = ""; $mode = SPH_MATCH_ALL; $host = "localhost"; $port = 3312; $index = "*"; $groupby = ""; $groupsort = "@group desc"; $filter = "group_id"; $filtervals = array(); $distinct = ""; $sortby = ""; $limit = 20; $ranker = SPH_RANK_PROXIMITY_BM25; for ( $i=0; $iSetServer ( $host, $port ); $cl->SetWeights ( array ( 100, 1 ) ); $cl->SetMatchMode ( $mode ); if ( count($filtervals) ) $cl->SetFilter ( $filter, $filtervals ); if ( $groupby ) $cl->SetGroupBy ( $groupby, SPH_GROUPBY_ATTR, $groupsort ); if ( $sortby ) $cl->SetSortMode ( SPH_SORT_EXTENDED, $sortby ); if ( $sortexpr ) $cl->SetSortMode ( SPH_SORT_EXPR, $sortexpr ); if ( $distinct ) $cl->SetGroupDistinct ( $distinct ); if ( $limit ) $cl->SetLimits ( 0, $limit, ( $limit>1000 ) ? $limit : 1000 ); $cl->SetRankingMode ( $ranker ); $cl->SetArrayResult ( true ); $res = $cl->Query ( $q, $index ); //////////////// // print me out //////////////// if ( $res===false ) { print "Query failed: " . $cl->GetLastError() . ".\n"; } else { if ( $cl->GetLastWarning() ) print "WARNING: " . $cl->GetLastWarning() . "\n\n"; print "Query '$q' retrieved $res[total] of $res[total_found] matches in $res[time] sec.\n"; print "Query stats:\n"; if ( is_array($res["words"]) ) foreach ( $res["words"] as $word => $info ) print " '$word' found $info[hits] times in $info[docs] documents\n"; print "\n"; if ( is_array($res["matches"]) ) { $n = 1; print "Matches:\n"; foreach ( $res["matches"] as $docinfo ) { print "$n. doc_id=$docinfo[id], weight=$docinfo[weight]"; foreach ( $res["attrs"] as $attrname => $attrtype ) { $value = $docinfo["attrs"][$attrname]; if ( $attrtype & SPH_ATTR_MULTI ) { $value = "(" . join ( ",", $value ) .")"; } else { if ( $attrtype==SPH_ATTR_TIMESTAMP ) $value = date ( "Y-m-d H:i:s", $value ); } print ", $attrname=$value"; } print "\n"; $n++; } } } // // $Id: test.php 1103 2008-01-24 18:42:57Z shodan $ // ?>