Update search

This commit is contained in:
2024-05-16 01:25:08 -04:00
parent 15f486205d
commit f4d17bb7dc
4 changed files with 64 additions and 8 deletions

View File

@ -239,12 +239,14 @@ class AjaxController extends AbstractController
return $res;
}
#[Route('/search-note', name: 'app_open_note')]
public function openNote(Request $req, EntityManagerInterface $emi): Response
#[Route('/search', name: 'app_search_note')]
public function searchNote(Request $req, EntityManagerInterface $emi): Response
{
/** @var User $user */
$user = $this->getUser();
$res = new Response();
$data = json_decode($req->getContent());
$note = $emi->getRepository(Note::class)->findNote($data->search);
$note = $emi->getRepository(Note::class)->findNote($data->query, $user->getId()->toBinary());
$res->setContent(json_encode($note));
return $res;

View File

@ -29,6 +29,22 @@ class NoteRepository extends ServiceEntityRepository
return $ret;
}
public function findNote(string $query, string $userId): array
{
$ret = $this->createQueryBuilder('n')
->orderBy('n.date', 'DESC')
->where('n.title LIKE :query')
->orWhere('n.passage LIKE :query')
->andWhere('n.user = :user')
->setParameter('query', "%{$query}%")
->setParameter('user', $userId)
->setMaxResults(3)
->getQuery()
->getResult();
return $ret;
}
// /**
// * @return Note[] Returns an array of Note objects
// */