From 57697afa39b57010d4f780ad763c7840cf2bb8ef Mon Sep 17 00:00:00 2001 From: wlx Date: Fri, 27 Nov 2009 14:20:19 +0000 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E9=AB=98=E7=BA=A7=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E5=8A=9F=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/controllers/DataController.php | 59 ++++++---- .../views/scripts/data/advancesearch.phtml | 108 ++++++++++++++++++ .../default/views/scripts/data/search.phtml | 5 +- application/models/SearchForm.php | 9 +- 4 files changed, 151 insertions(+), 30 deletions(-) create mode 100644 application/default/views/scripts/data/advancesearch.phtml diff --git a/application/default/controllers/DataController.php b/application/default/controllers/DataController.php index 2c363099..f8d9d4c0 100755 --- a/application/default/controllers/DataController.php +++ b/application/default/controllers/DataController.php @@ -397,33 +397,29 @@ class DataController extends Zend_Controller_Action $this->view->addHelperPath('helper','Zend_View_Helper_'); $form=new SearchForm(); $this->view->form=$form; - $form->submit->setLabel('快速搜索'); - if ($this->_request->isPost()) { - $formData=$this->_request->getPost(); - include_once("bcspamblock.php"); - if (bcspamblock_verify() && $form->isValid($formData)) { - $page=@(int)$formData['page']; + //$form->submit->setLabel('快速搜索'); + $key=$this->_request->getParam('q'); + if (!empty($key)) { + //$formData=$this->_request->getPost(); + //include_once("bcspamblock.php"); + //if ($form->isValid($formData)) { + $page=@(int)$this->_request->getParam('page'); if (empty($page)) $page=1; $limit=10; $offset=$limit*($page-1); - $key=$formData['q']; if (!empty($key)) { $md=new MetadataTable(); $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); $row=$state->fetchAll(); $sum=$row[0]['count']; $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->page=new Pagination($sum,$page); $this->view->key=$key; } - - } - } else { - } } /* @@ -431,25 +427,44 @@ class DataController extends Zend_Controller_Action */ function advancesearchAction() { + $this->view->addHelperPath('helper','Zend_View_Helper_'); + $form=new SearchForm(); + $this->view->form=$form; + $md=new MetadataTable(); $db=$md->getAdapter(); $page=(int)$this->_request->getParam('page'); if (empty($page)) $page=1; $limit=10; $offset=$limit*($page-1); - $key=$this->_request->getParam('key'); - $searchtype=$this->_request->getParam('type'); - if (!empty($key)) { - $sql=$db->quoteInto('select count(*) from metadata where title ilike ? or description ilike ?','%'.$key.'%','%'.$key.'%'); - $state=$db->query($sql); - $row=$state->fetchAll(); + $key=$this->_request->getParam('q'); + $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)) { + $sql='select count(*) from metadata where east? and north? and (title ilike ? or description ilike ?)'; + $row=$db->fetchAll($sql,array($e,$w,$n,$s,'%'.$key.'%','%'.$key.'%')); + } else { + $sql='select count(*) from metadata where east? and north?'; + $row=$db->fetchAll($sql,array($e,$w,$n,$s)); + } $sum=$row[0]['count']; $select=$db->select(); - $select->from('metadata','*')->where('title ilike ? or description ilike ?','%'.$key.'%','%'.$key.'%')->order('id desc')->limit($limit,$offset); + $select->from('metadata','*')->where('eastwhere('west>?',$w)->where('northwhere('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->page=new Pagination($sum,$page); - $this->view->key=$key; - } + $this->view->key=$key; + } } /* * 根据id或uuid来查看元数据 diff --git a/application/default/views/scripts/data/advancesearch.phtml b/application/default/views/scripts/data/advancesearch.phtml new file mode 100644 index 00000000..e4766ad8 --- /dev/null +++ b/application/default/views/scripts/data/advancesearch.phtml @@ -0,0 +1,108 @@ +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('首页'); +$this->breadcrumb(''.$this->config->title->data.''); +$this->breadcrumb('高级搜索'); +$this->breadcrumb()->setSeparator(' > '); +?> +
+partial('data/tools.phtml'); ?> +
+form; ?> +高级搜索 +metadata)) : ?> +page->getNavigation(); +foreach($this->metadata as $md) : ?> +
+
+
+

escape($md['title']);?> +

+ 400?$this->escape(mb_substr($md['description'],0,400,'UTF-8').'...'):$this->escape($md['description']);?> +
+ +
+page->getNavigation();?> + + + +
+
+ +
+ + + + +
+
搜索说明
  • 关键词:您可以使用一个关键词,比如"沙漠",也可以使用多个关键词,中间用空格分开。
  • +
  • 空间范围:这是以度为单位的十进制数字。比如,东经125读30分,可以输入为125.5。您也可以通过下面的在线地图工具直接在图上拉框选择一个范围,空间坐标会自动转换到文本框中。
  • +
  • 时间范围:指数据的时间范围,从开始时间到结束时间,若结束时间不填,则是一个时间点。时间格式为YYYY-MM-DD。
  • +
  • 还不清楚?您可以到论坛提问。
  • +
+
+ + + + \ No newline at end of file diff --git a/application/default/views/scripts/data/search.phtml b/application/default/views/scripts/data/search.phtml index 105e9904..af8ee3ae 100755 --- a/application/default/views/scripts/data/search.phtml +++ b/application/default/views/scripts/data/search.phtml @@ -26,4 +26,7 @@ foreach($this->metadata as $md) : ?> 400?$this->escape(mb_substr($md['description'],0,400,'UTF-8').'...'):$this->escape($md['description']);?> - \ No newline at end of file + +
+page->getNavigation();?> + \ No newline at end of file diff --git a/application/models/SearchForm.php b/application/models/SearchForm.php index 95fbaee8..ad7f9464 100755 --- a/application/models/SearchForm.php +++ b/application/models/SearchForm.php @@ -13,15 +13,10 @@ class SearchForm extends Zend_Form ->addFilter('StringTrim') ->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->setLabel('搜索'); - $this->addElements(array($q,$submit,$spam,$id)); + $this->addElements(array($q,$submit)); $this->clearDecorators(); $this->addDecorator('FormElements') ->addDecorator('HtmlTag', array('tag' => '