note 70396 added to ref.mnogosearch
| From: | mikko at sorl dot net | Date: | Sat, 14 Oct 2006 21:01:56 +0000 |
| Subject: | note 70396 added to ref.mnogosearch | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-118529@lists.php.net to get a copy of this message | ||
Here is a simple class to use with Mnogosearch + php5,
usage:
<?php
$test = new MnogoSearch;
$test->find("search string",0,10);
$test->fetch();
?>
$test->matches contains an array with the matches and
$test->total contains the total nr of matches
find takes "search string", pagenr, rows/page as arguments.
good luck!
<?php
class MnogoSearch
{
public $matches = NULL;
public $total = NULL;
protected $agent = NULL;
protected $res = NULL;
public function __construct() {
$this->agent = udm_alloc_agent('mysql://user:password@localhost/database/');
$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);
$this->set(UDM_PARAM_MIN_WORD_LEN, 3);
$this->set(UDM_PARAM_MAX_WORD_LEN, 100);
}
public function set($k, $v) {
udm_set_agent_param($this->agent, $k, $v);
}
public function fetch() {
$t = udm_get_res_param($this->res, UDM_PARAM_FOUND);
$b = udm_get_res_param($this->res, UDM_PARAM_FIRST_DOC);
$e = udm_get_res_param($this->res, UDM_PARAM_LAST_DOC);
if ($b <= $t) {
$this->total = $t;
$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<=$e-$b; $i++) {
for($j=0; $j<count($fields); $j++) {
$this->matches[$i][$fields[$j]] = udm_get_res_field($this->res, $i, $j+1);
}
}
}
}
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);
}
public function __destruct() {
udm_free_res($this->res);
udm_free_agent($this->agent);
}
}
?>
----
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/70396
Del: integrated -- https://master.php.net/note/delete/70396/integrated
Del: useless -- https://master.php.net/note/delete/70396/useless
Del: bad code -- https://master.php.net/note/delete/70396/bad+code
Del: spam -- https://master.php.net/note/delete/70396/spam
Del: non-english -- https://master.php.net/note/delete/70396/non-english
Del: in docs -- https://master.php.net/note/delete/70396/in+docs
Del: other reasons-- https://master.php.net/note/delete/70396
Reject -- https://master.php.net/note/reject/70396
Search -- https://master.php.net/manage/user-notes.php