svn: /web/php/trunk/ images/bing.png results.php ws.php
| From: | Rasmus Lerdorf | Date: | Thu, 14 Jul 2011 05:24:48 +0000 |
| Subject: | svn: /web/php/trunk/ images/bing.png results.php ws.php | ||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-11623@lists.php.net to get a copy of this message | ||
rasmus Thu, 14 Jul 2011 05:24:48 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=313221
Log:
Switching search backend from Yahoo to Bing.
and to head off the inevitable bitching about this, it
is because the Yahoo BOSS v1 API we are using is going
away on July 20 and Yahoo was not willing to give us
free access to the new v2 API. It would end up costing
us about $600/year at our current usage pattern.
The new Google REST API would cost us about $7500/year.
The Bing API is free.
Changed paths:
A web/php/trunk/images/bing.png
U web/php/trunk/results.php
U web/php/trunk/ws.php
Added: web/php/trunk/images/bing.png
===================================================================
(Binary files differ)
Property changes on: web/php/trunk/images/bing.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Modified: web/php/trunk/results.php
===================================================================
--- web/php/trunk/results.php 2011-07-14 04:37:25 UTC (rev 313220)
+++ web/php/trunk/results.php 2011-07-14 05:24:48 UTC (rev 313221)
@@ -71,9 +71,10 @@
$results_count = ($res['ResultSet']['totalResultsAvailable'] < 100 ?
$res['ResultSet']['totalResultsAvailable'] : 'more than 100');
-
+$disp_start_result = $start_result + 1;
+$disp_end_result = $end_result + 1;
echo <<<EOB
-<h2>Showing results $start_result to $end_result of $results_count</h2>
+<h2>Showing results $disp_start_result to $disp_end_result of $results_count</h2>
<ul id="search-results">
EOB;
$pos = $res['ResultSet']['firstResultPosition'];
@@ -131,9 +132,8 @@
}
echo <<<EOB
</ul>
-<span style="margin-left: 3em; margin-top: 1em; float: left;"><a href="http://developer.yahoo.net/about">
-<img src="http://l.yimg.com/a/i/us/nt/bdg/websrv_120_1.gif"
border="0">
-</a></span>
+<span style="margin-left: 3em; margin-top: 1em; float: left; font-family: Verdana, Tahoma,
Helvetica, Arial;
+font-size: 11px; color:#555;">Results by <img
src="/images/bing.png"/></span>
<div id="results_nav"><h4>Results Page:</h4>
<ul id="results_nav_list">
EOB;
Modified: web/php/trunk/ws.php
===================================================================
--- web/php/trunk/ws.php 2011-07-14 04:37:25 UTC (rev 313220)
+++ web/php/trunk/ws.php 2011-07-14 05:24:48 UTC (rev 313221)
@@ -1,17 +1,18 @@
<?php
-if(!$conf=apc_fetch('ws_config')) {
- include '/local/Web/ws.conf';
- apc_store('ws_config',$conf);
+include 'include/languages.inc';
+if(!$conf=apc_fetch('ws2_config')) {
+ include '/local/Web/ws2.conf';
+ apc_store('ws2_config',$conf);
}
$raw = filter_input(INPUT_GET, 'q', FILTER_UNSAFE_RAW);
$q = urlencode($raw);
$r = isset($_REQUEST['results']) ? (int)$_REQUEST['results'] : 10;
$s = isset($_REQUEST['start']) ? (int)$_REQUEST['start'] : 1;
-$l = isset($_REQUEST['lang']) ? htmlspecialchars($_REQUEST['lang']) :
'en';
-$m = isset($_REQUEST['mirror']) ? htmlspecialchars($_REQUEST['mirror']) :
'';
+$l = isset($_REQUEST['lang']) ? htmlspecialchars($_REQUEST['lang'], ENT_QUOTES)
: 'en';
+$m = isset($_REQUEST['mirror']) ? htmlspecialchars($_REQUEST['mirror'],
ENT_QUOTES) : '';
$sites = array( 'all'=>'php.net',
'local'=>'www.php.net',
- 'manual'=>'www.php.net',
+ 'manual'=>"www.php.net/manual/$l",
'news'=>'news.php.net',
'bugs'=>'bugs.php.net',
'pear'=>'pear.php.net',
@@ -19,41 +20,48 @@
'talks'=>'talks.php.net',
);
+$market = 'en-us';
+if(!empty($LANGUAGES_MAP[$l])) $market = $LANGUAGES_MAP[$l];
+
if(isset($sites[$_REQUEST['profile']])) {
- $scope = $_REQUEST['profile'];
+ $scope = htmlspecialchars($_REQUEST['profile'], ENT_QUOTES);
+ // If they are doing a manual search in a language we don't have a translation for,
default to English
+ if($scope == 'manual' && empty($ACTIVE_ONLINE_LANGUAGES[$l])) {
+ $sites['manual'] = "www.php.net/manual/en";
+ }
} else {
- $scope = 'all';
+ $scope = 'all';
}
-$request =
"{$conf['svc']}$q?appid={$conf['appid']}&start=$s&count=$r&sites={$sites[$scope]}&lang=$l&format=json";
+$request =
"{$conf['svc']}?appid={$conf['appid']}&query=$q%20site:{$sites[$scope]}&version=2.2&Sources=Web&web.offset=$s&web.count=$r&market=$market";
$data = @file_get_contents($request);
list($version,$status_code,$msg) = explode(' ',$http_response_header[0], 3);
-if($status_code==200) echo ws_boss_massage($data);
+if($status_code==200) echo ws_bing_massage($data);
else echo serialize($http_response_header[0]);
-function ws_boss_massage($data) {
+function ws_bing_massage($data) {
$results = json_decode($data, true);
- $rsp = $results['ysearchresponse'];
- $set = $rsp['resultset_web'];
+ $rsp = $results['SearchResponse']['Web'];
+ $set = $rsp['Results'];
$massaged = array(
'ResultSet' => array(
- 'totalResultsAvailable' => $rsp['totalhits'],
- 'totalResultsReturned' => $rsp['count'],
- 'firstResultPosition' => $rsp['start'],
+ 'totalResultsAvailable' => $rsp['Total'],
+ 'totalResultsReturned' => count($set),
+ 'firstResultPosition' => $rsp['Offset'],
'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
+ 'Title' => $result['Title'],
+ 'Summary' => $result['Description'],
+ 'Url' => $result['Url'],
+ 'ClickUrl' => $result['Url'],
+ 'MimeType' => NULL, // Not returned by Bing
+ 'ModificationDate' => strtotime($result['DateTime']),
+ 'Cache' => $result['CacheUrl']
);
}
@@ -64,8 +72,8 @@
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true));
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try {
- $stmt = $dbh->prepare("INSERT INTO log (query,profile,mirror) VALUES
(:query,:profile,:mirror)");
-
$stmt->execute(array(':query'=>$raw,':profile'=>$scope,':mirror'=>$m));
+ $stmt = $dbh->prepare("INSERT INTO log (query,profile,mirror,lang) VALUES
(:query,:profile,:mirror,:lang)");
+
$stmt->execute(array(':query'=>$raw,':profile'=>$scope,':mirror'=>$m,':lang'=>$l));
} catch (PDOException $e) {
}