mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-26 16:41:21 +01:00
fix: move record to controller
This commit is contained in:
@@ -66,6 +66,7 @@ searchController.search = async function (req, res, next) {
|
|||||||
|
|
||||||
const [searchData, categoriesData] = await Promise.all([
|
const [searchData, categoriesData] = await Promise.all([
|
||||||
search.search(data),
|
search.search(data),
|
||||||
|
recordSearch(data);
|
||||||
buildCategories(req.uid, searchOnly),
|
buildCategories(req.uid, searchOnly),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -95,6 +96,14 @@ searchController.search = async function (req, res, next) {
|
|||||||
res.render('search', searchData);
|
res.render('search', searchData);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async function recordSearch(data) {
|
||||||
|
const { query, searchIn } = data;
|
||||||
|
const cleanedQuery = String(query).trim().toLowerCase().substr(0, 255);
|
||||||
|
if (['titles', 'titlesposts', 'posts'].includes(searchIn) && cleanedQuery.length > 2) {
|
||||||
|
await db.sortedSetIncrBy('searches:all', 1, cleanedQuery);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function buildCategories(uid, searchOnly) {
|
async function buildCategories(uid, searchOnly) {
|
||||||
if (searchOnly) {
|
if (searchOnly) {
|
||||||
return [];
|
return [];
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ async function searchInContent(data) {
|
|||||||
|
|
||||||
async function doSearch(type, searchIn) {
|
async function doSearch(type, searchIn) {
|
||||||
if (searchIn.includes(data.searchIn)) {
|
if (searchIn.includes(data.searchIn)) {
|
||||||
await recordSearch(data.query);
|
|
||||||
return await plugins.hooks.fire('filter:search.query', {
|
return await plugins.hooks.fire('filter:search.query', {
|
||||||
index: type,
|
index: type,
|
||||||
content: data.query,
|
content: data.query,
|
||||||
@@ -95,13 +94,6 @@ async function searchInContent(data) {
|
|||||||
return Object.assign(returnData, metadata);
|
return Object.assign(returnData, metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function recordSearch(query) {
|
|
||||||
const cleanedQuery = String(query).trim().toLowerCase().substr(0, 255);
|
|
||||||
if (cleanedQuery.length > 2) {
|
|
||||||
await db.sortedSetIncrBy('searches:all', 1, cleanedQuery);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function filterAndSort(pids, data) {
|
async function filterAndSort(pids, data) {
|
||||||
if (data.sortBy === 'relevance' && !data.replies && !data.timeRange && !data.hasTags && !plugins.hooks.hasListeners('filter:search.filterAndSort')) {
|
if (data.sortBy === 'relevance' && !data.replies && !data.timeRange && !data.hasTags && !plugins.hooks.hasListeners('filter:search.filterAndSort')) {
|
||||||
return pids;
|
return pids;
|
||||||
|
|||||||
Reference in New Issue
Block a user