mirror of
https://gitlab.aliens-lyon.fr/encartes/backend.git
synced 2026-03-17 22:51:04 +01:00
Added place search API
This commit is contained in:
parent
d6521842b2
commit
23ccfea82d
22
API.md
22
API.md
@ -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
|
### /api/map/get_site_name/ID
|
||||||
|
|
||||||
> Return the name of the Site ID.
|
> Return the name of the Site ID.
|
||||||
|
|||||||
@ -238,6 +238,22 @@ class JsonReaderController extends AbstractController
|
|||||||
$r->addCylinderRepresentation($cyl);
|
$r->addCylinderRepresentation($cyl);
|
||||||
$manager->persist($r);
|
$manager->persist($r);
|
||||||
|
|
||||||
|
$names = $room['names'];
|
||||||
|
$rusers = $room['inhabitants'];
|
||||||
|
|
||||||
|
foreach($names as $name) {
|
||||||
|
$n = new PlaceName();
|
||||||
|
$n->setName($name);
|
||||||
|
$n->setPlace($r);
|
||||||
|
$manager->persist($n);
|
||||||
|
}
|
||||||
|
foreach($rusers as $ruser) {
|
||||||
|
$ru = new RoomUserName();
|
||||||
|
$ru->setUserName($ruser);
|
||||||
|
$ru->setPlace($r);
|
||||||
|
$manager->persist($ru);
|
||||||
|
}
|
||||||
|
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|||||||
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
|
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
|
||||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||||
use Symfony\Component\HttpKernel\Exception\PreconditionFailedHttpException;
|
use Symfony\Component\HttpKernel\Exception\PreconditionFailedHttpException;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
|
||||||
@ -158,6 +159,15 @@ class MapApiController extends AbstractController
|
|||||||
}
|
}
|
||||||
return $this->json($result);
|
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}')]
|
#[Route('/map/get_place_info/{id}')]
|
||||||
|
|||||||
@ -77,6 +77,47 @@ class PlaceRepository extends ServiceEntityRepository
|
|||||||
{
|
{
|
||||||
return $this->createQueryBuilder('s')->orderBy('s.id','ASC')->getQuery()->getResult();
|
return $this->createQueryBuilder('s')->orderBy('s.id','ASC')->getQuery()->getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function searchPlaceNameAndUser(string $text)
|
||||||
|
{
|
||||||
|
$sql = "
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
run.place_id AS pid,
|
||||||
|
'U' AS type,
|
||||||
|
user_name AS txt,
|
||||||
|
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 DISTINCT ON (pn.place_id)
|
||||||
|
pn.place_id AS pid,
|
||||||
|
'P' AS type,
|
||||||
|
name AS txt,
|
||||||
|
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 pn.place_id
|
||||||
|
)
|
||||||
|
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
|
// public function findOneBySomeField($value): ?Place
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user