nodebb-plugin-dbsearch 5.0.3 → 5.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc +1 -137
- package/lib/dbsearch.js +530 -516
- package/lib/mongo.js +114 -115
- package/lib/postgres.js +111 -111
- package/lib/redis.js +52 -52
- package/package.json +5 -5
- package/plugin.json +2 -5
- package/public/.eslintrc +3 -0
- package/{lib → public}/admin.js +120 -124
- package/{public/templates → templates}/admin/plugins/dbsearch.tpl +0 -0
- package/upgrades/dbsearch_change_mongodb_schema.js +11 -32
package/{lib → public}/admin.js
RENAMED
|
@@ -1,124 +1,120 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return dbsearch;
|
|
124
|
-
});
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
define('admin/plugins/dbsearch', ['alerts'], function (alerts) {
|
|
4
|
+
var dbsearch = {};
|
|
5
|
+
var intervalId = 0;
|
|
6
|
+
|
|
7
|
+
$(window).on('action:ajaxify.end', function (ev, data) {
|
|
8
|
+
if (data.url === 'admin/plugins/dbsearch' && ajaxify.data.working) {
|
|
9
|
+
startProgress();
|
|
10
|
+
} else {
|
|
11
|
+
clearProgress();
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
dbsearch.init = function () {
|
|
16
|
+
$('#save').on('click', function () {
|
|
17
|
+
$.post(config.relative_path + '/api/admin/plugins/dbsearch/save', {
|
|
18
|
+
_csrf: $('#csrf_token').val(),
|
|
19
|
+
topicLimit: $('#topicLimit').val(),
|
|
20
|
+
postLimit: $('#postLimit').val(),
|
|
21
|
+
excludeCategories: $('#exclude-categories').val(),
|
|
22
|
+
}, function (data) {
|
|
23
|
+
if (typeof data === 'string') {
|
|
24
|
+
alerts.success('Settings saved');
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
return false;
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
$('#reindex').on('click', function () {
|
|
32
|
+
bootbox.confirm('Are you sure you want to reindex all content? This might take a while depending on the amount of content. During the operation the forum might slow down.', function (confirm) {
|
|
33
|
+
if (!confirm) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
socket.emit('admin.plugins.dbsearch.reindex', function (err) {
|
|
37
|
+
if (err) {
|
|
38
|
+
alerts.error(err);
|
|
39
|
+
return clearProgress();
|
|
40
|
+
}
|
|
41
|
+
alerts.success('Started indexing content! This might take a while. You can check the progress on this page.');
|
|
42
|
+
startProgress();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
return false;
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
$('#clear-index').on('click', function () {
|
|
50
|
+
bootbox.confirm('Are you sure you want to clear all indices? This might take a while depending on the amount of content. During the operation the forum might slow down.', function (confirm) {
|
|
51
|
+
if (!confirm) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
socket.emit('admin.plugins.dbsearch.clearIndex', function (err) {
|
|
55
|
+
if (err) {
|
|
56
|
+
alerts.error(err);
|
|
57
|
+
return clearProgress();
|
|
58
|
+
}
|
|
59
|
+
alerts.success('Started clearing index! This might take a while. You can check the progress on this page.');
|
|
60
|
+
startProgress();
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
return false;
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
$('#changeLanguage').on('click', function () {
|
|
67
|
+
var lang = $('#indexLanguage').val();
|
|
68
|
+
alerts.success('Changing index language to "' + lang + '".');
|
|
69
|
+
socket.emit('admin.plugins.dbsearch.changeLanguage', lang, function (err) {
|
|
70
|
+
if (err) {
|
|
71
|
+
return alerts.error(err);
|
|
72
|
+
}
|
|
73
|
+
alerts.success('Search index language changed!');
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
function startProgress() {
|
|
79
|
+
clearProgress();
|
|
80
|
+
intervalId = setInterval(checkProgress, 1000);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function clearProgress() {
|
|
84
|
+
if (intervalId) {
|
|
85
|
+
clearInterval(intervalId);
|
|
86
|
+
intervalId = 0;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function checkProgress() {
|
|
91
|
+
socket.emit('admin.plugins.dbsearch.checkProgress', function (err, progress) {
|
|
92
|
+
if (err) {
|
|
93
|
+
clearProgress();
|
|
94
|
+
return alerts.error(err);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
var working = parseInt(progress.working, 10);
|
|
98
|
+
if (!working) {
|
|
99
|
+
clearInterval(intervalId);
|
|
100
|
+
$('#reindex').removeAttr('disabled');
|
|
101
|
+
} else {
|
|
102
|
+
$('#reindex').attr('disabled', true);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
$('#work-in-progress').toggleClass('hidden', !working);
|
|
106
|
+
|
|
107
|
+
if (progress.topicsPercent >= 100 && progress.postsPercent >= 100) {
|
|
108
|
+
progress.topicsPercent = 100;
|
|
109
|
+
progress.postsPercent = 100;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
$('#topics-indexed').text(progress.topicsIndexed);
|
|
113
|
+
$('#posts-indexed').text(progress.postsIndexed);
|
|
114
|
+
$('.topic-progress').css('width', progress.topicsPercent + '%').text(progress.topicsPercent + '%');
|
|
115
|
+
$('.post-progress').css('width', progress.postsPercent + '%').text(progress.postsPercent + '%');
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return dbsearch;
|
|
120
|
+
});
|
|
File without changes
|
|
@@ -1,49 +1,28 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
const async = require.main.require('async');
|
|
5
4
|
const winston = require.main.require('winston');
|
|
6
5
|
const db = module.parent.require('./database');
|
|
7
6
|
|
|
8
7
|
module.exports = {
|
|
9
8
|
name: 'Changing dbsearch mongodb search schema to use _id',
|
|
10
9
|
timestamp: Date.UTC(2018, 10, 26),
|
|
11
|
-
method: function (
|
|
10
|
+
method: async function () {
|
|
12
11
|
const nconf = require.main.require('nconf');
|
|
13
12
|
const isMongo = nconf.get('database') === 'mongo';
|
|
14
13
|
if (!isMongo) {
|
|
15
|
-
return
|
|
14
|
+
return;
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
const plugin = require('../lib/dbsearch');
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
function (next) {
|
|
29
|
-
client.collection('searchtopic').dropIndex({ id: 1 }, function (err) {
|
|
30
|
-
if (err) {
|
|
31
|
-
winston.error(err);
|
|
32
|
-
}
|
|
33
|
-
next();
|
|
34
|
-
});
|
|
35
|
-
},
|
|
36
|
-
function (next) {
|
|
37
|
-
client.collection('searchpost').dropIndex({ id: 1 }, function (err) {
|
|
38
|
-
if (err) {
|
|
39
|
-
winston.error(err);
|
|
40
|
-
}
|
|
41
|
-
next();
|
|
42
|
-
});
|
|
43
|
-
},
|
|
44
|
-
async function () {
|
|
45
|
-
await plugin.reindex();
|
|
46
|
-
},
|
|
47
|
-
], callback);
|
|
18
|
+
await db.client.collection('searchtopic').deleteMany({});
|
|
19
|
+
await db.client.collection('searchpost').deleteMany({});
|
|
20
|
+
try {
|
|
21
|
+
await db.client.collection('searchtopic').dropIndex({ id: 1 });
|
|
22
|
+
await db.client.collection('searchpost').dropIndex({ id: 1 });
|
|
23
|
+
} catch (err) {
|
|
24
|
+
winston.error(err.stack);
|
|
25
|
+
}
|
|
26
|
+
await plugin.reindex();
|
|
48
27
|
},
|
|
49
28
|
};
|