fix: category search shoudn't return results that match in the cid part

This commit is contained in:
Barış Soner Uşaklı
2026-02-21 13:49:46 -05:00
parent 84ec8ef94b
commit 75477202d3

View File

@@ -77,17 +77,19 @@ module.exports = function (Categories) {
if (!query || String(query).length < 2) { if (!query || String(query).length < 2) {
return []; return [];
} }
const searchQuery = String(query).toLowerCase();
const data = await db.getSortedSetScan({ const data = await db.getSortedSetScan({
key: 'categories:name', key: 'categories:name',
match: `*${String(query).toLowerCase()}*`, match: `*${searchQuery}*`,
limit: hardCap || 500, limit: hardCap || 500,
}); });
return data.map((data) => { return data.reduce((acc, match) => {
const split = data.split(':'); const [name, ...cidParts] = match.split(':');
split.shift(); if (name.includes(searchQuery)) {
const cid = split.join(':'); acc.push(cidParts.join(':'));
return cid; }
}); return acc;
}, []);
} }
async function getChildrenCids(cids, uid) { async function getChildrenCids(cids, uid) {