mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-03 11:01:20 +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) {
|
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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user