|
udm_find
Perform search
(PHP 4 >= 4.0.5, PHP 5 <= 5.0.5, PECL mnogosearch:1.0.0)
Code Examples / Notes » udm_findmatt
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); ?> sm_dev_mnogo
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 /* if (Udm_Api_Version() >= 30204) { $dbaddr='mysql://mnogo:mnogo@/mnogo/?dbmode=single'; } else { $dbaddr='mysql://mnogo:mnogo@/mnogo/'; $dbmode='single'; } */ // 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. |
Change Languageudm_add_search_limit udm_alloc_agent_array udm_alloc_agent udm_api_version udm_cat_list udm_cat_path udm_check_charset udm_check_stored udm_clear_search_limits udm_close_stored udm_crc32 udm_errno udm_error udm_find udm_free_agent udm_free_ispell_data udm_free_res udm_get_doc_count udm_get_res_field udm_get_res_param udm_hash32 udm_load_ispell_data udm_open_stored udm_set_agent_param |