Skip to content

Commit 2b7a774

Browse files
Merge pull request #5245 from Countly/feedback-index
[SER-1507] [star-rating] Add text index for comment and email
2 parents 7b88306 + 736a1cc commit 2b7a774

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

plugins/star-rating/api/api.js

+10-4
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,6 +1423,9 @@ function uploadFile(myfile, id, callback) {
14261423
common.db.collection('feedback' + appId).ensureIndex({
14271424
"ts": 1
14281425
}, function() {});
1426+
common.db.collection('feedback' + appId).ensureIndex({
1427+
comment: 'text', email: 'text'
1428+
}, () => {});
14291429
});
14301430
plugins.register("/i/apps/delete", function(ob) {
14311431
var appId = ob.appId;
@@ -1468,6 +1468,9 @@ function uploadFile(myfile, id, callback) {
14681468
common.db.collection('feedback' + appId).ensureIndex({
14691469
"ts": 1
14701470
}, function() {});
1471+
common.db.collection('feedback' + appId).ensureIndex({
1472+
comment: 'text', email: 'text'
1473+
}, () => {});
14711474
});
14721475
common.db.collection("events" + crypto.createHash('sha1').update("[CLY]_star_rating" + appId).digest('hex')).drop(function() {});
14731476
if (common.drillDb) {
@@ -1487,6 +1490,9 @@ function uploadFile(myfile, id, callback) {
14871490
common.db.collection('feedback' + appId).ensureIndex({
14881491
"ts": 1
14891492
}, function() {});
1493+
common.db.collection('feedback' + appId).ensureIndex({
1494+
comment: 'text', email: 'text'
1495+
}, () => {});
14901496
});
14911497
common.db.collection("events" + crypto.createHash('sha1').update("[CLY]_star_rating" + appId).digest('hex')).drop(function() {});
14921498
if (common.drillDb) {

plugins/star-rating/install.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ pluginManager.dbConnection().then((countlyDb) => {
2020
console.log("Adding ratings collections to " + app.name);
2121
function cb() {
2222
cnt++;
23-
if (cnt == 2) {
23+
if (cnt == 3) {
2424
done();
2525
}
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({comment: 'text', email: 'text'}, {background: true}, cb);
2930
}
3031
async.forEach(apps, upgrade, function() {
3132
console.log("Ratings plugin installation finished");

0 commit comments

Comments
 (0)