From 219888d4899fa1704452ed7169b718f6766aaa07 Mon Sep 17 00:00:00 2001 From: mensonge Date: Fri, 14 Mar 2008 10:32:00 +0000 Subject: [PATCH] New Feature: save searches (and display a searchhistory box) git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@80 b3834d28-1941-0410-a4f8-b48e95affb8f --- config.inc.php.example | 6 ++ index.php | 2 +- locales/fr_FR/LC_MESSAGES/messages.mo | Bin 18568 -> 18840 bytes locales/fr_FR/LC_MESSAGES/messages.po | 57 ++++++++------ locales/messages.po | 50 +++++++----- search.php | 6 +- services/searchhistoryservice.php | 108 ++++++++++++++++++++++++++ tables.sql | 16 ++++ templates/sidebar.block.search.php | 35 +++++++++ tests/LAUNCH_TESTS | 2 +- tests/searchTest.php | 80 +++++++++++++++++++ 11 files changed, 313 insertions(+), 49 deletions(-) create mode 100644 services/searchhistoryservice.php create mode 100644 templates/sidebar.block.search.php create mode 100644 tests/searchTest.php diff --git a/config.inc.php.example b/config.inc.php.example index 55b1c24..1059bba 100644 --- a/config.inc.php.example +++ b/config.inc.php.example @@ -95,6 +95,10 @@ $dbname = 'scuttle'; # # enableWebsiteThumbnails : true or false. According to artviper.net license, buy a license if you gain profit with your pages. (see http://www.websitethumbnail.de/) # +# sizeSearchHistory : the number of users' searches that are saved +# 10 [Default] +# -1 Unlimited +# ###################################################################### $sitename = 'SemanticScuttle'; @@ -137,6 +141,8 @@ $enableCommonBookmarkDescription = true; $enableWebsiteThumbnails = true; // see above, if you gain profit with your pages +$sizeSearchHistory = 10; + include_once('debug.inc.php'); ?> diff --git a/index.php b/index.php index f70f72b..e3125aa 100644 --- a/index.php +++ b/index.php @@ -67,7 +67,7 @@ $dtend = date('Y-m-d H:i:s', strtotime('tomorrow')); $tplVars['page'] = $page; $tplVars['start'] = $start; $tplVars['popCount'] = 30; -$tplVars['sidebar_blocks'] = array('users', 'linked', 'recent'); +$tplVars['sidebar_blocks'] = array('search', 'users', 'linked', 'recent'); $tplVars['range'] = 'all'; $tplVars['pagetitle'] = T_('Store, share and tag your favourite links'); $tplVars['subtitle'] = T_('Recent Bookmarks'); diff --git a/locales/fr_FR/LC_MESSAGES/messages.mo b/locales/fr_FR/LC_MESSAGES/messages.mo index 820aea18e59e15ae389c4a9b2267e9c7f9d0c2c3..e6ab4aeaf9f9bcef6a7e863b3c70b346216e9079 100644 GIT binary patch delta 4859 zcmYk;3w+Jz9mnw}k%(jDiXh0pDbh&PW$vQl61BQjYpfU|Igya$BqzyM+w5Ry+M3G_ z8QP+08_}XTimpY~bgMf>SuJ+a)?U`NbRFC1_W9=jq}%`HoA>klbI$XB{=et>|D$Sk z*t%d?pgulgt>L&#I*@Bkjp-6*%(j*~YfM(WF=h0JVH^6P1Y=s^F&u+eu>{jOIR!W1 z9K3~*IJLDgF*plbV5xNhMjI0_&)5^|F_sV1VifK}{+UDkXoeT8_1KR7r>M_|F{=!W z#~wHo-&d}(>iL3Z6j7)UD5Qk~>laQjAY-Gk}ELPw& z%*Qi09{aa-?{pbzV$~RdTabTd8$UG8QB*}vU@X@+S7>P9&ycE_yVxA#xJ?bv0rkcE zP+xoi`G^^S`rJg+#HZWe7uf!js2f{?i}6*|INjU3OWg+p4{~B64P9sy#II5JN+TY(qO(>pU_QDk88fKEU#9D=#aE`DK867^4~5y{Te1bU%1O+VBc zWum?~0d=PZs0o&%Dzyl;*43zq)S>pyepE%@LG7K>xEC*>DzLI6)x_$K)L)xozddmU zRm!hXyR~^IcT*+eSo#m6Cb|YSk@cvFZ9z?VxBdN5)Hugb7rcm?*za))evBG_NFbT= z(|81R;(647TTvI-q0NLtj{qx?m8sd0xhcFoYWD7CwQV&hCJ@m`1+{8%l~StJ#d2@FCQA z$E{cF`Oh$d^Z&#lT;F_6;{nWMLG?I#QJZ89j>f;@Kf& zMmD!kQ)?+wcM{S-Ps0;lAHL>V!?oz~~ zE}Vv1%g3xUQKc=yC@e!=cs^<(D{*U>F$Zx4{eleYuTtI4a9=2`x*Ic-ej1kJ(>N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@@ msgid "" msgstr "" "Project-Id-Version: Scuttle\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2008-03-12 18:05+0100\n" -"PO-Revision-Date: 2008-03-12 18:09+0100\n" +"POT-Creation-Date: 2008-03-14 11:27+0100\n" +"PO-Revision-Date: 2008-03-14 11:29+0100\n" "Last-Translator: BenjaminHKB \n" "Language-Team: fr-FR \n" "MIME-Version: 1.0\n" @@ -27,7 +27,7 @@ msgstr "À propos" #: ../../../ajaxDelete.php:30 msgid "You are not allowed to delete this bookmark" -msgstr "Vous ne pouvez pas supprimer ce signet." +msgstr "Vous n'êtes pas autorisés à supprimer ce signet" #: ../../../ajaxDelete.php:34 #: ../../../edit.php:78 @@ -43,7 +43,7 @@ msgstr "Tous les tags" #: ../../../populartags.php:58 #: ../../../profile.php:44 #: ../../../rss.php:62 -#: ../../../search.php:87 +#: ../../../search.php:88 #: ../../../watch.php:34 #: ../../../watchlist.php:61 #, php-format @@ -419,12 +419,12 @@ msgstr "tous les signets" msgid "for" msgstr "pour" -#: ../../../search.php:58 -#: ../../../search.php:104 +#: ../../../search.php:59 +#: ../../../search.php:108 msgid "Search Bookmarks" msgstr "Recherche de signets" -#: ../../../search.php:64 +#: ../../../search.php:65 msgid "Search Results" msgstr "Résultats de recherche" @@ -463,9 +463,8 @@ msgid "Tag common description updated" msgstr "Editer la description commune du tag" #: ../../../tagcommondescriptionedit.php:48 -#, fuzzy msgid "Failed to update the tag common description" -msgstr "Impossible d'effacer le tag" +msgstr "Impossible de mettre à jour la description commune du tag" #: ../../../tagcommondescriptionedit.php:55 #: ../../../templates/sidebar.block.tagactions.php:25 @@ -652,32 +651,32 @@ msgstr " et les autres %s" msgid "Copy" msgstr "Copier" -#: ../../../templates/bookmarks.tpl.php:201 -#: ../../../templates/bookmarks.tpl.php:207 +#: ../../../templates/bookmarks.tpl.php:202 +#: ../../../templates/bookmarks.tpl.php:208 msgid "First" msgstr "Première" -#: ../../../templates/bookmarks.tpl.php:202 -#: ../../../templates/bookmarks.tpl.php:208 +#: ../../../templates/bookmarks.tpl.php:203 +#: ../../../templates/bookmarks.tpl.php:209 msgid "Previous" msgstr "Précédent" -#: ../../../templates/bookmarks.tpl.php:215 -#: ../../../templates/bookmarks.tpl.php:218 +#: ../../../templates/bookmarks.tpl.php:216 +#: ../../../templates/bookmarks.tpl.php:219 msgid "Next" msgstr "Suivant" -#: ../../../templates/bookmarks.tpl.php:216 -#: ../../../templates/bookmarks.tpl.php:219 +#: ../../../templates/bookmarks.tpl.php:217 +#: ../../../templates/bookmarks.tpl.php:220 msgid "Last" msgstr "Dernière" -#: ../../../templates/bookmarks.tpl.php:221 +#: ../../../templates/bookmarks.tpl.php:222 #, php-format msgid "Page %d of %d" msgstr "Page %d de %d" -#: ../../../templates/bookmarks.tpl.php:225 +#: ../../../templates/bookmarks.tpl.php:226 msgid "No bookmarks available" msgstr "Pas de signets disponibles." @@ -942,27 +941,27 @@ msgstr "Enregistrez-vous ici pour créer un compte gratuit %s. Toutes les inform msgid "Antispam question" msgstr "Question antispam" -#: ../../../templates/sidebar.block.linked.php:16 +#: ../../../templates/sidebar.block.linked.php:17 msgid "Edit link" msgstr "Editer un lien" -#: ../../../templates/sidebar.block.linked.php:40 +#: ../../../templates/sidebar.block.linked.php:44 msgid "Synonyms:" msgstr "Synonymes :" -#: ../../../templates/sidebar.block.linked.php:101 +#: ../../../templates/sidebar.block.linked.php:105 msgid "Linked Tags" msgstr "Tags structurés" -#: ../../../templates/sidebar.block.linked.php:104 +#: ../../../templates/sidebar.block.linked.php:108 msgid "plus" msgstr "plus" -#: ../../../templates/sidebar.block.linked.php:122 +#: ../../../templates/sidebar.block.linked.php:126 msgid "Add new link" msgstr "Créer un lien" -#: ../../../templates/sidebar.block.linked.php:123 +#: ../../../templates/sidebar.block.linked.php:127 msgid "Delete link" msgstr "Supprimer un lien" @@ -974,6 +973,14 @@ msgstr "Tags récents" msgid "Related Tags" msgstr "Tags en relation" +#: ../../../templates/sidebar.block.search.php:16 +msgid "Last Searches" +msgstr "Dernières recherches" + +#: ../../../templates/sidebar.block.search.php:25 +msgid "Number of bookmarks for this query" +msgstr "Nombre de signets pour cette recherche" + #: ../../../templates/sidebar.block.tagactions.php:17 #: ../../../templates/sidebar.block.watchstatus.php:17 #, fuzzy diff --git a/locales/messages.po b/locales/messages.po index e7be482..4a1c074 100644 --- a/locales/messages.po +++ b/locales/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2008-03-12 18:05+0100\n" +"POT-Creation-Date: 2008-03-14 11:27+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -36,7 +36,7 @@ msgstr "" #: ../../../alltags.php:57 ../../../bookmarks.php:72 #: ../../../populartags.php:58 ../../../profile.php:44 ../../../rss.php:62 -#: ../../../search.php:87 ../../../watch.php:34 ../../../watchlist.php:61 +#: ../../../search.php:88 ../../../watch.php:34 ../../../watchlist.php:61 #, php-format msgid "User with username %s was not found" msgstr "" @@ -397,11 +397,11 @@ msgstr "" msgid "for" msgstr "" -#: ../../../search.php:58 ../../../search.php:104 +#: ../../../search.php:59 ../../../search.php:108 msgid "Search Bookmarks" msgstr "" -#: ../../../search.php:64 +#: ../../../search.php:65 msgid "Search Results" msgstr "" @@ -633,32 +633,32 @@ msgstr "" msgid "Copy" msgstr "" -#: ../../../templates/bookmarks.tpl.php:201 -#: ../../../templates/bookmarks.tpl.php:207 +#: ../../../templates/bookmarks.tpl.php:202 +#: ../../../templates/bookmarks.tpl.php:208 msgid "First" msgstr "" -#: ../../../templates/bookmarks.tpl.php:202 -#: ../../../templates/bookmarks.tpl.php:208 +#: ../../../templates/bookmarks.tpl.php:203 +#: ../../../templates/bookmarks.tpl.php:209 msgid "Previous" msgstr "" -#: ../../../templates/bookmarks.tpl.php:215 -#: ../../../templates/bookmarks.tpl.php:218 -msgid "Next" -msgstr "" - #: ../../../templates/bookmarks.tpl.php:216 #: ../../../templates/bookmarks.tpl.php:219 +msgid "Next" +msgstr "" + +#: ../../../templates/bookmarks.tpl.php:217 +#: ../../../templates/bookmarks.tpl.php:220 msgid "Last" msgstr "" -#: ../../../templates/bookmarks.tpl.php:221 +#: ../../../templates/bookmarks.tpl.php:222 #, php-format msgid "Page %d of %d" msgstr "" -#: ../../../templates/bookmarks.tpl.php:225 +#: ../../../templates/bookmarks.tpl.php:226 msgid "No bookmarks available" msgstr "" @@ -938,27 +938,27 @@ msgstr "" msgid "Antispam question" msgstr "" -#: ../../../templates/sidebar.block.linked.php:16 +#: ../../../templates/sidebar.block.linked.php:17 msgid "Edit link" msgstr "" -#: ../../../templates/sidebar.block.linked.php:40 +#: ../../../templates/sidebar.block.linked.php:44 msgid "Synonyms:" msgstr "" -#: ../../../templates/sidebar.block.linked.php:101 +#: ../../../templates/sidebar.block.linked.php:105 msgid "Linked Tags" msgstr "" -#: ../../../templates/sidebar.block.linked.php:104 +#: ../../../templates/sidebar.block.linked.php:108 msgid "plus" msgstr "" -#: ../../../templates/sidebar.block.linked.php:122 +#: ../../../templates/sidebar.block.linked.php:126 msgid "Add new link" msgstr "" -#: ../../../templates/sidebar.block.linked.php:123 +#: ../../../templates/sidebar.block.linked.php:127 msgid "Delete link" msgstr "" @@ -970,6 +970,14 @@ msgstr "" msgid "Related Tags" msgstr "" +#: ../../../templates/sidebar.block.search.php:16 +msgid "Last Searches" +msgstr "" + +#: ../../../templates/sidebar.block.search.php:25 +msgid "Number of bookmarks for this query" +msgstr "" + #: ../../../templates/sidebar.block.tagactions.php:17 #: ../../../templates/sidebar.block.watchstatus.php:17 msgid "Actions" diff --git a/search.php b/search.php index 2c88f91..6e002bb 100644 --- a/search.php +++ b/search.php @@ -31,6 +31,7 @@ if (isset($_POST['terms'])) { $bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService'); $templateservice =& ServiceFactory::getServiceInstance('TemplateService'); $userservice =& ServiceFactory::getServiceInstance('UserService'); + $searchhistoryservice =& ServiceFactory::getServiceInstance('SearchHistoryService'); $logged_on_userid = $userservice->getCurrentUserId(); list($url, $range, $terms, $page) = explode('/', $_SERVER['PATH_INFO']); @@ -94,11 +95,14 @@ if (isset($_POST['terms'])) { } } $bookmarks =& $bookmarkservice->getBookmarks($start, $perpage, $s_user, NULL, $terms, getSortOrder(), $s_watchlist, $s_start, $s_end); + + // Save search + $searchhistoryservice->addSearch($terms, $range, $bookmarks['total'], $logged_on_userid); $tplVars['page'] = $page; $tplVars['start'] = $start; $tplVars['popCount'] = 25; - $tplVars['sidebar_blocks'] = array('recent'); + $tplVars['sidebar_blocks'] = array('search', 'recent'); $tplVars['range'] = $range; $tplVars['terms'] = $terms; $tplVars['pagetitle'] = T_('Search Bookmarks'); diff --git a/services/searchhistoryservice.php b/services/searchhistoryservice.php new file mode 100644 index 0000000..7389906 --- /dev/null +++ b/services/searchhistoryservice.php @@ -0,0 +1,108 @@ +db =& $db; + $this->tablename = $GLOBALS['tableprefix'] .'searchhistory'; + if(isset($GLOBALS['sizeSearchHistory'])) { + $this->sizeSearchHistory = $GLOBALS['sizeSearchHistory']; + } else { + $this->sizeSearchHistory = 10; + } + } + + function addSearch($terms, $range, $nbResults, $uId=0) { + if(strlen($terms) == 0) { + return false; + } + $datetime = gmdate('Y-m-d H:i:s', time()); + + //Insert values + $values = array('shTerms'=>$terms, 'shRange'=>$range, 'shDatetime'=>$datetime, 'shNbResults'=>$nbResults, 'uId'=>$uId); + $sql = 'INSERT INTO '. $this->getTableName() .' '. $this->db->sql_build_array('INSERT', $values); + $this->db->sql_transaction('begin'); + if (!($dbresult = & $this->db->sql_query($sql))) { + $this->db->sql_transaction('rollback'); + message_die(GENERAL_ERROR, 'Could not insert search history', '', __LINE__, __FILE__, $sql, $this->db); + return false; + } + + if($this->sizeSearchHistory != -1 && + $this->countSearches() > $this->sizeSearchHistory) { + $this->deleteOldestSearch(); + } + } + + function getAllSearches($range = NULL, $uId = NULL, $nb = NULL, $start = NULL, $distinct = false) { + $sql = 'SELECT DISTINCT(shTerms), shId, shRange, shNbResults, shDatetime, uId'; + $sql.= ' FROM '. $this->getTableName(); + $sql.= ' WHERE 1=1'; + if($range != NULL) { + $sql.= ' AND shRange = "'.$range.'"'; + } else { + $sql.= ' AND shRange = "all"'; + } + if($uId != NULL) { + $sql.= ' AND uId = '.$uId; + } + if($distinct) { + $sql.= ' GROUP BY shTerms'; + } + $sql.= ' ORDER BY shId DESC'; + + if (!($dbresult = & $this->db->sql_query_limit($sql, $nb, $start))) { + message_die(GENERAL_ERROR, 'Could not get searches', '', __LINE__, __FILE__, $sql, $this->db); + return false; + } + + $searches = array(); + while ($row = & $this->db->sql_fetchrow($dbresult)) { + $searches[] = $row; + } + return $searches; + } + + function countSearches() { + $sql = 'SELECT COUNT(*) AS `total` FROM '. $this->getTableName(); + if (!($result = & $this->db->sql_query($sql)) || (!($row = & $this->db->sql_fetchrow($result)))) { + message_die(GENERAL_ERROR, 'Could not get total searches', '', __LINE__, __FILE__, $sql, $this->db); + return false; + } + + return $row['total']; + } + + /* This function allows to limit the number of saved searches + by deleting the oldest one */ + function deleteOldestSearch() { + $sql = 'DELETE FROM '.$this->getTableName(); + $sql.= ' ORDER BY shId ASC LIMIT 1'; // warning: here the limit is important + + $this->db->sql_transaction('begin'); + if (!($dbresult = & $this->db->sql_query($sql))) { + $this->db->sql_transaction('rollback'); + message_die(GENERAL_ERROR, 'Could not delete bookmarks', '', __LINE__, __FILE__, $query, $this->db); + return false; + } + } + + function deleteAll() { + $query = 'TRUNCATE TABLE `'. $this->getTableName() .'`'; + $this->db->sql_query($query); + } + + // Properties + function getTableName() { return $this->tablename; } + function setTableName($value) { $this->tablename = $value; } +} +?> diff --git a/tables.sql b/tables.sql index 64a7ec9..92c42c7 100644 --- a/tables.sql +++ b/tables.sql @@ -121,3 +121,19 @@ CREATE TABLE `sc_commondescription` ( UNIQUE KEY `sc_commondescription_tag_datetime` (`tag`,`cdDatetime`), UNIQUE KEY `sc_commondescription_bookmark_datetime` (`bHash`,`cdDatetime`) ); + +-- -------------------------------------------------------- + +-- +-- Table structure for table `sc_searchhistory` +-- + +CREATE TABLE `sc_searchhistory` ( + `shId` int(11) NOT NULL auto_increment, + `shTerms` varchar(255) NOT NULL default '', + `shRange` varchar(32) NOT NULL default '', + `shDatetime` datetime NOT NULL default '0000-00-00 00:00:00', + `shNbResults` int(6) NOT NULL default '0', + `uId` int(11) NOT NULL default '0', + PRIMARY KEY (`shId`) +); diff --git a/templates/sidebar.block.search.php b/templates/sidebar.block.search.php new file mode 100644 index 0000000..e9638d2 --- /dev/null +++ b/templates/sidebar.block.search.php @@ -0,0 +1,35 @@ +getCurrentUserId(); +if ($logged_on_userid === false) { + $logged_on_userid = NULL; +} + +$lastSearches = $searchhistoryservice->getAllSearches('all', NULL, 3, NULL, true); + +if ($lastSearches && count($lastSearches) > 0) { +?> + +

+
+ +'; +} +//echo ''; +?> + +
'; + echo ''; + echo $row['shTerms']; + echo ''; + echo ' ('.$row['shNbResults'].')'; + echo '
...
+
+ diff --git a/tests/LAUNCH_TESTS b/tests/LAUNCH_TESTS index dc8bdf4..52d4ba5 100644 --- a/tests/LAUNCH_TESTS +++ b/tests/LAUNCH_TESTS @@ -4,4 +4,4 @@ Then To launch the tests, put in a console situated in the root of the SEMANTICSCUTTLE project (where is the SEMANTICSCUTTLE config file): -phpunit BookmarksTest ./tests/bookmarksTest.php ; phpunit CommonDescriptionTest tests/commonDescriptionTest.php ; phpunit Tag2TagTest tests/tag2TagTest.php +phpunit BookmarksTest ./tests/bookmarksTest.php ; phpunit CommonDescriptionTest tests/commonDescriptionTest.php ; phpunit Tag2TagTest tests/tag2TagTest.php ; phpunit SearchTest tests/searchTest.php diff --git a/tests/searchTest.php b/tests/searchTest.php new file mode 100644 index 0000000..ecdc6ad --- /dev/null +++ b/tests/searchTest.php @@ -0,0 +1,80 @@ +us =& ServiceFactory::getServiceInstance('UserService'); + $this->bs =& ServiceFactory::getServiceInstance('BookmarkService'); + $this->bs->deleteAll(); + $this->ts =& ServiceFactory::getServiceInstance('TagService'); + $this->ts->deleteAll(); + $this->tts =& ServiceFactory::getServiceInstance('Tag2TagService'); + $this->tts->deleteAll(); + $this->tsts =& ServiceFactory::getServiceInstance('TagStatService'); + $this->tsts->deleteAll(); + $this->shs =& ServiceFactory::getServiceInstance('SearchHistoryService'); + $this->shs->deleteAll(); + } + + public function testSearchHistory() + { + $shs = $this->shs; + + $terms = 'bbqsdkbb;,:,:q;,qddds&é"\'\\\\\(-è_çà)'; + $terms2 = '~#{|`]'; + $range = 'all'; + $nbResults = 10908; + $uId = 10; + + $shs->addSearch($terms, $range, $nbResults, $uId); + $shs->addSearch($terms2, $range, $nbResults, $uId); + $shs->addSearch('', $range, $nbResults, $uId); // A void search must not be saved + + $searches = $shs->getAllSearches(); + $this->assertSame(2, count($searches)); + $searches = $shs->getAllSearches($range, $uId); + $this->assertEquals(2, count($searches)); + $searches = $shs->getAllSearches($range, 20); // fake userid + $this->assertEquals(0, count($searches)); + $searches = $shs->getAllSearches($range, $uId, 1); + $this->assertEquals(1, count($searches)); + $searches = $shs->getAllSearches($range, null, 1, 1); + $this->assertEquals(1, count($searches)); + + //test content of results + $searches = $shs->getAllSearches(); + $this->assertSame($terms2, $searches[0]['shTerms']); + $this->assertSame($range, $searches[0]['shRange']); + $this->assertEquals($nbResults, $searches[0]['shNbResults']); + $this->assertEquals($uId, $searches[0]['uId']); + $this->assertSame($terms, $searches[1]['shTerms']); + $this->assertSame($range, $searches[1]['shRange']); + $this->assertEquals($nbResults, $searches[1]['shNbResults']); + $this->assertEquals($uId, $searches[1]['uId']); + + //test distinct parameter + $shs->addSearch($terms, $range, $nbResults, 30); // we repeat a search (same terms) + $searches = $shs->getAllSearches(); + $this->assertSame(3, count($searches)); + $searches = $shs->getAllSearches(NULL, NULL, NULL, NULL, true); + $this->assertSame(2, count($searches)); + } +} +?>