Exemple #1
0
 /**
 * 重载父类getResult()方法,把原先的query参数和filters参数合并成一个数组传入
 * 数组格式为:
 * 	$arr = array(
 		array('marriage','4'),//字段搜索
 		array('city','1,2,3',EXCLUDE_FALSE),//单值或多值属性
 		array('province',array(1,2),EXCLUDE_FALSE),//区间属性
 		);
 		每个字段对应一个数组元素,如果是查询索引字段,则第一个元素为索引字段名,第二个元素为查询值 eg:array('marriage','4')
 		如果字段是属性,则,元素一为字段名,元素二为字段值,元素三为是否为排序搜索,值为true或false,由EXCLUDE_开头的常量表示
 		调用该方法前请先设置查询类型
 		$this->setQueryType($type);
 		使用实例:
 		$arr1 = array(array('s_cid','0'));//单值
 		$arr2 = array(array('s_cid','0,1,2'));//多值
 		$arr3 = array(array('s_cid',array('0','2')));//区间
 		$arr4 = array(array('username','fl_dream@163.com,139580051@qq.com'));//用户名搜索
 		$arr5 = array(array('marriage','4'),array('s_cid',array('0','2')));//字段,属性 搜索
 		//$cl->setQueryType(true);
 		$rs  = $cl->getResult($arr5);
 * @see search::getResult()
 */
 public function getResult($arr, $limit = null, $sorts = null, $groups = null)
 {
     $this->parsePramas($arr);
     $this->parseLimit($limit);
     $this->parseSort($sorts);
     $this->parseGroupBy($groups);
     echo $this->queryStr;
     return parent::getResults(rtrim($this->queryStr, '|'), $this->limit_arr, $this->sorts_arr, $this->filtersArr, $this->groups_arr);
 }
<h1>Search</h1>
<?php 
if (isset($_POST['string'])) {
    echo 'You have searched for: <strong>' . htmlspecialchars($_POST['string']) . '</strong>';
    $search = new search($_POST['string']);
    $puzzles = $search->getResults();
    for ($i = 0; $i < count($puzzles); $i++) {
        $output = '<div>';
        $output .= '<h2><a href="' . SITE_URL . '/index.php?p=puzzle&id=' . $puzzles[$i]['picture_id'] . '">' . htmlentities($puzzles[$i]['titel']) . '</a></h2>';
        $output .= '<p>Gemaakt door: <br /> ' . htmlentities($puzzles[$i]['username']) . '</p>';
        $output .= '</div>';
        echo $output;
    }
}