more search cleanup

v1.18.x
barisusakli 9 years ago
parent c8fb68c2d5
commit 9ac4704848

@ -1,5 +1,5 @@
"use strict";
/*global define, socket, app, admin, utils, bootbox, RELATIVE_PATH*/
/*global define, socket, app, utils, bootbox*/
define('admin/manage/tags', [
'forum/infinitescroll',
@ -25,12 +25,12 @@ define('admin/manage/tags', [
}
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) {
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);
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
timeoutId = 0;
@ -43,7 +43,7 @@ define('admin/manage/tags', [
}
function handleModify() {
$('#modify').on('click', function(ev) {
$('#modify').on('click', function() {
var tagsToModify = $('.tag-row.selected');
if (!tagsToModify.length) {
return;

@ -24,7 +24,7 @@ define('forum/tags', ['forum/infinitescroll'], function(infinitescroll) {
if (err) {
return app.alertError(err.message);
}
onTagsLoaded(results, true, function() {
onTagsLoaded(results.tags, true, function() {
timeoutId = 0;
});
});

@ -22,15 +22,13 @@ search.search = function(data, callback) {
return callback(err);
}
result.search_query = validator.escape(query);
data.search_query = validator.escape(query);
if (searchIn === 'titles' || searchIn === 'titlesposts') {
searchIn = 'posts';
}
result[searchIn] = data.matches;
result.matchCount = data.matchCount;
result.pageCount = data.pageCount;
result.time = (process.elapsedTimeSince(start) / 1000).toFixed(2);
callback(null, result);
data.time = (process.elapsedTimeSince(start) / 1000).toFixed(2);
callback(null, data);
}
var start = process.hrtime();
@ -38,18 +36,12 @@ search.search = function(data, callback) {
var query = data.query;
var searchIn = data.searchIn || 'titlesposts';
var result = {
posts: [],
users: [],
tags: []
};
if (searchIn === 'posts' || searchIn === 'titles' || searchIn === 'titlesposts') {
searchInContent(data, done);
} else if (searchIn === 'users') {
searchInUsers(data, done);
user.search(data, done);
} else if (searchIn === 'tags') {
searchInTags(query, done);
topics.searchAndLoadTags(data, done);
} else {
callback(new Error('[[error:unknown-search-filter]]'));
}
@ -91,7 +83,7 @@ function searchInContent(data, callback) {
var matchCount = 0;
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([
@ -118,7 +110,7 @@ function searchInContent(data, callback) {
posts.getPostSummaryByPids(pids, data.uid, {}, 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);
});
@ -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) {
plugins.fireHook('filter:search.query', {
index: index,

@ -2,12 +2,12 @@
'use strict';
var async = require('async'),
winston = require('winston'),
db = require('../database'),
meta = require('../meta'),
_ = require('underscore'),
plugins = require('../plugins'),
utils = require('../../public/src/utils');
plugins = require('../plugins');
module.exports = function(Topics) {
@ -248,7 +248,7 @@ module.exports = function(Topics) {
};
Topics.searchTags = function(data, callback) {
if (!data) {
if (!data || !data.query) {
return callback(null, []);
}
@ -256,9 +256,7 @@ module.exports = function(Topics) {
if (err) {
return callback(null, []);
}
if (data.query === '') {
return callback(null, tags);
}
data.query = data.query.toLowerCase();
var matches = [];
@ -279,8 +277,14 @@ module.exports = function(Topics) {
};
Topics.searchAndLoadTags = function(data, callback) {
var searchResult = {
tags: [],
matchCount: 0,
pageCount: 1
};
if (!data.query || !data.query.length) {
return callback(null, []);
return callback(null, searchResult);
}
Topics.searchTags(data, function(err, tags) {
if (err) {
@ -307,8 +311,10 @@ module.exports = function(Topics) {
results.tagData.sort(function(a, b) {
return b.score - a.score;
});
callback(null, results.tagData);
searchResult.tags = results.tagData;
searchResult.matchCount = results.tagData.length;
searchResult.pageCount = 1;
callback(null, searchResult);
});
});
};

Loading…
Cancel
Save