实现高级搜索功能。
This commit is contained in:
parent
1c77aaea35
commit
57697afa39
|
@ -397,33 +397,29 @@ class DataController extends Zend_Controller_Action
|
||||||
$this->view->addHelperPath('helper','Zend_View_Helper_');
|
$this->view->addHelperPath('helper','Zend_View_Helper_');
|
||||||
$form=new SearchForm();
|
$form=new SearchForm();
|
||||||
$this->view->form=$form;
|
$this->view->form=$form;
|
||||||
$form->submit->setLabel('快速搜索');
|
//$form->submit->setLabel('快速搜索');
|
||||||
if ($this->_request->isPost()) {
|
$key=$this->_request->getParam('q');
|
||||||
$formData=$this->_request->getPost();
|
if (!empty($key)) {
|
||||||
include_once("bcspamblock.php");
|
//$formData=$this->_request->getPost();
|
||||||
if (bcspamblock_verify() && $form->isValid($formData)) {
|
//include_once("bcspamblock.php");
|
||||||
$page=@(int)$formData['page'];
|
//if ($form->isValid($formData)) {
|
||||||
|
$page=@(int)$this->_request->getParam('page');
|
||||||
if (empty($page)) $page=1;
|
if (empty($page)) $page=1;
|
||||||
$limit=10;
|
$limit=10;
|
||||||
$offset=$limit*($page-1);
|
$offset=$limit*($page-1);
|
||||||
$key=$formData['q'];
|
|
||||||
if (!empty($key)) {
|
if (!empty($key)) {
|
||||||
$md=new MetadataTable();
|
$md=new MetadataTable();
|
||||||
$db=$md->getAdapter();
|
$db=$md->getAdapter();
|
||||||
$sql=$db->quoteInto('select count(*) from metadata where title ilike ? or description ilike ?','%'.$key.'%','%'.$key.'%');
|
$sql=$db->quoteInto('select count(*) from metadata where title ilike ? or description ilike ?','%'.$key.'%');
|
||||||
$state=$db->query($sql);
|
$state=$db->query($sql);
|
||||||
$row=$state->fetchAll();
|
$row=$state->fetchAll();
|
||||||
$sum=$row[0]['count'];
|
$sum=$row[0]['count'];
|
||||||
$select=$db->select();
|
$select=$db->select();
|
||||||
$select->from('metadata','*')->where('title ilike ? or description ilike ?','%'.$key.'%','%'.$key.'%')->order('id desc')->limit($limit,$offset);
|
$select->from('metadata','*')->where('title ilike ? or description ilike ?','%'.$key.'%')->order('id desc')->limit($limit,$offset);
|
||||||
$this->view->metadata = $db->fetchAll($select);
|
$this->view->metadata = $db->fetchAll($select);
|
||||||
$this->view->page=new Pagination($sum,$page);
|
$this->view->page=new Pagination($sum,$page);
|
||||||
$this->view->key=$key;
|
$this->view->key=$key;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
@ -431,21 +427,40 @@ class DataController extends Zend_Controller_Action
|
||||||
*/
|
*/
|
||||||
function advancesearchAction()
|
function advancesearchAction()
|
||||||
{
|
{
|
||||||
|
$this->view->addHelperPath('helper','Zend_View_Helper_');
|
||||||
|
$form=new SearchForm();
|
||||||
|
$this->view->form=$form;
|
||||||
|
|
||||||
$md=new MetadataTable();
|
$md=new MetadataTable();
|
||||||
$db=$md->getAdapter();
|
$db=$md->getAdapter();
|
||||||
$page=(int)$this->_request->getParam('page');
|
$page=(int)$this->_request->getParam('page');
|
||||||
if (empty($page)) $page=1;
|
if (empty($page)) $page=1;
|
||||||
$limit=10;
|
$limit=10;
|
||||||
$offset=$limit*($page-1);
|
$offset=$limit*($page-1);
|
||||||
$key=$this->_request->getParam('key');
|
$key=$this->_request->getParam('q');
|
||||||
$searchtype=$this->_request->getParam('type');
|
$n=(int)$this->_request->getParam('n');
|
||||||
|
$s=(int)$this->_request->getParam('s');
|
||||||
|
$e=(int)$this->_request->getParam('e');
|
||||||
|
$w=(int)$this->_request->getParam('w');
|
||||||
|
if (!(empty($n) && empty($key))) {
|
||||||
|
if (empty($n)) $n=90;
|
||||||
|
if (empty($s)) $s=-90;
|
||||||
|
if (empty($e)) $e=180;
|
||||||
|
if (empty($w)) $w=-180;
|
||||||
|
$start=$this->_request->getParam('start');
|
||||||
|
$end=$this->_request->getParam('end');
|
||||||
if (!empty($key)) {
|
if (!empty($key)) {
|
||||||
$sql=$db->quoteInto('select count(*) from metadata where title ilike ? or description ilike ?','%'.$key.'%','%'.$key.'%');
|
$sql='select count(*) from metadata where east<? and west>? and north<? and south>? and (title ilike ? or description ilike ?)';
|
||||||
$state=$db->query($sql);
|
$row=$db->fetchAll($sql,array($e,$w,$n,$s,'%'.$key.'%','%'.$key.'%'));
|
||||||
$row=$state->fetchAll();
|
} else {
|
||||||
|
$sql='select count(*) from metadata where east<? and west>? and north<? and south>?';
|
||||||
|
$row=$db->fetchAll($sql,array($e,$w,$n,$s));
|
||||||
|
}
|
||||||
$sum=$row[0]['count'];
|
$sum=$row[0]['count'];
|
||||||
$select=$db->select();
|
$select=$db->select();
|
||||||
$select->from('metadata','*')->where('title ilike ? or description ilike ?','%'.$key.'%','%'.$key.'%')->order('id desc')->limit($limit,$offset);
|
$select->from('metadata','*')->where('east<?',$e)->where('west>?',$w)->where('north<?',$n)->where('south>?',$s);
|
||||||
|
if (!empty($key)) $select->where('(title ilike ? or description ilike ?)','%'.$key.'%');
|
||||||
|
$select->order('id desc')->limit($limit,$offset);
|
||||||
$this->view->metadata = $db->fetchAll($select);
|
$this->view->metadata = $db->fetchAll($select);
|
||||||
$this->view->page=new Pagination($sum,$page);
|
$this->view->page=new Pagination($sum,$page);
|
||||||
$this->view->key=$key;
|
$this->view->key=$key;
|
||||||
|
|
|
@ -0,0 +1,108 @@
|
||||||
|
<?php
|
||||||
|
$this->headTitle($this->config->title->site);
|
||||||
|
$this->headTitle($this->config->title->data);
|
||||||
|
|
||||||
|
$this->headTitle('高级搜索');
|
||||||
|
if (!empty($this->codename)) $this->headTitle($this->codename);
|
||||||
|
$this->headTitle()->setSeparator(' - ');
|
||||||
|
$this->headLink()->appendStylesheet('/css/metadata.css');
|
||||||
|
$this->headLink()->appendStylesheet('/css/search.css');
|
||||||
|
$this->breadcrumb('<a href="/">首页</a>');
|
||||||
|
$this->breadcrumb('<a href="/data">'.$this->config->title->data.'</a>');
|
||||||
|
$this->breadcrumb('高级搜索');
|
||||||
|
$this->breadcrumb()->setSeparator(' > ');
|
||||||
|
?>
|
||||||
|
<div id='tools'>
|
||||||
|
<?= $this->partial('data/tools.phtml'); ?>
|
||||||
|
</div>
|
||||||
|
<?php echo $this->form; ?>
|
||||||
|
<a href="/data/advancesearch">高级搜索</a>
|
||||||
|
<?php if (!empty($this->metadata)) : ?>
|
||||||
|
<?php echo $this->page->getNavigation();
|
||||||
|
foreach($this->metadata as $md) : ?>
|
||||||
|
<hr />
|
||||||
|
<div class="mditem">
|
||||||
|
<div class="thumb"><img src="/data/thumb/id/<?php echo $md['id'];?>" /></div>
|
||||||
|
<h2><a href="/data/<?php echo $md['uuid'];?>"><?php echo $this->escape($md['title']);?></a>
|
||||||
|
</h2>
|
||||||
|
<span><?php echo mb_strlen($md['description'])>400?$this->escape(mb_substr($md['description'],0,400,'UTF-8').'...'):$this->escape($md['description']);?></span>
|
||||||
|
</div>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<hr />
|
||||||
|
<?php echo $this->page->getNavigation();?>
|
||||||
|
<?php else: ?>
|
||||||
|
<script src='http://maps.google.com/maps?file=api&v=2&key=ABQIAAAACD-MqkkoOm60o_dvwdcKVhThiRESR0xRCe9JKd36EL3glTk0OxTsRzifkUWmTTrYWaE7dY1lYUlGxA'></script>
|
||||||
|
<script src="/js/dragzoom.js" type="text/javascript"></script>
|
||||||
|
<div id="map"></div>
|
||||||
|
<div id="spatial">
|
||||||
|
<form id="search" enctype="application/x-www-form-urlencoded" action="/data/advancesearch" method="post">
|
||||||
|
<!--<fieldset><legend>时间范围</legend><ul>
|
||||||
|
<li><span>开始时间:</span>
|
||||||
|
<input name="start" type="text" id="start" />
|
||||||
|
</li>
|
||||||
|
<li><span>结束时间:</span>
|
||||||
|
<input name="end" type="text" id="end" />
|
||||||
|
</li></ul></fieldset>-->
|
||||||
|
<fieldset><legend>空间范围</legend><ul>
|
||||||
|
<li><span>东:</span>
|
||||||
|
|
||||||
|
<input name="e" id="e" type="text" /></li>
|
||||||
|
<li><span>南:</span>
|
||||||
|
<input name="s" id="s" type="text" /></li>
|
||||||
|
<li><span>西:</span>
|
||||||
|
<input name="w" id="w" type="text" /></li>
|
||||||
|
<li><span>北:</span>
|
||||||
|
<input name="n" id="n" type="text" /></li></ul></fieldset>
|
||||||
|
<span>关键词:</span><input name="q" id="q" type="text" />
|
||||||
|
<input id="search" type="submit" value="搜索" onclick="dosubmit()" />
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
function dosubmit()
|
||||||
|
{
|
||||||
|
theForm.action="/data/advancesearch";
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
var map = new GMap2(document.getElementById("map"));
|
||||||
|
map.setCenter(new GLatLng(36, 103.5, 5));
|
||||||
|
map.addControl(new GSmallMapControl());
|
||||||
|
map.addControl(new GMapTypeControl());
|
||||||
|
map.setMapType(G_HYBRID_MAP);
|
||||||
|
var txte=document.getElementById("e");
|
||||||
|
var txtw=document.getElementById("w");
|
||||||
|
var txtn=document.getElementById("n");
|
||||||
|
var txts=document.getElementById("s");
|
||||||
|
/* first set of options is for the visual overlay.*/
|
||||||
|
var boxStyleOpts = {
|
||||||
|
opacity: .2,
|
||||||
|
border: "2px solid red"
|
||||||
|
}
|
||||||
|
|
||||||
|
/* second set of options is for everything else */
|
||||||
|
var otherOpts = {
|
||||||
|
buttonHTML: "<img src='/images/zoom-button.gif' />",
|
||||||
|
buttonZoomingHTML: "<img src='/images/zoom-button-activated.gif' />",
|
||||||
|
buttonStartingStyle: {width: '24px', height: '24px'}
|
||||||
|
};
|
||||||
|
|
||||||
|
/* third set of options specifies callbacks */
|
||||||
|
var callbacks = {
|
||||||
|
dragend: function(nw,ne,se,sw,nwpx,nepx,sepx,swpx){txte.value=ne.lng();txtn.value=ne.lat();txts.value=sw.lat();txtw.value=sw.lng();}
|
||||||
|
};
|
||||||
|
|
||||||
|
map.addControl(new DragZoomControl(boxStyleOpts, otherOpts, callbacks));
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div id="help">
|
||||||
|
<fieldset><legend>搜索说明</legend><ul><li>关键词:您可以使用一个关键词,比如"沙漠",也可以使用多个关键词,中间用空格分开。</li>
|
||||||
|
<li>空间范围:这是以度为单位的十进制数字。比如,东经125读30分,可以输入为125.5。您也可以通过下面的在线地图工具直接在图上拉框选择一个范围,空间坐标会自动转换到文本框中。</li>
|
||||||
|
<li>时间范围:指数据的时间范围,从开始时间到结束时间,若结束时间不填,则是一个时间点。时间格式为YYYY-MM-DD。</li>
|
||||||
|
<li>还不清楚?您可以到<a href="http://forum.westgis.ac.cn/viewforum.php?f=30">论坛</a>提问。</li>
|
||||||
|
</ul></fieldset>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<?php endif; ?>
|
|
@ -26,4 +26,7 @@ foreach($this->metadata as $md) : ?>
|
||||||
</h2>
|
</h2>
|
||||||
<span><?php echo mb_strlen($md['description'])>400?$this->escape(mb_substr($md['description'],0,400,'UTF-8').'...'):$this->escape($md['description']);?></span>
|
<span><?php echo mb_strlen($md['description'])>400?$this->escape(mb_substr($md['description'],0,400,'UTF-8').'...'):$this->escape($md['description']);?></span>
|
||||||
</div>
|
</div>
|
||||||
<?php endforeach; endif?>
|
<?php endforeach; ?>
|
||||||
|
<hr />
|
||||||
|
<?php echo $this->page->getNavigation();?>
|
||||||
|
<?php endif; ?>
|
|
@ -13,15 +13,10 @@ class SearchForm extends Zend_Form
|
||||||
->addFilter('StringTrim')
|
->addFilter('StringTrim')
|
||||||
->addValidator('NotEmpty');
|
->addValidator('NotEmpty');
|
||||||
|
|
||||||
$spam=new element_bcSpamBlock('spam');
|
|
||||||
$spam->addPrefixPath('Validator','validator/','validate')
|
|
||||||
->addValidator('SpamBlock');
|
|
||||||
|
|
||||||
$id = new Zend_Form_Element_Hidden('id');
|
|
||||||
|
|
||||||
$submit = new Zend_Form_Element_Submit('submit');
|
$submit = new Zend_Form_Element_Submit('submit');
|
||||||
$submit->setLabel('搜索');
|
$submit->setLabel('搜索');
|
||||||
$this->addElements(array($q,$submit,$spam,$id));
|
$this->addElements(array($q,$submit));
|
||||||
$this->clearDecorators();
|
$this->clearDecorators();
|
||||||
$this->addDecorator('FormElements')
|
$this->addDecorator('FormElements')
|
||||||
->addDecorator('HtmlTag', array('tag' => '<ul>'))
|
->addDecorator('HtmlTag', array('tag' => '<ul>'))
|
||||||
|
|
Loading…
Reference in New Issue