Skip to content

Commit 736a1cc

Browse files
committed
[star-rating] Use text index for comment and email
1 parent 900625d commit 736a1cc

File tree

2 files changed

+11
-24
lines changed

2 files changed

+11
-24
lines changed

plugins/star-rating/api/api.js

+10-19
Original file line numberDiff line numberDiff line change
@@ -1041,10 +1041,7 @@ function uploadFile(myfile, id, callback) {
10411041
query.device_id = params.qstring.device_id;
10421042
}
10431043
if (params.qstring.sSearch && params.qstring.sSearch !== "") {
1044-
query.$or = [
1045-
{ comment: {$regex: new RegExp(`.*${params.qstring.sSearch}.*`, 'i')} },
1046-
{ email: {$regex: new RegExp(`.*${params.qstring.sSearch}.*`, 'i')} },
1047-
];
1044+
query.$text = { $search: params.qstring.sSearch };
10481045
}
10491046
if (params.qstring.iSortCol_0) {
10501047
try {
@@ -1426,11 +1423,9 @@ function uploadFile(myfile, id, callback) {
14261423
common.db.collection('feedback' + appId).ensureIndex({
14271424
"ts": 1
14281425
}, function() {});
1429-
common.db.collection('feedback' + appId).ensureIndex(
1430-
{ '$**': 1 },
1431-
{ wildcardProjection: { comment: 1, email: 1 }, name: 'comment_*_email_*' },
1432-
() => {},
1433-
);
1426+
common.db.collection('feedback' + appId).ensureIndex({
1427+
comment: 'text', email: 'text'
1428+
}, () => {});
14341429
});
14351430
plugins.register("/i/apps/delete", function(ob) {
14361431
var appId = ob.appId;
@@ -1473,11 +1468,9 @@ function uploadFile(myfile, id, callback) {
14731468
common.db.collection('feedback' + appId).ensureIndex({
14741469
"ts": 1
14751470
}, function() {});
1476-
common.db.collection('feedback' + appId).ensureIndex(
1477-
{ '$**': 1 },
1478-
{ wildcardProjection: { comment: 1, email: 1 }, name: 'comment_*_email_*' },
1479-
() => {},
1480-
);
1471+
common.db.collection('feedback' + appId).ensureIndex({
1472+
comment: 'text', email: 'text'
1473+
}, () => {});
14811474
});
14821475
common.db.collection("events" + crypto.createHash('sha1').update("[CLY]_star_rating" + appId).digest('hex')).drop(function() {});
14831476
if (common.drillDb) {
@@ -1497,11 +1490,9 @@ function uploadFile(myfile, id, callback) {
14971490
common.db.collection('feedback' + appId).ensureIndex({
14981491
"ts": 1
14991492
}, function() {});
1500-
common.db.collection('feedback' + appId).ensureIndex(
1501-
{ '$**': 1 },
1502-
{ wildcardProjection: { comment: 1, email: 1 }, name: 'comment_*_email_*' },
1503-
() => {},
1504-
);
1493+
common.db.collection('feedback' + appId).ensureIndex({
1494+
comment: 'text', email: 'text'
1495+
}, () => {});
15051496
});
15061497
common.db.collection("events" + crypto.createHash('sha1').update("[CLY]_star_rating" + appId).digest('hex')).drop(function() {});
15071498
if (common.drillDb) {

plugins/star-rating/install.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ pluginManager.dbConnection().then((countlyDb) => {
2626
}
2727
countlyDb.collection('feedback' + app._id).ensureIndex({"uid": 1}, {background: true}, cb);
2828
countlyDb.collection('feedback' + app._id).ensureIndex({"ts": 1}, {background: true}, cb);
29-
countlyDb.collection('feedback' + app._id).ensureIndex(
30-
{ '$**': 1 },
31-
{ wildcardProjection: { comment: 1, email: 1 }, background: true, name: 'comment_*_email_*' },
32-
cb,
33-
);
29+
countlyDb.collection('feedback' + app._id).ensureIndex({comment: 'text', email: 'text'}, {background: true}, cb);
3430
}
3531
async.forEach(apps, upgrade, function() {
3632
console.log("Ratings plugin installation finished");

0 commit comments

Comments
 (0)