svn: /web/php/trunk/ ws.php

From: Date: Thu, 02 Dec 2010 15:37:03 +0000
Subject: svn: /web/php/trunk/ ws.php
Groups: php.webmaster 
Request: Send a blank email to php-webmaster+get-9570@lists.php.net to get a copy of this message
salathe Thu, 02 Dec 2010 15:37:03 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=305910 Log: make search use Y! BOSS Changed paths: U web/php/trunk/ws.php Modified: web/php/trunk/ws.php =================================================================== --- web/php/trunk/ws.php 2010-12-02 15:34:59 UTC (rev 305909) +++ web/php/trunk/ws.php 2010-12-02 15:37:03 UTC (rev 305910) @@ -25,12 +25,41 @@ $scope = 'all'; } -$request = "{$conf['svc']}?appid={$conf['appid']}&query=$q&start=$s&results=$r&site={$sites[$scope]}&language=$l&output=php&similar_ok=1"; +$request = "{$conf['svc']}$q?appid={$conf['appid']}&start=$s&count=$r&sites={$sites[$scope]}&lang=$l&format=json"; $data = @file_get_contents($request); list($version,$status_code,$msg) = explode(' ',$http_response_header[0], 3); -if($status_code==200) echo $data; +if($status_code==200) echo ws_boss_massage($data); else echo serialize($http_response_header[0]); +function ws_boss_massage($data) { + $results = json_decode($data, true); + $rsp = $results['ysearchresponse']; + $set = $rsp['resultset_web']; + + $massaged = array( + 'ResultSet' => array( + 'totalResultsAvailable' => $rsp['totalhits'], + 'totalResultsReturned' => $rsp['count'], + 'firstResultPosition' => $rsp['start'], + 'Result' => array(), + ), + ); + + foreach ($set as $result) { + $massaged['ResultSet']['Result'][] = array( + 'Title' => $result['title'], + 'Summary' => $result['abstract'], + 'Url' => $result['url'], + 'ClickUrl' => $result['clickurl'], + 'MimeType' => NULL, // Not returned from BOSS + 'ModificationDate' => strtotime($result['date']), + 'Cache' => NULL, // Not returned from BOSS + ); + } + + return serialize($massaged); +} + $dbh = new PDO('mysql:host=localhost;dbname=ws', $conf['db_user'], $conf['db_pw'], array(PDO::ATTR_PERSISTENT => true, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true)); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

« previous php.webmaster (#9570) next »