heihe view中cnki搜索添加了无返回结果的判断

This commit is contained in:
Li Jianxuan 2011-11-28 02:41:26 +00:00
parent 66da794226
commit 9df01d3cbe
2 changed files with 23 additions and 15 deletions

View File

@ -953,6 +953,8 @@ class ServiceController extends Zend_Controller_Action
foreach ($matchs[1] as $k=>$v){ foreach ($matchs[1] as $k=>$v){
if($k < $max) $rev[$k]['url']=$v; if($k < $max) $rev[$k]['url']=$v;
} }
}else{
$error = "无搜索结果";
} }
if(preg_match_all("#<span class=\"search_result_snap\" >(.+?)</span>#i",$body,$matchs,PREG_PATTERN_ORDER)) if(preg_match_all("#<span class=\"search_result_snap\" >(.+?)</span>#i",$body,$matchs,PREG_PATTERN_ORDER))
@ -962,7 +964,7 @@ class ServiceController extends Zend_Controller_Action
} }
} }
$response=array("result"=>$rev,"count"=>$max,"morelink"=>'http://search.cnki.net/search.aspx?q='.$keyword); $response=array("result"=>$rev,"count"=>$max,"morelink"=>'http://search.cnki.net/search.aspx?q='.$keyword,"error"=>$error);
$rev = Zend_Json::encode($response); $rev = Zend_Json::encode($response);
return $rev; return $rev;

View File

@ -91,7 +91,7 @@ else
<?php if (!empty($md->timebegin)) : ?> <?php if (!empty($md->timebegin)) : ?>
<li id="datatimes">数据时间范围:<?php echo date('Y-m-d',strtotime($md->timebegin));if (!empty($md->timeend)) echo " 至 ".date('Y-m-d',strtotime($md->timeend)); ?></li> <li id="datatimes">数据时间范围:<?php echo date('Y-m-d',strtotime($md->timebegin));if (!empty($md->timeend)) echo " 至 ".date('Y-m-d',strtotime($md->timeend)); ?></li>
<?php endif; ?> <?php endif; ?>
<?php if ($this->attachments) : ?> <?php if ($this->attachments) : ?>
<li>相关文档: <li>相关文档:
<?php foreach ($this->attachments as $k=>$a) : ?> <?php foreach ($this->attachments as $k=>$a) : ?>
@ -249,8 +249,8 @@ endforeach;
<ul id="searchlist"> <ul id="searchlist">
</ul> </ul>
</div> </div>
<div id="service"> <div id="service">
<?php if ($this->downhistory) : ?> <?php if ($this->downhistory) : ?>
<p>最近10条服务记录如下</p> <p>最近10条服务记录如下</p>
<ol start="1"> <ol start="1">
<?php <?php
@ -258,9 +258,9 @@ endforeach;
echo '<li>'.date("Y-m-d",strtotime($v->ts_created))." ".$v->unit." ".$v->realname.'</li>'; echo '<li>'.date("Y-m-d",strtotime($v->ts_created))." ".$v->unit." ".$v->realname.'</li>';
} }
?> ?>
</ol> </ol>
<?php else : ?> <?php else : ?>
暂时没有服务记录,欢迎您下载使用! 暂时没有服务记录,欢迎您下载使用!
<?php endif; ?> <?php endif; ?>
</div> </div>
<div id="recommend"> <div id="recommend">
@ -480,14 +480,20 @@ function cnkiSearch(keyword){
success:function(html){ success:function(html){
var items = []; var items = [];
var obj = jQuery.parseJSON(html); var obj = jQuery.parseJSON(html);
$.each(obj.result, function(key, val) { alert(obj.error);
var html = '<p><a href="' +val['url']+'" target="_blank">'+val['title']+'<a/></p><p><span>' if(obj.error != '')
+val['url'].replace(/%(.*)/i,"") +'</span></p><p>' {
+val['content'] items.push('<li>' + obj.error + '</li>');
+'</p>'; }else{
$.each(obj.result, function(key, val) {
items.push('<li>' + html + '</li>'); var html = '<p><a href="' +val['url']+'" target="_blank">'+val['title']+'<a/></p><p><span>'
}); +val['url'].replace(/%(.*)/i,"") +'</span></p><p>'
+val['content']
+'</p>';
items.push('<li>' + html + '</li>');
});
}
items.push('<li class="more"><a href="'+obj.morelink+'" target="_blank">查看更多搜索结果</a></div>'); items.push('<li class="more"><a href="'+obj.morelink+'" target="_blank">查看更多搜索结果</a></div>');
$('#searchlist').html(items.join('')); $('#searchlist').html(items.join(''));
$('html, body').animate({scrollTop:$('html').height()}, 'slow'); $('html, body').animate({scrollTop:$('html').height()}, 'slow');