1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
|
<?php
mysql_connect( "localhost", "root", "" ) ; //connexion à la bdd
mysql_select_db("INFOS") ;
if (isset($_POST['rechercher'])) //si on a validé le formulaire
{
$recherche = mysql_real_escape_string(htmlspecialchars($_POST['recherche'])); //sécurisation des variables
$recherche=strtolower($recherche);
$mode = mysql_real_escape_string(htmlspecialchars($_POST['mode']));
if (isset($_POST['offre'])) $offre=$_POST['offre'];//si on a coché la case
if ($mode == "tous_les_mots")
{
$and_ou_or = 'AND'; //on utilisera AND dans la boucle
}
else
{
$and_ou_or = 'OR'; //on utilisera OR dans la boucle
}
if ($mode == "expression_exacte") //si le mode de recherche est par expression exacte
{
//$selection_recherche = mysql_query("SELECT * FROM document,terme WHERE document.code_doc=terme.code_doc AND document.type_offre='$offre' AND terme LIKE '%$recherche%' group by url ORDER BY poids DESC ");
}
else //si le mode de recherche n'est pas par expression exacte
{
$aTab = preg_split('`[\s| : \ , \ ; \ . \ « \ » \%\&\0\1\2\3\4\5\6\7\7\8\9\=\*\@\<\>\;\-\ " \ \ \ / \ { \ } \ - \ # \ < \ > \ _ ( \
) \ + \ -\[\]\=\?\!\^\`\¿\_\{\}\|\~\€\‚\ƒ\„\…\†\‡\ˆ\‰\Š\‹\Œ\Ž\‘\’\“\”\•\–\— \˜\™\š\›\œ\ž\¨\µ\¬\$\©\@\§\ \ ]+`', $recherche);//caractéres spécieux keyword
$champs1=implode(" ",$aTab); //keyword
$motsExclus = array('a','afin','ai','ainsi','ais');
if( preg_match_all('`\w{2,}`', $champs1, $result) )
{
// Remplacement des mots exclus par rien
$result[0] = preg_replace('`\b(' . implode($motsExclus, '|') . ')\b`i', '', $result[0]);
// Suppression des éléments vides avec array_filter()
$result[0] = array_filter($result[0]);
}
$champs11=implode(" ", $result[0]);
$mots = explode(" ", $champs11); //séparation des mots reprtésentation sous forme d'un tableau
$nombre_mots = count ($mots); //compte le nombre de mots
$valeur_requete = '';
for($nombre_mots_boucle = 0; $nombre_mots_boucle < $nombre_mots; $nombre_mots_boucle++) //tant que le nombre de mots de la recherche est supérieur à celui de la boucle, on continue en augmentant le nombre de mots de 1 à chaque fois
{
$valeur_requete .= '' . $and_ou_or . ' terme LIKE \'%' . $mots[$nombre_mots_boucle] . '%\' OR terme_titre LIKE \'%' . $mots[$nombre_mots_boucle] . '%\''; //modification de la variable $valeur_requete
}
$valeur_requete = ltrim($valeur_requete,$and_ou_or); //suppression de AND ou de OR au début de la boucle
$selection="SELECT *
FROM document,terme,titre
WHERE (document.code_doc=terme.code_doc and document.code_doc=titre.code_doc) AND document.type_offre='$offre' AND ($valeur_requete) group by url ";
$selection_recherche = mysql_query($selection); //requête avec le résultat de la boucle dedans
$page = 1;
// Nombre de pages
if(isset($_POST['page']))
{
$page = $_POST['page'];
}
// Nombre de résultats par page
$nb = 5;
if(isset($_POST['nb']) && is_numeric($_POST['nb']))
{
$nb = $_POST['nb'];
}
// Nombre total d'enregistrements
$total = mysql_num_rows(mysql_query($selection,$cnx));
// Nombre maximum de pages
$max_pg = ceil($total / $nb);
// SELECTion des enregistrements pour la page considérée
$selection .= ' LIMIT '.(($page-1) * $nb).','.$nb.'';
$query = mysql_query($selection, $cnx);
} //fin else
$nombre_resultats = mysql_num_rows($query); //compte le nombre d'entrées sélectionnées par la recherche
$somme = array();
$somme2 = array();
if ($nombre_resultats == 0) //s'il n'y a pas de résultat
{
echo("<META HTTP-equiv=\"refresh\" content=0;URL=aucun_resultat.php?nombre_resultats=$nombre_resultats&champs1=$champs1>");
}
else //il y a au moins un résultat
{?>
<div id="navigationnn1"><!-- c'est la partie au en remplit le contenu-->
<div id="resultatsite">
<b>Recherche dans le site</b>
</div>
<!-- <div id="text">Si vous cherchez une offre de <b>stage</b> ou d'<b>emploi</b></div>-->
<form method="post" action="afficher_visiteur.php">
<table width="700" align="center" bgcolor="#333366" style="margin-top:-15px; " >
<tr>
<td><span class="Style1">Choisir et lancer maintenant votre recherche</span></td>
</tr>
<tr>
<td bgcolor="#F2F2F2"> <p>
</p>
<p>
<input type="text" name="recherche" value="<?php if (isset($_POST['recherche'])) echo htmlentities(trim($_POST['recherche'])); ?>" SIZE="31" MAXLENGTH="255" style="margin-bottom:10px;">
<input type="submit" value="Rechercher" name="rechercher" style="margin-bottom:10px;">
<br>
<select name="mode" style="float:left; margin-left:185px; display:none " >
<option value="expression_exacte">Expression Eexacte</option>
<option value="tous_les_mots">Tout les mots</option>
<option value="un_mot" selected>Au moins un mot</option>
</select>
Rechercher dans :
<input type="radio" name="offre" value="stage"> Stage
<input type="radio" name="offre" value="emploi" checked> Emploi </p>
<p> </p></td>
</tr>
</table>
<?php
echo 'Page: ';
print "<select name='page'>";
for($i = 1 ; $i <= $max_pg ; $i++)
{
if ($i==$page)
print "<option selected value='$i'>$i</option>";
else
print "<option value='$i'>$i</option>";
}
print "</select>";
print " <button type=Submit name=''> OK </button>";
?>
</form>
<hr style="border-bottom:solid 1px #000066; margin-top:-20px;width:900px; "></hr>
<?php
echo '<div style="background-color:#E0E0E0; width:900px; margin-top:-25px; height:25px; text-align:left;">
<strong>Site</strong>
Nombre de résultats : <strong> ' . $nombre_resultats . '</strong> pour <strong>'.$champs1.'</strong> </div><br /><br />'; //nombre de résultats
while($resultats = mysql_fetch_array($query) ) //boucle affichant les résultats
{
if(!array_key_exists($resultats["url"], $somme))
{
$somme[$resultats["url"]] = 0;
$somme[$resultats["url"]] += $resultats["poids"];
}
if(!array_key_exists($resultats["url"], $somme2))
{
$somme2[$resultats["url"]] = 0;
$somme2[$resultats["url"]] += $resultats["poids"] * $resultats["poids"];
}
}
arsort($somme);
foreach ($somme as $url => $poids)
{
$somme_carre=$somme2[$url];
$racine_sommecarre=sqrt($somme2[$url]);
$somme_mot=sqrt($nombre_mots);
$rsv=$poids/($somme_mot*$racine_sommecarre);
$affichage="select titre,resume,type_offre FROM document WHERE url='$url'";
$affichage1=mysql_query($affichage);
$affichage2 = mysql_fetch_array($affichage1);
echo '<p align="left" style="margin-bottom:-60px; font-size=20px; margin-left:18px;"><a href=' .$url. '>'.$affichage2['titre'].'</a>...<p><br>
<p><hr style="border-bottom:solid 1px #000066;width:870px; margin-left:3px; margin-bottom:-50px;"></hr></p><br>
<p align="left" style="margin-bottom:-50px; margin-left:35px; margin-top:-30px; margin-right:20px;">'.$affichage2['resume'].'...<p><br>
<p align="left" style="margin-bottom:-50px; color:#0F7C91; margin-left:35px;">' . $url . '<p><br><br><br>';
}
}//fin else
} //fin de if(isset)
else //si on n'a pas validé le formulaire, on l'affiche
{?>
<div id="recherchesite">
<b>Recherche dans le site</b>
</div>
<div id="text">Si vous cherchez une offre de <b>stage</b> ou d'<b>emploi</b></div>
<div id="espace">
<form method="post" action="afficher_visiteur.php">
<table width="700" align="center" bgcolor="#333366" >
<tr>
<td><span class="Style1">Choisir et lancer maintenant votre recherche</span></td>
</tr>
<td bgcolor="#F2F2F2"> <p>
</p>
<p>
<input type="text" name="recherche" value="<?php if (isset($_POST['recherche'])) echo htmlentities(trim($_POST['recherche'])); ?>" SIZE="31" MAXLENGTH="255" style="margin-bottom:10px;">
<input type="submit" value="Rechercher" name="rechercher" style="margin-bottom:10px;">
<br>
<select name="mode" style="float:left; margin-left:185px; display:none " >
<option value="expression_exacte">Expression Eexacte</option>
<option value="tous_les_mots">Tout les mots</option>
<option value="un_mot" selected>Au moins un mot</option>
</select>
Rechercher dans :
<input type="radio" name="offre" value="stage"> Stage
<input type="radio" name="offre" value="emploi" checked> Emploi </p>
<p> </p></td>
</tr>
<tr>
</table>
</form>
<?php
}
mysql_close(); //déconnexion de la bdd
?> |
Partager