mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-23 07:01:12 +01:00
fix: category search shoudn't return results that match in the cid part
This commit is contained in:
@@ -77,17 +77,19 @@ module.exports = function (Categories) {
|
||||
if (!query || String(query).length < 2) {
|
||||
return [];
|
||||
}
|
||||
const searchQuery = String(query).toLowerCase();
|
||||
const data = await db.getSortedSetScan({
|
||||
key: 'categories:name',
|
||||
match: `*${String(query).toLowerCase()}*`,
|
||||
match: `*${searchQuery}*`,
|
||||
limit: hardCap || 500,
|
||||
});
|
||||
return data.map((data) => {
|
||||
const split = data.split(':');
|
||||
split.shift();
|
||||
const cid = split.join(':');
|
||||
return cid;
|
||||
});
|
||||
return data.reduce((acc, match) => {
|
||||
const [name, ...cidParts] = match.split(':');
|
||||
if (name.includes(searchQuery)) {
|
||||
acc.push(cidParts.join(':'));
|
||||
}
|
||||
return acc;
|
||||
}, []);
|
||||
}
|
||||
|
||||
async function getChildrenCids(cids, uid) {
|
||||
|
||||
Reference in New Issue
Block a user