©
이 문서에서는 PHP 중국어 웹사이트 매뉴얼 풀어 주다
(PHP 4 >= 4.0.5, PHP 5 <= 5.0.5, PECL mnogosearch >= 1.0.0)
udm_find — Perform search
$agent
, string $query
)Performs a search.
The search itself. The first argument - session, the next one - query itself. To find something just type words you want to find and press SUBMIT button. For example, "mysql odbc". You should not use quotes " in query, they are written here only to divide a query from other text. mnoGoSearch will find all documents that contain word "mysql" and/or word "odbc". Best documents having bigger weights will be displayed first. If you use search mode ALL, search will return documents that contain both (or more) words you entered. In case you use mode ANY, the search will return list of documents that contain any of the words you entered. If you want more advanced results you may use query language. You should select "bool" match mode in the search from.
agent
A link to Agent, received after call to udm_alloc_agent() .
query
mnoGoSearch understands the following boolean operators:
& - logical AND. For example, "mysql & odbc". mnoGoSearch will find any URLs that contain both "mysql" and "odbc".
| - logical OR. For example "mysql|odbc". mnoGoSearch will find any URLs, that contain word "mysql" or word "odbc".
~ - logical NOT. For example "mysql & ~odbc". mnoGoSearch will find URLs that contain word "mysql" and do not contain word "odbc" at the same time. Note that ~ just excludes given word from results. Query "~odbc" will find nothing!
() - group command to compose more complex queries. For example "(mysql | msql) & ~postgres". Query language is simple and powerful at the same time. Just consider query as usual boolean expression.
Returns a result link identifier on success 或者在失败时返回 FALSE
.
[#1] sm_dev_mnogo at u5 dot com [2003-11-20 03:02:10]
For me (PHP 4.3.3, Mnogo 3.2.15 on FreeBSD) Mnogo doesn't work as described - but very well if done as in the PHP-template distributed by MnogoSearch
I had huge problems getting Udm_Find(... to return anything at all.
All the other calls worked, like udm_get_doc_count(... but _find seemed to insist on returning nothing, no matter what I tried.
However, I had actually a working installation of mnogo, using the PHP template, so it was just to find the difference in the, BTW impressive, work by Sergey 'gluke' Kartashoff.
The result was surprising, see below. The parameter UDM_PARAM_QUERY is not mentioned in the manual
<?php
$q="help";
// This is the real query. Note that Udm_find seems to
// ignore it, despite the
// description in the manual
$udm_agent
=Udm_Alloc_Agent('pgsql://me:secret@/mnogo_db/?dbmode=multi');
// This is actually also contrary to the manual, but it
// works. Also in the PHP-template it said
// which contradicts the manual for never versions
$iDoItAsInTheManual = true; //Set to false and it works
if ($iDoItAsInTheManual)
{
$res=Udm_Find($udm_agent, $q);
}
else
// This works:
{
Udm_Set_Agent_Param($udm_agent,UDM_PARAM_QUERY,$q);
$res=Udm_Find($udm_agent,"anything here, makes no difference!!");
}
$url = udm_get_res_field(
$res, //resource res,
0, // int row,
UDM_FIELD_URL // int field
);
echo $url;
// Fails if $iDoItAsInTheManual==true, otherwise it works fine
?>
I don't know where something has gone wrong but I hope this may help someone save a little time.
[#2] matt at nowhere dot dot [2002-12-23 10:50:29]
Here is a small snipet of code that will perform a search on mnogosearch and (in not so pretty a way) display the results. Note that it appears that UDM_PARAM_FIRST_DOC starts at 1, but perhaps should be 0.
<?php
$searchText = trim($_GET['search']);
$mnogo = udm_alloc_agent ('mysql://me:secret@localhost/mnogosearch/');
$mResult = udm_find($mnogo,$searchText);
$totalMatches = udm_get_res_param ($mResult,UDM_PARAM_FOUND);
$pageSize = udm_get_res_param ($mResult,UDM_PARAM_NUM_ROWS);
$firstRow = udm_get_res_param ($mResult,UDM_PARAM_FIRST_DOC);
$lastRow = udm_get_res_param ($mResult,UDM_PARAM_LAST_DOC);
echo "Your search for <b>$searchText</b> resulted in <b>$totalMatches</b> matches";
echo "The result set (pagesize) is <b>$pageSize</b>\n";
echo "The first doc is row <b>$firstRow</b> and the last doc is <b>$lastRow</b>\n";
$row=0;
for ($i=$firstRow-1;$i<$lastRow;$i++) {
$row++;
echo "Match $row:";
echo 'Url: ';
$url = udm_get_res_field ($mResult,$i,UDM_FIELD_URL);
echo "<a href=\"$url\">$url</a>";
echo "\nTitle: <b>";
echo udm_get_res_field ($mResult, $i,UDM_FIELD_TITLE);
echo "</b>\nMeta Desc:";
echo udm_get_res_field ($mResult, $i,UDM_FIELD_DESC);
echo "\nPage Text: <b>\n";
echo udm_get_res_field ($mResult, $i,UDM_FIELD_TEXT);
echo "</b>\n<hr>\n";
}
udm_free_res($mResult);
udm_free_agent($mnogo);
?>