Ajout d'une méthode de recherche plus profonde

This commit is contained in:
MysaaJava 2023-03-13 11:07:39 +01:00
parent 758fe02fbf
commit b7b6a492b8
Signed by: Mysaa
GPG Key ID: DBA23608F23F5A10
3 changed files with 74 additions and 0 deletions

22
API.md
View File

@ -120,6 +120,28 @@ __Notes :__
---------------------
### /api/map/search_place?text=TEXT
> Return a list of dict representing all names (place name or user name)
> which matches the query TEXT, along with associated place id.
__Format of the dict :__
```json
[
{
'type': char, //'U' if matching text is an user name, 'P' if it is a place name
'txt':string, //the matching name (whichever type)
'pid': int, //id of the associated place
'floor' : string, //id of the lowest floor the place is part of
'rank': float //the «match» score of this txt against query TEXT
},
{...}
]
```
__Notes :__
- If _NAME_ doesn't correspond to any registered place : Return an Empty list.
---------------------
### /api/map/get_site_name/ID
> Return the name of the Site ID.

View File

@ -8,6 +8,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\PreconditionFailedHttpException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
@ -159,6 +160,15 @@ class MapApiController extends AbstractController
return $this->json($result);
}
#[Route('/map/search_place')]
public function search_place(Request $request, PlaceRepository $pnRepo) {
$text = $request->query->get('text');
$res = $pnRepo->searchPlaceNameAndUser($text);
return $this->json($res);
}
#[Route('/map/get_place_info/{id}')]
public function get_place_info(PlaceRepository $rep, int $id): JsonResponse

View File

@ -78,6 +78,48 @@ class PlaceRepository extends ServiceEntityRepository
return $this->createQueryBuilder('s')->orderBy('s.id','ASC')->getQuery()->getResult();
}
public function searchPlaceNameAndUser(string $text)
{
$sql = "
(
SELECT
'U' AS type,
user_name AS txt,
run.place_id AS pid,
MIN(pf.floor_id) AS floor,
SIMILARITY(user_name,:searchtext) AS rank
FROM room_user_name AS run
JOIN place_floor AS pf ON pf.place_id=run.place_id
GROUP BY run.id
ORDER BY rank DESC
LIMIT :limit
)
UNION
(
SELECT
'P' AS type,
name AS txt,
pn.place_id AS pid,
MIN(pf.floor_id) AS floor,
SIMILARITY(name,:searchtext) AS rank
FROM place_name pn
JOIN place_floor AS pf ON pf.place_id=pn.place_id
GROUP BY pn.id
ORDER BY rank DESC
LIMIT :limit
)
ORDER BY rank DESC
LIMIT :limit;
";
$stmt = $this->getEntityManager()->getConnection()->prepare($sql);
$stmt->bindValue("searchtext",$text);
$stmt->bindValue("limit",5);
$res = $stmt->executeQuery() ;
$out = $res->fetchAllAssociative();
return $out;
}
// public function findOneBySomeField($value): ?Place
// {