mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-08 23:15:48 +01:00
more search cleanup
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
/*global define, socket, app, admin, utils, bootbox, RELATIVE_PATH*/
|
/*global define, socket, app, utils, bootbox*/
|
||||||
|
|
||||||
define('admin/manage/tags', [
|
define('admin/manage/tags', [
|
||||||
'forum/infinitescroll',
|
'forum/infinitescroll',
|
||||||
@@ -25,12 +25,12 @@ define('admin/manage/tags', [
|
|||||||
}
|
}
|
||||||
|
|
||||||
timeoutId = setTimeout(function() {
|
timeoutId = setTimeout(function() {
|
||||||
socket.emit('topics.searchAndLoadTags', {query: $('#tag-search').val()}, function(err, tags) {
|
socket.emit('topics.searchAndLoadTags', {query: $('#tag-search').val()}, function(err, result) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return app.alertError(err.message);
|
return app.alertError(err.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
infinitescroll.parseAndTranslate('admin/manage/tags', 'tags', {tags: tags}, function(html) {
|
infinitescroll.parseAndTranslate('admin/manage/tags', 'tags', {tags: result.tags}, function(html) {
|
||||||
$('.tag-list').html(html);
|
$('.tag-list').html(html);
|
||||||
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
||||||
timeoutId = 0;
|
timeoutId = 0;
|
||||||
@@ -43,7 +43,7 @@ define('admin/manage/tags', [
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleModify() {
|
function handleModify() {
|
||||||
$('#modify').on('click', function(ev) {
|
$('#modify').on('click', function() {
|
||||||
var tagsToModify = $('.tag-row.selected');
|
var tagsToModify = $('.tag-row.selected');
|
||||||
if (!tagsToModify.length) {
|
if (!tagsToModify.length) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ define('forum/tags', ['forum/infinitescroll'], function(infinitescroll) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
return app.alertError(err.message);
|
return app.alertError(err.message);
|
||||||
}
|
}
|
||||||
onTagsLoaded(results, true, function() {
|
onTagsLoaded(results.tags, true, function() {
|
||||||
timeoutId = 0;
|
timeoutId = 0;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -22,15 +22,13 @@ search.search = function(data, callback) {
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
result.search_query = validator.escape(query);
|
data.search_query = validator.escape(query);
|
||||||
if (searchIn === 'titles' || searchIn === 'titlesposts') {
|
if (searchIn === 'titles' || searchIn === 'titlesposts') {
|
||||||
searchIn = 'posts';
|
searchIn = 'posts';
|
||||||
}
|
}
|
||||||
result[searchIn] = data.matches;
|
|
||||||
result.matchCount = data.matchCount;
|
data.time = (process.elapsedTimeSince(start) / 1000).toFixed(2);
|
||||||
result.pageCount = data.pageCount;
|
callback(null, data);
|
||||||
result.time = (process.elapsedTimeSince(start) / 1000).toFixed(2);
|
|
||||||
callback(null, result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var start = process.hrtime();
|
var start = process.hrtime();
|
||||||
@@ -38,18 +36,12 @@ search.search = function(data, callback) {
|
|||||||
var query = data.query;
|
var query = data.query;
|
||||||
var searchIn = data.searchIn || 'titlesposts';
|
var searchIn = data.searchIn || 'titlesposts';
|
||||||
|
|
||||||
var result = {
|
|
||||||
posts: [],
|
|
||||||
users: [],
|
|
||||||
tags: []
|
|
||||||
};
|
|
||||||
|
|
||||||
if (searchIn === 'posts' || searchIn === 'titles' || searchIn === 'titlesposts') {
|
if (searchIn === 'posts' || searchIn === 'titles' || searchIn === 'titlesposts') {
|
||||||
searchInContent(data, done);
|
searchInContent(data, done);
|
||||||
} else if (searchIn === 'users') {
|
} else if (searchIn === 'users') {
|
||||||
searchInUsers(data, done);
|
user.search(data, done);
|
||||||
} else if (searchIn === 'tags') {
|
} else if (searchIn === 'tags') {
|
||||||
searchInTags(query, done);
|
topics.searchAndLoadTags(data, done);
|
||||||
} else {
|
} else {
|
||||||
callback(new Error('[[error:unknown-search-filter]]'));
|
callback(new Error('[[error:unknown-search-filter]]'));
|
||||||
}
|
}
|
||||||
@@ -91,7 +83,7 @@ function searchInContent(data, callback) {
|
|||||||
|
|
||||||
var matchCount = 0;
|
var matchCount = 0;
|
||||||
if (!results || (!results.pids.length && !results.tids.length)) {
|
if (!results || (!results.pids.length && !results.tids.length)) {
|
||||||
return callback(null, {matches: [], matchCount: matchCount, pageCount: 1});
|
return callback(null, {posts: [], matchCount: matchCount, pageCount: 1});
|
||||||
}
|
}
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
@@ -118,7 +110,7 @@ function searchInContent(data, callback) {
|
|||||||
posts.getPostSummaryByPids(pids, data.uid, {}, next);
|
posts.getPostSummaryByPids(pids, data.uid, {}, next);
|
||||||
},
|
},
|
||||||
function(posts, next) {
|
function(posts, next) {
|
||||||
next(null, {matches: posts, matchCount: matchCount, pageCount: Math.max(1, Math.ceil(parseInt(matchCount, 10) / 10))});
|
next(null, {posts: posts, matchCount: matchCount, pageCount: Math.max(1, Math.ceil(parseInt(matchCount, 10) / 10))});
|
||||||
}
|
}
|
||||||
], callback);
|
], callback);
|
||||||
});
|
});
|
||||||
@@ -423,25 +415,6 @@ function getSearchUids(data, callback) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function searchInUsers(data, callback) {
|
|
||||||
user.search(data, function(err, results) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
callback(null, {matches: results.users, matchCount: results.matchCount, pageCount: results.pageCount});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function searchInTags(query, callback) {
|
|
||||||
topics.searchAndLoadTags({query: query}, function(err, tags) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(null, {matches: tags, matchCount: tags.length, pageCount: 1});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
search.searchQuery = function(index, content, cids, uids, callback) {
|
search.searchQuery = function(index, content, cids, uids, callback) {
|
||||||
plugins.fireHook('filter:search.query', {
|
plugins.fireHook('filter:search.query', {
|
||||||
index: index,
|
index: index,
|
||||||
|
|||||||
@@ -2,12 +2,12 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var async = require('async'),
|
var async = require('async'),
|
||||||
winston = require('winston'),
|
|
||||||
db = require('../database'),
|
db = require('../database'),
|
||||||
meta = require('../meta'),
|
meta = require('../meta'),
|
||||||
_ = require('underscore'),
|
_ = require('underscore'),
|
||||||
plugins = require('../plugins'),
|
plugins = require('../plugins');
|
||||||
utils = require('../../public/src/utils');
|
|
||||||
|
|
||||||
module.exports = function(Topics) {
|
module.exports = function(Topics) {
|
||||||
|
|
||||||
@@ -248,7 +248,7 @@ module.exports = function(Topics) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Topics.searchTags = function(data, callback) {
|
Topics.searchTags = function(data, callback) {
|
||||||
if (!data) {
|
if (!data || !data.query) {
|
||||||
return callback(null, []);
|
return callback(null, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,9 +256,7 @@ module.exports = function(Topics) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
return callback(null, []);
|
return callback(null, []);
|
||||||
}
|
}
|
||||||
if (data.query === '') {
|
|
||||||
return callback(null, tags);
|
|
||||||
}
|
|
||||||
data.query = data.query.toLowerCase();
|
data.query = data.query.toLowerCase();
|
||||||
|
|
||||||
var matches = [];
|
var matches = [];
|
||||||
@@ -279,8 +277,14 @@ module.exports = function(Topics) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Topics.searchAndLoadTags = function(data, callback) {
|
Topics.searchAndLoadTags = function(data, callback) {
|
||||||
|
var searchResult = {
|
||||||
|
tags: [],
|
||||||
|
matchCount: 0,
|
||||||
|
pageCount: 1
|
||||||
|
};
|
||||||
|
|
||||||
if (!data.query || !data.query.length) {
|
if (!data.query || !data.query.length) {
|
||||||
return callback(null, []);
|
return callback(null, searchResult);
|
||||||
}
|
}
|
||||||
Topics.searchTags(data, function(err, tags) {
|
Topics.searchTags(data, function(err, tags) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -307,8 +311,10 @@ module.exports = function(Topics) {
|
|||||||
results.tagData.sort(function(a, b) {
|
results.tagData.sort(function(a, b) {
|
||||||
return b.score - a.score;
|
return b.score - a.score;
|
||||||
});
|
});
|
||||||
|
searchResult.tags = results.tagData;
|
||||||
callback(null, results.tagData);
|
searchResult.matchCount = results.tagData.length;
|
||||||
|
searchResult.pageCount = 1;
|
||||||
|
callback(null, searchResult);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user