Merge branch 'searchengine'

This commit is contained in:
Mysaa 2021-10-26 23:16:12 +02:00
commit 95b3fea2ef
Signed by: Mysaa
GPG Key ID: DBA23608F23F5A10
7 changed files with 1950 additions and 9043 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ svg-pan-zoom.min.js
tinycolor-min.js
api/dbinit.php
api/sallesNoms.index

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "api/tntsearch"]
path = api/tntsearch
url = git@github.com:teamtnt/tntsearch.git

View File

@ -6,9 +6,8 @@ ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Se connecte à la BDD (identifiants cachés)
include 'dbinit.php';
// Charge les paramètres de tnt dans $tntconfig
include_once 'dbinit.php';
if(isset($_GET["salle"])) {
@ -54,32 +53,48 @@ if(isset($_GET["salle"])) {
echo (json_encode($out));
}
} else if (isset($_GET["research"])) {
$research = $_GET["research"];
} else if (isset($_GET["search"])) {
$searchText = $_GET["search"];
$rescount = isset($_GET["rescount"])?$_GET["rescount"]:7;
$stmt = $conn->prepare("SELECT salleID, nom FROM salleAlias WHERE MATCH nom AGAINST (? IN BOOLEAN MODE)");
$stmt->execute([$research]);
$res = $stmt->fetchAll();
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);$i++)
$out[$i] = array("id" => $res[$i]['salleID'], "name" => $res[$i]["nom"]);
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();
echo (json_encode($out));
$nomz = array();
for($j=0;$j<count($resS);$j++)
$nomz[$j] = $resS[$j]['nom'];
} else if (isset($_GET["salleLocSearch"])) {
$out[$theid] = array('noms' => $nomz);
}
$salleLocSearch = $_GET["salleLocSearch"];
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();
$stmt = $conn->prepare("SELECT salleID, personne FROM `locataires` WHERE MATCH personne AGAINST (? IN BOOLEAN MODE)");
$stmt->execute([$salleLocSearch]);
$res = $stmt->fetchAll();
$locatairez = array();
for($j=0;$j<count($resL);$j++)
$locatairez[$j] = $resL[$j]['personne'];
$out = array();
$out[$theid]['locataires'] = $locatairez;
}
for($i=0;$i<count($res);$i++)
$out[$i] = array("salleID" => $res[$i]['salleID'], "personne" => $res[$i]["personne"]);
echo (json_encode($out));

23
api/setupTntsearch.php Normal file
View File

@ -0,0 +1,23 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . './tntsearch/src/');
use TeamTNT\TNTSearch\TNTSearch;
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;
$tnt->loadConfig($tntconfig);

1
api/tntsearch Submodule

@ -0,0 +1 @@
Subproject commit 1fd7b79467dffe141de3691942d11127a21c2cbd

18
api/updateIndexes.php Normal file
View File

@ -0,0 +1,18 @@
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Se connecte à la BDD (identifiants cachés)
// Charge les paramètres de tnt dans $tntconfig
include_once 'dbinit.php';
include_once 'setupTntsearch.php';
$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->run();
echo "<br/>";
echo "Mise à jour de l'index faite avec succès !";

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 680 KiB

After

Width:  |  Height:  |  Size: 788 KiB