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 関数
導入
ここで示す関数により、フリーの検索エンジン mnoGoSearch (旧名は UdmSearch) へアクセスすることが可能となります。 mnoGoSearch はイントラネットおよびインターネットサーバ用の多機能な 検索エンジンソフトウエアであり、GNU ライセンスのもとで配布されています。 mnoGoSearch は、サイト内の検索から料理レシピまたは新聞検索、 ftp アーカイブ検索、新聞記事検索といった特定の検索システムといった 広い範囲のアプリケーションを構築する等といったユニークないくつかの 機能を有しています。mnoGoSearch により HTML、PDF、テキストドキュメントに 関する全文テキストインデックス作成と検索が可能になります。 mnoGoSearch は二つの部分から構成されます。最初の部分は、 インデックス機構 (indexer) です。indexer は、HTTP, FTP, NEWS サーバ またはローカルファイルにアクセスし、再帰的に全てのドキュメントを取得して、 そのドキュメントに関するメタデータを優れた効率的な手法で SQL データベースに保存します。各ドキュメントがその対応する URL で 参照された後、indexer により収集されたメタデータが後で検索処理において 使用されます。検索は、Web インターフェースにより行われます。 C CGI、PHP、Perl 用の検索フロントエンドが含まれています。
mnoGoSearchに関するより詳細な情報は、http://www.mnogosearch.org/にあります。
注意: この拡張モジュールは PECL レポジトリに移動 されており、以下のバージョン以降 PHP にバンドルされなくなっています。 PHP 5.1.0.
注意: この拡張モジュールは Windows 環境では利用できません。
要件
http://www.mnogosearch.org/ から mnoGosearch を ダウンロードし、使用するシステムにインストールしてください。 以下の関数を使用するには、3.1.10 以降のバージョンの mnoGoSearch が インストールされている必要があります。
インストール手順
これらの関数を利用可能とするためには、オプション --with-mnogosearch により mnoGosearch サポートを指定して PHP をコンパイルする必要があります。 mnoGosearch のパスを指定せずにこのオプションを使用した場合、PHP は デフォルトで mnoGosearch が /usr/local/mnogosearch にあるものとして検索を行います。mnoGosearch を他の場所にインストール している場合には、--with-mnogosearch=DIR のようにそのパスを指定する必要があります。
注意: PHP には MySQL との接続ライブラリが組み込まれており、MySQL に アクセスすることが可能です。mnoGoSearch はこの組み込みライブラリと 互換性がなく、通常の MySQL ライブラリとの組合せでのみ動作します。 このため、mnoGoSearch を MySQL と組み合わせて使用する際には、PHP の configure に MySQL をインストールしたディレクトリを指定する必要が あります。これは mnoGoSearch に関する設定で使用され、例えば 次のようになります。 --with-mnogosearch --with-mysql=/usr
実行時設定
設定ディレクティブは定義されていません。
定義済み定数
以下の定数が定義されています。 この関数の拡張モジュールが PHP 組み込みでコンパイルされているか、 実行時に動的にロードされている場合のみ使用可能です。
- UDM_FIELD_URLID (integer)
- UDM_FIELD_URL (integer)
- UDM_FIELD_CONTENT (integer)
- UDM_FIELD_TITLE (integer)
- UDM_FIELD_KEYWORDS (integer)
- UDM_FIELD_DESC (integer)
- UDM_FIELD_DESCRIPTION (integer)
- UDM_FIELD_TEXT (integer)
- UDM_FIELD_SIZE (integer)
- UDM_FIELD_RATING (integer)
- UDM_FIELD_SCORE (integer)
- UDM_FIELD_MODIFIED (integer)
- UDM_FIELD_ORDER (integer)
- UDM_FIELD_CRC (integer)
- UDM_FIELD_CATEGORY (integer)
- UDM_FIELD_LANG (integer)
- UDM_FIELD_CHARSET (integer)
- UDM_PARAM_PAGE_SIZE (integer)
- UDM_PARAM_PAGE_NUM (integer)
- UDM_PARAM_SEARCH_MODE (integer)
- UDM_PARAM_CACHE_MODE (integer)
- UDM_PARAM_TRACK_MODE (integer)
- UDM_PARAM_PHRASE_MODE (integer)
- UDM_PARAM_CHARSET (integer)
- UDM_PARAM_LOCAL_CHARSET (integer)
- UDM_PARAM_BROWSER_CHARSET (integer)
- UDM_PARAM_STOPTABLE (integer)
- UDM_PARAM_STOP_TABLE (integer)
- UDM_PARAM_STOPFILE (integer)
- UDM_PARAM_STOP_FILE (integer)
- UDM_PARAM_WEIGHT_FACTOR (integer)
- UDM_PARAM_WORD_MATCH (integer)
- UDM_PARAM_MAX_WORD_LEN (integer)
- UDM_PARAM_MAX_WORDLEN (integer)
- UDM_PARAM_MIN_WORD_LEN (integer)
- UDM_PARAM_MIN_WORDLEN (integer)
- UDM_PARAM_ISPELL_PREFIXES (integer)
- UDM_PARAM_ISPELL_PREFIX (integer)
- UDM_PARAM_PREFIXES (integer)
- UDM_PARAM_PREFIX (integer)
- UDM_PARAM_CROSS_WORDS (integer)
- UDM_PARAM_CROSSWORDS (integer)
- UDM_PARAM_VARDIR (integer)
- UDM_PARAM_DATADIR (integer)
- UDM_PARAM_HLBEG (integer)
- UDM_PARAM_HLEND (integer)
- UDM_PARAM_SYNONYM (integer)
- UDM_PARAM_SEARCHD (integer)
- UDM_PARAM_QSTRING (integer)
- UDM_PARAM_REMOTE_ADDR (integer)
- UDM_LIMIT_CAT (integer)
- UDM_LIMIT_URL (integer)
- UDM_LIMIT_TAG (integer)
- UDM_LIMIT_LANG (integer)
- UDM_LIMIT_DATE (integer)
- UDM_PARAM_FOUND (integer)
- UDM_PARAM_NUM_ROWS (integer)
- UDM_PARAM_WORDINFO (integer)
- UDM_PARAM_WORD_INFO (integer)
- UDM_PARAM_SEARCHTIME (integer)
- UDM_PARAM_SEARCH_TIME (integer)
- UDM_PARAM_FIRST_DOC (integer)
- UDM_PARAM_LAST_DOC (integer)
- UDM_MODE_ALL (integer)
- UDM_MODE_ANY (integer)
- UDM_MODE_BOOL (integer)
- UDM_MODE_PHRASE (integer)
- UDM_CACHE_ENABLED (integer)
- UDM_CACHE_DISABLED (integer)
- UDM_TRACK_ENABLED (integer)
- UDM_TRACK_DISABLED (integer)
- UDM_PHRASE_ENABLED (integer)
- UDM_PHRASE_DISABLED (integer)
- UDM_CROSS_WORDS_ENABLED (integer)
- UDM_CROSSWORDS_ENABLED (integer)
- UDM_CROSS_WORDS_DISABLED (integer)
- UDM_CROSSWORDS_DISABLED (integer)
- UDM_PREFIXES_ENABLED (integer)
- UDM_PREFIX_ENABLED (integer)
- UDM_ISPELL_PREFIXES_ENABLED (integer)
- UDM_ISPELL_PREFIX_ENABLED (integer)
- UDM_PREFIXES_DISABLED (integer)
- UDM_PREFIX_DISABLED (integer)
- UDM_ISPELL_PREFIXES_DISABLED (integer)
- UDM_ISPELL_PREFIX_DISABLED (integer)
- UDM_ISPELL_TYPE_AFFIX (integer)
- UDM_ISPELL_TYPE_SPELL (integer)
- UDM_ISPELL_TYPE_DB (integer)
- UDM_ISPELL_TYPE_SERVER (integer)
- UDM_MATCH_WORD (integer)
- UDM_MATCH_BEGIN (integer)
- UDM_MATCH_SUBSTR (integer)
- UDM_MATCH_END (integer)
- 目次
- udm_add_search_limit -- 種々の検索の制約を設定する
- udm_alloc_agent_array -- mnoGoSearch セッションを割り当てる
- udm_alloc_agent -- mnoGoSearch セッションを確保する
- udm_api_version -- mnoGoSearch API バージョンを取得する
- udm_cat_list -- カレントのカテゴリと同じレベルのカテゴリを全て取得する
- udm_cat_path -- カレントのカテゴリへのパスを取得する
- udm_check_charset -- 指定した charset が mnogosearch で認識されるかどうか調べる
- udm_check_stored -- 保存された接続を調べる
- udm_clear_search_limits -- mnoGoSearch 検索に関する全ての制約をクリアする
- udm_close_stored -- 保存した接続を閉じる
- udm_crc32 -- 指定した文字列の CRC32 チェックサムを計算する
- udm_errno -- mnoGoSearch エラー番号を取得する
- udm_error -- mnoGoSearch エラーメッセージを得る
- udm_find -- 検索を実行する
- udm_free_agent -- mnoGoSearch セッションを開放する
- udm_free_ispell_data -- ispell データ用に確保されたメモリを解放する
- udm_free_res -- mnoGoSearch 結果を開放する
- udm_get_doc_count -- データベース内のドキュメントの総数を得る
- udm_get_res_field -- mnoGoSearch 結果フィールドを取得する
- udm_get_res_param -- mnoGoSearch 結果パラメータを取得する
- udm_hash32 -- 指定した文字列の Hash32 チェックサムを返す
- udm_load_ispell_data -- ispell データを読み込む
- udm_open_stored -- 保存した接続をオープンする
- udm_set_agent_param -- 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
