note 70396 deleted from ref.mnogosearch by betz
| From: | betz@php.net | Date: | Sun, 15 Oct 2006 09:51:25 +0000 |
| Subject: | note 70396 deleted from ref.mnogosearch by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-118541@lists.php.net to get a copy of this message | ||
Note Submitter: mikko at sorl dot net
----
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);
}
}
?>