diff --git a/application/default/controllers/ServiceController.php b/application/default/controllers/ServiceController.php index 47be8453..3db40442 100644 --- a/application/default/controllers/ServiceController.php +++ b/application/default/controllers/ServiceController.php @@ -767,6 +767,7 @@ class ServiceController extends Zend_Controller_Action 'q' => $q, // 查询内容 'key' => $this->config->google->maps->api, 'userip' => $_SERVER['REMOTE_ADDR'], + 'rsz' => 5 )); print_r($rez); exit(); @@ -784,6 +785,81 @@ class ServiceController extends Zend_Controller_Action $body = curl_exec($ch); curl_close($ch); return $body; - } + }// google 搜索 + + function bingsearchAction(){ + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + $q = $this->_request->getParam('q'); + $rez = $this->bing_search($q); + print_r($rez); + exit(); + } + + function bing_search($keyword,$referer = 'http://westdc.westgis.ac.cn/'){ + $keyword=urlencode($keyword); + $url = "http://api.bing.net/json.aspx?AppId=".$this->config->bing->api + ."&Query=".$keyword + ."&Sources=Web" + ."&Version=2.0" + ."&Market=en-us" + ."&Adult=Moderate" + ."&Options=EnableHighlighting" + ."&Web.Count=5" + ."&Web.Offset=0" + ."&Web.Options=DisableHostCollapsing+DisableQueryAlterations"; + //&JsonType=callback&JsonCallback=SearchCompleted + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_REFERER, $referer); + $body = curl_exec($ch); + curl_close($ch); + return $body; + }//bing 搜索 + + function cnkisearchAction(){ + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + $q = $this->_request->getParam('q'); + $rez = $this->cnki_search($q); + print_r($rez); + exit(); + } + + function cnki_search($keyword , $referer = 'http://westdc.westgis.ac.cn/'){ + $keyword = urlencode($keyword); + $url = "http://search.cnki.net/search.aspx?q=$keyword"; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_REFERER, $referer); + $body = curl_exec($ch); + curl_close($ch); + + $rev = array(); + $max = 5; + if(preg_match_all("#(.+?)#i",$body,$matchs,PREG_PATTERN_ORDER)) + { + foreach ($matchs[2] as $k=>$v){ + if($k < $max) $rev[$k]['title']=$v; + } + foreach ($matchs[1] as $k=>$v){ + if($k < $max) $rev[$k]['url']=$v; + } + } + + if(preg_match_all("#(.+?)#i",$body,$matchs,PREG_PATTERN_ORDER)) + { + foreach ($matchs[1] as $k=>$v){ + if($k < $max) $rev[$k]['content']=$v; + } + } + + $response=array("result"=>$rev,"count"=>$max,"morelink"=>'http://search.cnki.net/search.aspx?q='.$keyword); + + $rev = Zend_Json::encode($response); + return $rev; + }//cnki 搜索 } diff --git a/application/default/views/scripts/heihe/view.phtml b/application/default/views/scripts/heihe/view.phtml index c8aa404b..32b474b1 100755 --- a/application/default/views/scripts/heihe/view.phtml +++ b/application/default/views/scripts/heihe/view.phtml @@ -229,12 +229,20 @@ endforeach; +keys as $cg){ + if($cg->keytype=="theme") + $keywords[]=$cg->keyword; + } + $ev = join(" ",$keywords); +?> related) : ?> @@ -278,15 +286,9 @@ echo '【'.$r->author.'. '.$r->publisher.' '.$r->ts_issued.'】';
@@ -356,7 +358,8 @@ function ajaxpage(page){ success:function(html){$('#allcomments').html(html);}, beforeSend:function(){$('#allcomments').html('评论加载中');} }); -};ajaxpage(0); +}; +ajaxpage(0); function getFileList(){ var tw = ($(window).width() - $('#window-outter').width())/2; $('#window-outter').css({'right':tw}); @@ -411,8 +414,17 @@ function getSubFileList(uuid,id,depth){ }); } +$('.googlesearch').click(function(){ + googleSearch(''); +}); +$('.bingsearch').click(function(){ + bingSearch(''); +}); +$('.cnkiSearch').click(function(){ + cnkiSearch(''); +}); -function googlesearch(keyword){ +function googleSearch(keyword){ $.ajax({ type:"POST", url:"/service/googlesearch", @@ -421,12 +433,62 @@ function googlesearch(keyword){ var items = []; var obj = jQuery.parseJSON(html); $.each(obj.responseData.results, function(key, val) { - var html = '

'+val['title']+'

'+ - val['url'].replace(/%(.*)/i,"") +'

'+ - val['content'] + var html = '

'+val['title']+'

' + +val['url'].replace(/%(.*)/i,"") +'

' + +val['content'] +'

'; items.push('
  • ' + html + '
  • '); }); + items.push('
  • 查看更多搜索结果(约'+obj.responseData.cursor.estimatedResultCount+'条)
  • '); + $('#searchlist').html(items.join('')); + }, + beforeSend:function(){ + $('#searchlist').html('结果加载中'); + } + }); +} + +function bingSearch(keyword){ + $.ajax({ + type:"POST", + url:"/service/bingsearch", + data:'q='+keyword, + success:function(html){ + var items = []; + var obj = jQuery.parseJSON(html); + $.each(obj.SearchResponse.Web.Results, function(key, val) { + var html = '

    '+val['Title']+'

    ' + +val['DisplayUrl'].replace(/%(.*)/i,"") +'

    ' + +val['Description'] + +'

    '; + items.push('
  • ' + html + '
  • '); + }); + items.push('
  • 查看更多搜索结果(约'+obj.SearchResponse.Web.Total+'条)'); + $('#searchlist').html(items.join('')); + }, + beforeSend:function(){ + $('#searchlist').html('结果加载中'); + } + }); +} + +function cnkiSearch(keyword){ + $.ajax({ + type:"POST", + url:"/service/cnkisearch", + data:'q='+keyword, + success:function(html){ + var items = []; + var obj = jQuery.parseJSON(html); + $.each(obj.result, function(key, val) { + var html = '

    '+val['title']+'

    ' + +val['url'].replace(/%(.*)/i,"") +'

    ' + +val['content'] + +'

    '; + + items.push('
  • ' + html + '
  • '); + }); + items.push('
  • 查看更多搜索结果'); $('#searchlist').html(items.join('')); }, beforeSend:function(){