dont record searches made by composer

This commit is contained in:
Barış Soner Uşaklı
2023-01-31 23:07:49 -05:00
parent ae048e1289
commit 69597d6333
4 changed files with 24 additions and 67 deletions

View File

@@ -91,7 +91,7 @@
"multiparty": "4.2.3",
"nconf": "0.12.0",
"nodebb-plugin-2factor": "7.0.1",
"nodebb-plugin-composer-default": "10.0.40",
"nodebb-plugin-composer-default": "10.0.41",
"nodebb-plugin-dbsearch": "6.0.0",
"nodebb-plugin-emoji": "5.0.3",
"nodebb-plugin-emoji-android": "4.0.0",

View File

@@ -23,8 +23,6 @@ get:
type: boolean
search_query:
type: string
expandSearch:
type: boolean
showAsPosts:
type: boolean
showAsTopics:

View File

@@ -238,7 +238,9 @@ define('search', ['translator', 'storage', 'hooks', 'alerts'], function (transla
Search.api = function (data, callback) {
const apiURL = config.relative_path + '/api/search?' + createQueryString(data);
data.searchOnly = undefined;
if (data.hasOwnProperty('searchOnly')) {
delete data.searchOnly;
}
const searchURL = config.relative_path + '/search?' + createQueryString(data);
$.get(apiURL, function (result) {
result.url = searchURL;
@@ -248,7 +250,6 @@ define('search', ['translator', 'storage', 'hooks', 'alerts'], function (transla
function createQueryString(data) {
const searchIn = data.in || 'titles';
const postedBy = data.by || '';
let term = data.term.replace(/^[ ?#]*/, '');
try {
term = encodeURIComponent(term);
@@ -257,52 +258,11 @@ define('search', ['translator', 'storage', 'hooks', 'alerts'], function (transla
}
const query = {
...data,
term: term,
in: searchIn,
};
if (data.matchWords) {
query.matchWords = data.matchWords;
}
if (postedBy && postedBy.length && (searchIn === 'posts' || searchIn === 'titles' || searchIn === 'titlesposts')) {
query.by = postedBy;
}
if (data.categories && data.categories.length) {
query.categories = data.categories;
if (data.searchChildren) {
query.searchChildren = data.searchChildren;
}
}
if (data.hasTags && data.hasTags.length) {
query.hasTags = data.hasTags;
}
if (parseInt(data.replies, 10) > 0) {
query.replies = data.replies;
query.repliesFilter = data.repliesFilter || 'atleast';
}
if (data.timeRange) {
query.timeRange = data.timeRange;
query.timeFilter = data.timeFilter || 'newer';
}
if (data.sortBy) {
query.sortBy = data.sortBy;
query.sortDirection = data.sortDirection;
}
if (data.showAs) {
query.showAs = data.showAs;
}
if (data.searchOnly) {
query.searchOnly = data.searchOnly;
}
hooks.fire('action:search.createQueryString', {
query: query,
data: data,

View File

@@ -88,8 +88,6 @@ searchController.search = async function (req, res, next) {
searchData.breadcrumbs = helpers.buildBreadcrumbs([{ text: '[[global:search]]' }]);
searchData.expandSearch = !req.query.term;
searchData.showAsPosts = !req.query.showAs || req.query.showAs === 'posts';
searchData.showAsTopics = req.query.showAs === 'topics';
searchData.title = '[[global:header.search]]';
@@ -148,25 +146,26 @@ const searches = {};
async function recordSearch(data) {
const { query, searchIn } = data;
if (query) {
const cleanedQuery = String(query).trim().toLowerCase().slice(0, 255);
if (['titles', 'titlesposts', 'posts'].includes(searchIn) && cleanedQuery.length > 2) {
searches[data.uid] = searches[data.uid] || { timeoutId: 0, queries: [] };
searches[data.uid].queries.push(cleanedQuery);
if (searches[data.uid].timeoutId) {
clearTimeout(searches[data.uid].timeoutId);
}
searches[data.uid].timeoutId = setTimeout(async () => {
if (searches[data.uid] && searches[data.uid].queries) {
const copy = searches[data.uid].queries.slice();
const filtered = searches[data.uid].queries.filter(
q => !copy.find(query => query.startsWith(q) && query.length > q.length)
);
delete searches[data.uid];
await Promise.all(filtered.map(query => db.sortedSetIncrBy('searches:all', 1, query)));
}
}, 5000);
if (!query || parseInt(data.qs.composer, 10) === 1) {
return;
}
const cleanedQuery = String(query).trim().toLowerCase().slice(0, 255);
if (['titles', 'titlesposts', 'posts'].includes(searchIn) && cleanedQuery.length > 2) {
searches[data.uid] = searches[data.uid] || { timeoutId: 0, queries: [] };
searches[data.uid].queries.push(cleanedQuery);
if (searches[data.uid].timeoutId) {
clearTimeout(searches[data.uid].timeoutId);
}
searches[data.uid].timeoutId = setTimeout(async () => {
if (searches[data.uid] && searches[data.uid].queries) {
const copy = searches[data.uid].queries.slice();
const filtered = searches[data.uid].queries.filter(
q => !copy.find(query => query.startsWith(q) && query.length > q.length)
);
delete searches[data.uid];
await Promise.all(filtered.map(query => db.sortedSetIncrBy('searches:all', 1, query)));
}
}, 5000);
}
}