This commit is contained in:
parent
7b74c2a37d
commit
476089ecc6
@ -39,9 +39,12 @@ app.get('/api/search', async (req, res) => {
|
|||||||
return res.json([]);
|
return res.json([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Escape special regex characters to allow literal search
|
||||||
|
const escapedQuery = query.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||||
|
|
||||||
// Search by family name (case-insensitive)
|
// Search by family name (case-insensitive)
|
||||||
const matches = await Family.find({
|
const matches = await Family.find({
|
||||||
family: { $regex: query, $options: 'i' }
|
family: { $regex: escapedQuery, $options: 'i' }
|
||||||
}).select('-__v -createdAt -updatedAt');
|
}).select('-__v -createdAt -updatedAt');
|
||||||
|
|
||||||
res.json(matches);
|
res.json(matches);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user