note 70406 added to ref.mnogosearch

From: Date: Sun, 15 Oct 2006 11:46:53 +0000
Subject: note 70406 added to ref.mnogosearch
Groups: php.notes 
Request: Send a blank email to php-notes+get-118545@lists.php.net to get a copy of this message
Well since the function udm_get_res_param used with UDM_PARAM_NUM_ROWS does infact not get the number of rows on the current page, it can actualy find more rows than specified by UDM_PARAM_PAGE_SIZE, ??? well i had to rewrite the some stuff I also added highlightning since the parameter UDM_PARAM_HLBEG nor UDM_PARAM_HLEND doesnt seem to work, alot of things here are fairly undocumented, I also found out after reading the Search_Mnogosearch pear class that replacing "\2" and "\3" in the text with HLBEG and HLEND works. well here is the class rewritten (without fetch, just find): <?php class MnogoSearch { public $matches = NULL; public $total = NULL; public $hilites = array('title', 'text'); public $hlbeg = '<span class="hilite">'; public $hlend = '</span>'; protected $agent = NULL; protected $res = NULL; public function __construct() { $this->agent = udm_alloc_agent('mysql://user:pass@localhost/mnogosearch/'); $this->set(UDM_PARAM_SEARCH_MODE, UDM_MODE_ALL); $this->set(UDM_PARAM_CHARSET, 'iso-8859-1'); $this->set(UDM_PARAM_BROWSER_CHARSET, 'iso-8859-1'); $this->set(UDM_PARAM_WORD_MATCH, UDM_MATCH_SUBSTR); } private function hiLite($t) { if ($t == '') return ''; $t = str_replace("\2", $this->hlbeg, $t); $t = str_replace("\3", $this->hlend, $t); return $t; } public function set($k, $v) { udm_set_agent_param($this->agent, $k, $v); } public function find($q, $page=0, $rows=10) { if ($page < 0 || $rows <= 0) { $page = 0; $rows = 10; } $this->set(UDM_PARAM_PAGE_SIZE, $rows); $this->set(UDM_PARAM_PAGE_NUM, $page); $this->res = udm_find($this->agent, $q); $this->total = udm_get_res_param($this->res, UDM_PARAM_FOUND); $found = udm_get_res_param($this->res, UDM_PARAM_NUM_ROWS); if($found) { $b = udm_get_res_param($this->res, UDM_PARAM_FIRST_DOC); $e = udm_get_res_param($this->res, UDM_PARAM_LAST_DOC); $rows = $e - $b + 1; $fields = array('urlid', 'url', 'content', 'title', 'keywords', 'desc', 'text', 'size', 'rating', 'modified', 'order', 'crc', 'category', 'lang', 'charset', 'siteid', 'pop_rank', 'originid'); for($i=0; $i<$rows; $i++){ for($j=0; $j<count($fields); $j++) { $this->matches[$i][$fields[$j]] = udm_get_res_field($this->res, $i, $j+1); } foreach($this->hilites as $hilite) { $this->matches[$i][$hilite] = $this->hiLite($this->matches[$i][$hilite]); } } return $rows; } else { return FALSE; } } public function __destruct() { udm_free_agent($this->agent); if (isset($this->res)) { udm_free_res($this->res); } } } ?> Im thinking, maybe swish-e is better ? :) ---- Server IP: 129.16.214.50 Probable Submitter: 213.114.99.43 (proxied: 127.0.0.1) ---- Manual Page -- http://www.php.net/manual/en/ref.mnogosearch.php Edit -- https://master.php.net/note/edit/70406 Del: integrated -- https://master.php.net/note/delete/70406/integrated Del: useless -- https://master.php.net/note/delete/70406/useless Del: bad code -- https://master.php.net/note/delete/70406/bad+code Del: spam -- https://master.php.net/note/delete/70406/spam Del: non-english -- https://master.php.net/note/delete/70406/non-english Del: in docs -- https://master.php.net/note/delete/70406/in+docs Del: other reasons-- https://master.php.net/note/delete/70406 Reject -- https://master.php.net/note/reject/70406 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#118545) next »