feat: aggiunta ricerca tramite regex nella pagina ricerca supodrata con modal che fornisce rapide indicazioni.
This commit is contained in:
1 parent
2ca95e062a
commit
d32522bcbb
4 files changed
+233
-22
No files matched your search
+38
-13
@@ -212,20 +212,45 @@ router.get('/', async (req, res) => {
|
||||
}
|
||||
const searchTerm = search || sub_search;
|
||||
if (searchTerm) {
|
||||
conditions.push(`(
|
||||
t.title ILIKE $${paramIdx} OR
|
||||
t.tn ILIKE $${paramIdx} OR
|
||||
EXISTS (
|
||||
SELECT 1 FROM article art
|
||||
LEFT JOIN article_data_mime adm ON art.id = adm.article_id
|
||||
WHERE art.ticket_id = t.id AND (
|
||||
adm.a_subject ILIKE $${paramIdx} OR
|
||||
adm.a_body ILIKE $${paramIdx}
|
||||
const isRegex = req.query.is_regex === 'true' || req.query.is_regex === '1';
|
||||
if (isRegex) {
|
||||
// Validate regex pattern to prevent DB syntax error
|
||||
try {
|
||||
new RegExp(searchTerm);
|
||||
} catch (regexErr) {
|
||||
return res.status(400).json({ error: `Espressione regolare non valida: ${regexErr.message}` });
|
||||
}
|
||||
|
||||
conditions.push(`(
|
||||
t.title ~* $${paramIdx} OR
|
||||
t.tn ~* $${paramIdx} OR
|
||||
EXISTS (
|
||||
SELECT 1 FROM article art
|
||||
LEFT JOIN article_data_mime adm ON art.id = adm.article_id
|
||||
WHERE art.ticket_id = t.id AND (
|
||||
adm.a_subject ~* $${paramIdx} OR
|
||||
adm.a_body ~* $${paramIdx}
|
||||
)
|
||||
)
|
||||
)
|
||||
)`);
|
||||
params.push(`%${searchTerm}%`);
|
||||
paramIdx++;
|
||||
)`);
|
||||
params.push(searchTerm);
|
||||
paramIdx++;
|
||||
} else {
|
||||
conditions.push(`(
|
||||
t.title ILIKE $${paramIdx} OR
|
||||
t.tn ILIKE $${paramIdx} OR
|
||||
EXISTS (
|
||||
SELECT 1 FROM article art
|
||||
LEFT JOIN article_data_mime adm ON art.id = adm.article_id
|
||||
WHERE art.ticket_id = t.id AND (
|
||||
adm.a_subject ILIKE $${paramIdx} OR
|
||||
adm.a_body ILIKE $${paramIdx}
|
||||
)
|
||||
)
|
||||
)`);
|
||||
params.push(`%${searchTerm}%`);
|
||||
paramIdx++;
|
||||
}
|
||||
}
|
||||
|
||||
const whereClause = conditions.length > 0
|
||||
|
||||
Reference in new issue
Block a user