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){
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))
@ -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);
return $rev;

View File

@ -91,7 +91,7 @@ else
<?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>
<?php endif; ?>
<?php if ($this->attachments) : ?>
<li>相关文档:
<?php foreach ($this->attachments as $k=>$a) : ?>
@ -249,8 +249,8 @@ endforeach;
<ul id="searchlist">
</ul>
</div>
<div id="service">
<?php if ($this->downhistory) : ?>
<div id="service">
<?php if ($this->downhistory) : ?>
<p>最近10条服务记录如下</p>
<ol start="1">
<?php
@ -258,9 +258,9 @@ endforeach;
echo '<li>'.date("Y-m-d",strtotime($v->ts_created))." ".$v->unit." ".$v->realname.'</li>';
}
?>
</ol>
<?php else : ?>
暂时没有服务记录,欢迎您下载使用!
</ol>
<?php else : ?>
暂时没有服务记录,欢迎您下载使用!
<?php endif; ?>
</div>
<div id="recommend">
@ -480,14 +480,20 @@ function cnkiSearch(keyword){
success:function(html){
var items = [];
var obj = jQuery.parseJSON(html);
$.each(obj.result, function(key, val) {
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>');
});
alert(obj.error);
if(obj.error != '')
{
items.push('<li>' + obj.error + '</li>');
}else{
$.each(obj.result, function(key, val) {
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>');
$('#searchlist').html(items.join(''));
$('html, body').animate({scrollTop:$('html').height()}, 'slow');