mirror of
https://gitlab.aliens-lyon.fr/savrillo/gpens.git
synced 2026-09-11 18:30:45 +02:00
L'api de recherche est maintenant fonctionelle, jusqu'au nouveaux bugs découverts.
This commit is contained in:
+43
-38
@@ -1,24 +1,13 @@
|
||||
<?php
|
||||
|
||||
use 'tntsearch/src/TNTSearch.php'
|
||||
|
||||
// Active les erreurs PHP.
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
$tnt = new TNTSearch;
|
||||
|
||||
// Se connecte à la BDD (identifiants cachés)
|
||||
// Charge les paramètres de tnt dans $tntconfig
|
||||
include 'dbinit.php';
|
||||
|
||||
$tnt->loadConfig($tntconfig);
|
||||
|
||||
$indexer = $tnt->createIndex('tntsearch/sallesNoms.index');
|
||||
$indexer->query('SELECT id, nom FROM sallesAlias;');
|
||||
$indexer->setLanguage('french');
|
||||
$indexer->run();
|
||||
include_once 'dbinit.php';
|
||||
|
||||
if(isset($_GET["salle"])) {
|
||||
|
||||
@@ -64,35 +53,51 @@ if(isset($_GET["salle"])) {
|
||||
echo (json_encode($out));
|
||||
}
|
||||
|
||||
} else if (isset($_GET["research"])) {
|
||||
$research = $_GET["research"];
|
||||
|
||||
$stmt = $conn->prepare("SELECT salleID, nom FROM salleAlias WHERE MATCH nom AGAINST (? IN BOOLEAN MODE)");
|
||||
$stmt->execute([$research]);
|
||||
$res = $stmt->fetchAll();
|
||||
|
||||
} else if (isset($_GET["search"])) {
|
||||
$searchText = $_GET["search"];
|
||||
$rescount = isset($_GET["rescount"])?$_GET["rescount"]:7;
|
||||
|
||||
include_once 'setupTntsearch.php';
|
||||
|
||||
$tnt->selectIndex("salleSearch.index");
|
||||
$tnt->fuzziness = true;
|
||||
$tnt->fuzzy_prefix_length = 2;
|
||||
$tnt->fuzzy_max_expansions = 50;
|
||||
$tnt->fuzzy_distance = 2; //represents the Levenshtein distance;
|
||||
|
||||
$res = $tnt->search($searchText,$rescount);
|
||||
|
||||
$out = array();
|
||||
|
||||
for($i=0; $i<count($res['ids']); $i++){
|
||||
$theid = $res['ids'][$i];
|
||||
$stmt = $conn->prepare("SELECT nom FROM salleAlias WHERE salleID=?");
|
||||
$stmt->execute([$theid]);
|
||||
$resS = $stmt->fetchAll();
|
||||
|
||||
$nomz = array();
|
||||
for($j=0;$j<count($resS);$j++)
|
||||
$nomz[$j] = $resS[$j]['nom'];
|
||||
|
||||
for($i=0;$i<count($res);$i++)
|
||||
$out[$i] = array("id" => $res[$i]['salleID'], "name" => $res[$i]["nom"]);
|
||||
|
||||
$out[$theid] = array('noms' => $nomz);
|
||||
}
|
||||
|
||||
for($i=0; $i<count($res["ids"]); $i++){
|
||||
$theid = $res['ids'][$i];
|
||||
$stmt = $conn->prepare("SELECT personne FROM locataires WHERE salleID=?");
|
||||
$stmt->execute([$theid]);
|
||||
$resL = $stmt->fetchAll();
|
||||
|
||||
$locatairez = array();
|
||||
for($j=0;$j<count($resL);$j++)
|
||||
$locatairez[$j] = $resL[$j]['personne'];
|
||||
|
||||
$out[$theid]['locataires'] = $locatairez;
|
||||
}
|
||||
|
||||
|
||||
echo (json_encode($out));
|
||||
|
||||
} else if (isset($_GET["salleLocSearch"])) {
|
||||
|
||||
$salleLocSearch = $_GET["salleLocSearch"];
|
||||
|
||||
$stmt = $conn->prepare("SELECT salleID, personne FROM `locataires` WHERE MATCH personne AGAINST (? IN BOOLEAN MODE)");
|
||||
$stmt->execute([$salleLocSearch]);
|
||||
$res = $stmt->fetchAll();
|
||||
|
||||
$out = array();
|
||||
|
||||
for($i=0;$i<count($res);$i++)
|
||||
$out[$i] = array("salleID" => $res[$i]['salleID'], "personne" => $res[$i]["personne"]);
|
||||
|
||||
echo (json_encode($out));
|
||||
|
||||
}else {
|
||||
} else {
|
||||
echo "Je ne connais pas cette commande ...";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user