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 ? :)
LXXXVII. mnoGoSearch
Introduction
Ces fonctions donnent l'accès à mnoGoSearch (anciennement UdmSearch), moteur de recherche du monde libre. mnoGoSearch est un moteur de recherche complet, destiné aux intranets et serveurs web, distribué sous licence GNU. MnoGoSearch offre des fonctionnalités unique, qui en font un excellent outil pour un grand nombre d'applications de recherche dans votre site : recherche de recettes de cuisines ou dans les journaux, recherche dans un site FTP, dans les groupes de news, etc. Il offre un système d'indexation de textes pour les fichiers HTML, PDF et documents textes. MnoGoSearch est constitué de deux parties : l'indexeur, qui effectue les recherches et le moteur de recherche. L'indexeur passe en revue récursivement les sites HTTP, FTP, NEWS ou encore les fichiers locaux, et enregistre des méta-données dans les bases MySQL, pour optimiser les recherches ultérieures. Une fois que tous les documents ont été référencés, ils sont accessibles au moteur de recherche. Celui-ci est utilisable par interface web. Les langages C CGI, Perl et PHP sont supportés pour effectuer les recherches.
Plus de détails sur le site officiel de mnoGoSearch : http://www.mnogosearch.org/.
Note : Cette extension a été déplacée dans le module PECL et ne sera plus intégrée dans PHP à partir de PHP 5.1.0.
Note : Cette extension n'est pas disponible sur les plates-formes Windows.
Pré-requis
Téléchargez mnoGosearch sur le site http://www.mnogosearch.org/ et installez-le sur votre système. Vous aurez besoin de la version 3.1.10 ou plus récente de mnoGoSearch, pour pouvoir utiliser ces fonctions.
Installation
Pour pouvoir les utiliser, vous devez inclure le support en ajoutant l'option --with-mnogosearch. Si vous utilisez cette option sans indiquer le chemin jusqu'à mnogosearch, PHP essaiera de le trouver dans le dossier /usr/local/mnogosearch. Si vous avez installé mnogosearch dans un autre endroit, vous devez l'indiquer comme ceci : --with-mnogosearch=DIR.
Note : PHP supporte naturellement MySQL. Il faut savoir que mnoGoSearch n'est pas compatible avec la bibliothèque interne de PHP, et ne peut fonctionner qu'avec les bibliothèques génériques MySQL. Par conséquent, si vous utilisez mnoGoSearch avec MySQL, indiquez le dossier d'installation de MySQL durant la configuration avec l'option : --with-mnogosearch --with-mysql=/usr.
Configuration à l'exécution
Cette extension ne définit aucune directive de configuration.
Constantes pré-définies
Ces constantes sont définies par cette extension, et ne sont disponibles que si cette extension a été compilée avec PHP, ou bien chargée au moment de l'exécution.
- UDM_FIELD_URLID (entier)
- UDM_FIELD_URL (entier)
- UDM_FIELD_CONTENT (entier)
- UDM_FIELD_TITLE (entier)
- UDM_FIELD_KEYWORDS (entier)
- UDM_FIELD_DESC (entier)
- UDM_FIELD_DESCRIPTION (entier)
- UDM_FIELD_TEXT (entier)
- UDM_FIELD_SIZE (entier)
- UDM_FIELD_RATING (entier)
- UDM_FIELD_SCORE (entier)
- UDM_FIELD_MODIFIED (entier)
- UDM_FIELD_ORDER (entier)
- UDM_FIELD_CRC (entier)
- UDM_FIELD_CATEGORY (entier)
- UDM_FIELD_LANG (entier)
- UDM_FIELD_CHARSET (entier)
- UDM_PARAM_PAGE_SIZE (entier)
- UDM_PARAM_PAGE_NUM (entier)
- UDM_PARAM_SEARCH_MODE (entier)
- UDM_PARAM_CACHE_MODE (entier)
- UDM_PARAM_TRACK_MODE (entier)
- UDM_PARAM_PHRASE_MODE (entier)
- UDM_PARAM_CHARSET (entier)
- UDM_PARAM_LOCAL_CHARSET (entier)
- UDM_PARAM_BROWSER_CHARSET (entier)
- UDM_PARAM_STOPTABLE (entier)
- UDM_PARAM_STOP_TABLE (entier)
- UDM_PARAM_STOPFILE (entier)
- UDM_PARAM_STOP_FILE (entier)
- UDM_PARAM_WEIGHT_FACTOR (entier)
- UDM_PARAM_WORD_MATCH (entier)
- UDM_PARAM_MAX_WORD_LEN (entier)
- UDM_PARAM_MAX_WORDLEN (entier)
- UDM_PARAM_MIN_WORD_LEN (entier)
- UDM_PARAM_MIN_WORDLEN (entier)
- UDM_PARAM_ISPELL_PREFIXES (entier)
- UDM_PARAM_ISPELL_PREFIX (entier)
- UDM_PARAM_PREFIXES (entier)
- UDM_PARAM_PREFIX (entier)
- UDM_PARAM_CROSS_WORDS (entier)
- UDM_PARAM_CROSSWORDS (entier)
- UDM_PARAM_VARDIR (entier)
- UDM_PARAM_DATADIR (entier)
- UDM_PARAM_HLBEG (entier)
- UDM_PARAM_HLEND (entier)
- UDM_PARAM_SYNONYM (entier)
- UDM_PARAM_SEARCHD (entier)
- UDM_PARAM_QSTRING (entier)
- UDM_PARAM_REMOTE_ADDR (entier)
- UDM_LIMIT_CAT (entier)
- UDM_LIMIT_URL (entier)
- UDM_LIMIT_TAG (entier)
- UDM_LIMIT_LANG (entier)
- UDM_LIMIT_DATE (entier)
- UDM_PARAM_FOUND (entier)
- UDM_PARAM_NUM_ROWS (entier)
- UDM_PARAM_WORDINFO (entier)
- UDM_PARAM_WORD_INFO (entier)
- UDM_PARAM_SEARCHTIME (entier)
- UDM_PARAM_SEARCH_TIME (entier)
- UDM_PARAM_FIRST_DOC (entier)
- UDM_PARAM_LAST_DOC (entier)
- UDM_MODE_ALL (entier)
- UDM_MODE_ANY (entier)
- UDM_MODE_BOOL (entier)
- UDM_MODE_PHRASE (entier)
- UDM_CACHE_ENABLED (entier)
- UDM_CACHE_DISABLED (entier)
- UDM_TRACK_ENABLED (entier)
- UDM_TRACK_DISABLED (entier)
- UDM_PHRASE_ENABLED (entier)
- UDM_PHRASE_DISABLED (entier)
- UDM_CROSS_WORDS_ENABLED (entier)
- UDM_CROSSWORDS_ENABLED (entier)
- UDM_CROSS_WORDS_DISABLED (entier)
- UDM_CROSSWORDS_DISABLED (entier)
- UDM_PREFIXES_ENABLED (entier)
- UDM_PREFIX_ENABLED (entier)
- UDM_ISPELL_PREFIXES_ENABLED (entier)
- UDM_ISPELL_PREFIX_ENABLED (entier)
- UDM_PREFIXES_DISABLED (entier)
- UDM_PREFIX_DISABLED (entier)
- UDM_ISPELL_PREFIXES_DISABLED (entier)
- UDM_ISPELL_PREFIX_DISABLED (entier)
- UDM_ISPELL_TYPE_AFFIX (entier)
- UDM_ISPELL_TYPE_SPELL (entier)
- UDM_ISPELL_TYPE_DB (entier)
- UDM_ISPELL_TYPE_SERVER (entier)
- UDM_MATCH_WORD (entier)
- UDM_MATCH_BEGIN (entier)
- UDM_MATCH_SUBSTR (entier)
- UDM_MATCH_END (entier)
- Table des matières
- udm_add_search_limit -- Ajoute différentes limitations de recherche
- udm_alloc_agent_array -- Alloue une session mnoGoSearch
- udm_alloc_agent -- Alloue une session mnoGoSearch
- udm_api_version -- Lit la version de l'API mnoGoSearch
- udm_cat_list -- Liste toutes les catégories soeurs d'une catégorie
- udm_cat_path -- Lit le chemin de la catégorie courante
- udm_check_charset -- Vérifie si un jeu de caractères est supporté par mnogosearch
- udm_check_stored -- Vérifie la connexion MnoGoSearch avec le document stocké
- udm_clear_search_limits -- Annule toutes les limitations de recherche MnoGoSearch
- udm_close_stored -- Ferme la connexion MnoGoSearch avec le document enregistré
- udm_crc32 -- Retourne la somme de contrôle CRC32 d'une chaîne
- udm_errno -- Numéro d'erreur mnoGoSearch
- udm_error -- Message d'erreur mnoGoSearch
- udm_find -- Effectue une recherche
- udm_free_agent -- Détruit une session mnoGoSearch
- udm_free_ispell_data -- Libère la mémoire allouée pour ispell par MnoGoSearch
- udm_free_res -- Libère un résultat mnoGoSearch
- udm_get_doc_count -- Lit le nombre total de documents dans les bases MnoGoSearch
- udm_get_res_field -- Lit un champ de résultat mnoGoSearch
- udm_get_res_param -- Lit les paramètres de résultats mnoGoSearch
- udm_hash32 -- Retourne une somme de contrôle Hash32
- udm_load_ispell_data -- Charge les données ispell
- udm_open_stored -- Ouvre une connexion MnoGoSearch avec un document stocké
- udm_set_agent_param -- Modifie les paramètres de l'agent MnoGoSearch
for win32 users, mnogosearch since version 3.2.x
support COM interface
for Reflection API of COM use Visual Studio .NET
-> Tools ..
-> OLE/COM object viewer
- > C:\Program Files\mnoGoSearch\searchcom.dll
simple code
<pre>
<?
define('MNOGOSEARCH_WIN32',
(strtoupper(substr(PHP_OS,0,3))=='WIN') && extension_loaded('COM'));
if (!MNOGOSEARCH_WIN32)
die('MnoGoSearch COM not loaded');
/** Create COM object */
$agent = new COM('MnoGoSearch.GoSearch')
or die('Can\'t create COM object MnoGoSearch.GoSearch');
com_load_typelib('MnoGoSearch.GoSearch');
//mysql://user:passwd@host:port/database/?mode=multi
$agent->DBAddr = $params['DBAddr'];
//buggy, not work
//$agent->DBMode = $params['DBMode'];
$agent->SetCharset($params['Charset']);
$agent->SetCacheMode(true);
$q = 'q='. $query .'&np='. $_REQUEST['page'] .'&ps='. $_REQUEST['pg_size'] .'&m='. $_REQUEST['match'];
$q .= '&wm='. $_REQUEST['word_match'] .'&ul='. $_REQUEST['url_match']. '&wf='. $_REQUEST['where_find'];
$q .= '&typ='. $_REQUEST['content_type'] .'&s='. $_REQUEST['sortby'].'';
//!!! EXECUTE SEARCH QUERY
$result = $agent->Find($q);
if ($agent->ErrorCode>0 || !$result->Valid)
die('MnogoSearch win32 COM Error #'.$agent->ErrorCode.' - '.$agent->ErrorDescription);
$last=$result->LastDoc;
$first=$result->FirstDoc;
$hl_begin = '<span class="mnogosearch_hilight">';
$hl_end= '</span>';
$fetched_result=array();
$i=0;
for($row=$first;$row<=$last;$row++) {
$i=$row-$first;
$line = $result->Line($row);
$fetched_result[$i] = array(
'order'=>$line->Section('Order', $hl_begin, $hl_end),
'url'=> $line->Section('URL', $hl_begin, $hl_end),
'relevance'=>$line->Section('Score', $hl_begin, $hl_end),
'pagerank'=> $line->Section('Pop_Rank', $hl_begin, $hl_end),
'content_type'=> $line->Section('Content-Type', $hl_begin, $hl_end),
'content_length'=> $line->Section('Content-Length', $hl_begin, $hl_end),
'last_time'=> $line->Section('Last-Modified', $hl_begin, $hl_end),
'title'=> $line->Section('title', $hl_begin, $hl_end),
'body'=> $line->Section('body', $hl_begin, $hl_end),
'metadesc'=> $line->Section('meta.description', $hl_begin, $hl_end),
'metakeywords'=> $line->Section('meta.keywords', $hl_begin, $hl_end)
);
}
var_dump($fetched_result);
echo '<br/>search time : '.$result->SearchSeconds;
echo '<br/>words stats :'.$result->WordInfo;
echo '<br/>pg_count: '.$result->NPages;
echo '<br/>total_rows: '. $result->Count;
echo '<br/>first_doc: '.$result->FirstDoc;
echo '<br/>last_doc: '.$result->LastDoc;
echo '<br/>rows_in_page: '.$result->RowsOnPage;
?>
</pre>
I finally got PHP 4.2.1 to compile with mnoGoSearch 3.2.2 ; trick is to build the shared mnoGoSearch and not the static version (opposite from mnoGoSearch defaults), and not to use --disable-rpath in PHP.
There is always a collisions for FTP name between PHP releease 4.2.0-dev and mnogosearch 3.2.3. So, first compile mnogosearch with --disable-ftp.
The name collision between php's builtin FTP functions and mnoGo's have been fixed since version 3.1.14 of mnoGoSearch according to; http://www.mnogosearch.ru/history.html
I have found that if you compile php with "--with-ftp and --with-mnogosearch=/dir" you must compile and build mnogosearch with "--disable-ftp" first. There are some naming conflicts between php's ftp libs and mno's ftp libs.
Hope this helps
