Skip to content

Commit bd2a73a

Browse files
committed
feat: make full-text search case-insensitive and search by submission author as well
Signed-off-by: Kostiantyn Miakshyn <molodchick@gmail.com>
1 parent 917e1e5 commit bd2a73a

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

docs/API_v3.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,9 @@ Get all Submissions to a Form
845845
|-----------|---------|-------------|
846846
| _formId_ | Integer | ID of the form to get the submissions for |
847847
| _submissionId_ | Integer | ID of the submission to get |
848+
| _query_ | Integer | Search string for full-text search. Can be a username |
849+
| _limit_ | Integer | How many submissions to fetch |
850+
| _offset_ | Integer | Offset for the pagination |
848851
- Response: The submission
849852

850853
```

lib/Db/SubmissionMapper.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ public function __construct(
3333
*
3434
* @param int $formId The ID of the form whose submissions are being retrieved.
3535
* @param string|null $userId An optional user ID to filter the submissions.
36-
* @param string|null $query An optional search query to filter the submissions.
36+
* @param string|null $searchString An optional search query to filter the submissions.
3737
* @param int|null $limit The maximum number of submissions to retrieve, default: all submissions
3838
* @param int $offset The number of submissions to skip before starting to retrieve, default: 0
3939
*
4040
* @return Submission[] An array of Submission objects.
4141
* @throws DoesNotExistException If no submissions are found for the given form ID.
4242
*
4343
*/
44-
public function findByForm(int $formId, ?string $userId = null, ?string $query = null, ?int $limit = null, int $offset = 0): array {
44+
public function findByForm(int $formId, ?string $userId = null, ?string $searchString = null, ?int $limit = null, int $offset = 0): array {
4545
$qb = $this->db->getQueryBuilder();
4646

4747
$filters = [
@@ -61,15 +61,18 @@ public function findByForm(int $formId, ?string $userId = null, ?string $query =
6161
->setMaxResults($limit);
6262

6363
// If a query is provided, join the answers table and filter by the query text
64-
if (!is_null($query) && $query !== '') {
64+
if (!is_null($searchString) && $searchString !== '') {
6565
$qb->join(
6666
'submissions',
6767
$this->answerMapper->getTableName(),
6868
'answers',
6969
$qb->expr()->eq('submissions.id', 'answers.submission_id')
7070
)
7171
->andWhere(
72-
$qb->expr()->like('answers.text', $qb->createNamedParameter('%' . $query . '%'))
72+
$qb->expr()->orX(
73+
$qb->expr()->iLike('submissions.user_id', $qb->createNamedParameter('%' . $searchString . '%')),
74+
$qb->expr()->iLike('answers.text', $qb->createNamedParameter('%' . $searchString . '%')),
75+
),
7376
);
7477
}
7578

@@ -156,7 +159,10 @@ protected function countSubmissionsWithFilters(int $formId, ?string $userId = nu
156159
$qb->expr()->eq('submissions.id', 'answers.submission_id')
157160
)
158161
->andWhere(
159-
$qb->expr()->like('answers.text', $qb->createNamedParameter('%' . $searchString . '%'))
162+
$qb->expr()->orX(
163+
$qb->expr()->iLike('submissions.user_id', $qb->createNamedParameter('%' . $searchString . '%')),
164+
$qb->expr()->iLike('answers.text', $qb->createNamedParameter('%' . $searchString . '%')),
165+
),
160166
);
161167
}
162168

0 commit comments

Comments
 (0)