diff --git a/api/request.php b/api/request.php index 1be68e5..2df4caf 100644 --- a/api/request.php +++ b/api/request.php @@ -1,24 +1,13 @@ 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; $iprepare("SELECT nom FROM salleAlias WHERE salleID=?"); + $stmt->execute([$theid]); + $resS = $stmt->fetchAll(); + + $nomz = array(); + for($j=0;$j $res[$i]['salleID'], "name" => $res[$i]["nom"]); - + $out[$theid] = array('noms' => $nomz); + } + + for($i=0; $iprepare("SELECT personne FROM locataires WHERE salleID=?"); + $stmt->execute([$theid]); + $resL = $stmt->fetchAll(); + + $locatairez = array(); + for($j=0;$jprepare("SELECT salleID, personne FROM `locataires` WHERE MATCH personne AGAINST (? IN BOOLEAN MODE)"); - $stmt->execute([$salleLocSearch]); - $res = $stmt->fetchAll(); - - $out = array(); - - for($i=0;$i $res[$i]['salleID'], "personne" => $res[$i]["personne"]); - - echo (json_encode($out)); - -}else { +} else { echo "Je ne connais pas cette commande ..."; } diff --git a/api/setupTntsearch.php b/api/setupTntsearch.php new file mode 100644 index 0000000..25d384f --- /dev/null +++ b/api/setupTntsearch.php @@ -0,0 +1,23 @@ + loadConfig($tntconfig); diff --git a/api/updateIndexes.php b/api/updateIndexes.php index 026de49..9b06e5d 100644 --- a/api/updateIndexes.php +++ b/api/updateIndexes.php @@ -4,37 +4,15 @@ ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); -set_include_path(get_include_path() . PATH_SEPARATOR . './tntsearch/src/'); -use TeamTNT\TNTSearch\TNTSearch; -use TeamTNT\TNTSearch\Support; - -include_once 'TNTSearch.php'; -include_once 'Support/AbstractTokenizer.php'; -include_once 'Support/TokenizerInterface.php'; -include_once 'Support/Tokenizer.php'; -include_once 'Support/Collection.php'; -include_once 'FileReaders/FileReaderInterface.php'; -include_once 'FileReaders/TextFileReader.php'; -include_once 'Indexer/TNTIndexer.php'; -include_once 'Stemmer/Stemmer.php'; -include_once 'Stemmer/FrenchStemmer.php'; -include_once 'Stemmer/NoStemmer.php'; -include_once 'Connectors/ConnectorInterface.php'; -include_once 'Connectors/Connector.php'; -include_once 'Connectors/MySqlConnector.php'; - -$tnt = new TNTSearch; - // Se connecte à la BDD (identifiants cachés) // Charge les paramètres de tnt dans $tntconfig -include 'dbinit.php'; +include_once 'dbinit.php'; +include_once 'setupTntsearch.php'; -$tnt->loadConfig($tntconfig); - -$indexer = $tnt->createIndex('sallesNoms.index'); -$indexer->query('SELECT ID, nom FROM salleAlias;'); +$indexer = $tnt->createIndex('salleSearch.index'); +$indexer->query('(SELECT salleId AS id, nom AS searchText FROM salleAlias) UNION (SELECT salleId AS id, personne AS searchText FROM locataires)'); $indexer->setLanguage('french'); -$indexer->setPrimaryKey('ID'); $indexer->run(); +echo "
"; echo "Mise à jour de l'index faite avec succès !";