mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
refactor: search logic to use switch..case
This commit is contained in:
@@ -19,20 +19,33 @@ search.search = async function (data) {
|
||||
data.sortBy = data.sortBy || 'relevance';
|
||||
|
||||
let result;
|
||||
if (['posts', 'titles', 'titlesposts', 'bookmarks'].includes(data.searchIn)) {
|
||||
result = await searchInContent(data);
|
||||
} else if (data.searchIn === 'users') {
|
||||
result = await user.search(data);
|
||||
} else if (data.searchIn === 'categories') {
|
||||
result = await categories.search(data);
|
||||
} else if (data.searchIn === 'tags') {
|
||||
result = await topics.searchAndLoadTags(data);
|
||||
} else if (data.searchIn) {
|
||||
result = await plugins.hooks.fire('filter:search.searchIn', {
|
||||
data,
|
||||
});
|
||||
} else {
|
||||
throw new Error('[[error:unknown-search-filter]]');
|
||||
switch (data.searchIn) {
|
||||
case 'users': {
|
||||
result = await user.search(data);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'categories': {
|
||||
result = await categories.search(data);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'tags': {
|
||||
result = await topics.searchAndLoadTags(data);
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
if (['posts', 'titles', 'titlesposts', 'bookmarks'].includes(data.searchIn)) {
|
||||
result = await searchInContent(data);
|
||||
} else if (data.searchIn) {
|
||||
result = await plugins.hooks.fire('filter:search.searchIn', {
|
||||
data,
|
||||
});
|
||||
} else {
|
||||
throw new Error('[[error:unknown-search-filter]]');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result.time = (process.elapsedTimeSince(start) / 1000).toFixed(2);
|
||||
|
||||
Reference in New Issue
Block a user