Skip to content

Commit

Permalink
Add Indexes to Schema API (#4240)
Browse files Browse the repository at this point in the history
* Add Indexes to Schema API

* error handling

* ci errors

* postgres support

* full text compound indexes

* pg clean up

* get indexes on startup

* test compound index on startup

* add default _id to index, full Text index on startup

* lint

* fix test
  • Loading branch information
dplewis authored and flovilmart committed Nov 25, 2017
1 parent 6a15107 commit 4bccf96
Show file tree
Hide file tree
Showing 10 changed files with 958 additions and 76 deletions.
8 changes: 7 additions & 1 deletion spec/MongoSchemaCollectionAdapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ describe('MongoSchemaCollection', () => {
"create":{"*":true},
"delete":{"*":true},
"addField":{"*":true},
},
"indexes": {
"name1":{"deviceToken":1}
}
},
"installationId":"string",
Expand Down Expand Up @@ -66,7 +69,10 @@ describe('MongoSchemaCollection', () => {
update: { '*': true },
delete: { '*': true },
addField: { '*': true },
}
},
indexes: {
name1: {deviceToken: 1}
},
});
done();
});
Expand Down
124 changes: 90 additions & 34 deletions spec/ParseQuery.FullTextSearch.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const fullTextHelper = () => {
const request = {
method: "POST",
body: {
subject: subjects[i]
subject: subjects[i],
comment: subjects[i],
},
path: "/1/classes/TestObject"
};
Expand Down Expand Up @@ -280,42 +281,83 @@ describe('Parse.Query Full Text Search testing', () => {
});

describe_only_db('mongo')('Parse.Query Full Text Search testing', () => {
it('fullTextSearch: $search, only one text index', (done) => {
return reconfigureServer({
appId: 'test',
restAPIKey: 'test',
publicServerURL: 'http://localhost:8378/1',
databaseAdapter: new MongoStorageAdapter({ uri: mongoURI })
it('fullTextSearch: does not create text index if compound index exist', (done) => {
fullTextHelper().then(() => {
return databaseAdapter.dropAllIndexes('TestObject');
}).then(() => {
return rp.post({
url: 'http://localhost:8378/1/batch',
body: {
requests: [
{
method: "POST",
body: {
subject: "coffee is java"
},
path: "/1/classes/TestObject"
},
{
method: "POST",
body: {
subject: "java is coffee"
},
path: "/1/classes/TestObject"
return databaseAdapter.getIndexes('TestObject');
}).then((indexes) => {
expect(indexes.length).toEqual(1);
return databaseAdapter.createIndex('TestObject', {subject: 'text', comment: 'text'});
}).then(() => {
return databaseAdapter.getIndexes('TestObject');
}).then((indexes) => {
expect(indexes.length).toEqual(2);
const where = {
subject: {
$text: {
$search: {
$term: 'coffee'
}
]
},
json: true,
}
}
};
return rp.post({
url: 'http://localhost:8378/1/classes/TestObject',
json: { where, '_method': 'GET' },
headers: {
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'test'
}
});
}).then((resp) => {
expect(resp.results.length).toEqual(3);
return databaseAdapter.getIndexes('TestObject');
}).then((indexes) => {
expect(indexes.length).toEqual(2);
rp.get({
url: 'http://localhost:8378/1/schemas/TestObject',
headers: {
'X-Parse-Application-Id': 'test',
'X-Parse-Master-Key': 'test',
},
json: true,
}, (error, response, body) => {
expect(body.indexes._id_).toBeDefined();
expect(body.indexes._id_._id).toEqual(1);
expect(body.indexes.subject_text_comment_text).toBeDefined();
expect(body.indexes.subject_text_comment_text.subject).toEqual('text');
expect(body.indexes.subject_text_comment_text.comment).toEqual('text');
done();
});
}).catch(done.fail);
});

it('fullTextSearch: does not create text index if schema compound index exist', (done) => {
fullTextHelper().then(() => {
return databaseAdapter.dropAllIndexes('TestObject');
}).then(() => {
return databaseAdapter.createIndex('TestObject', {random: 'text'});
return databaseAdapter.getIndexes('TestObject');
}).then((indexes) => {
expect(indexes.length).toEqual(1);
return rp.put({
url: 'http://localhost:8378/1/schemas/TestObject',
json: true,
headers: {
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'test',
'X-Parse-Master-Key': 'test',
},
body: {
indexes: {
text_test: { subject: 'text', comment: 'text'},
},
},
});
}).then(() => {
return databaseAdapter.getIndexes('TestObject');
}).then((indexes) => {
expect(indexes.length).toEqual(2);
const where = {
subject: {
$text: {
Expand All @@ -334,12 +376,26 @@ describe_only_db('mongo')('Parse.Query Full Text Search testing', () => {
}
});
}).then((resp) => {
fail(`Should not be more than one text index: ${JSON.stringify(resp)}`);
done();
}).catch((err) => {
expect(err.error.code).toEqual(Parse.Error.INTERNAL_SERVER_ERROR);
done();
});
expect(resp.results.length).toEqual(3);
return databaseAdapter.getIndexes('TestObject');
}).then((indexes) => {
expect(indexes.length).toEqual(2);
rp.get({
url: 'http://localhost:8378/1/schemas/TestObject',
headers: {
'X-Parse-Application-Id': 'test',
'X-Parse-Master-Key': 'test',
},
json: true,
}, (error, response, body) => {
expect(body.indexes._id_).toBeDefined();
expect(body.indexes._id_._id).toEqual(1);
expect(body.indexes.text_test).toBeDefined();
expect(body.indexes.text_test.subject).toEqual('text');
expect(body.indexes.text_test.comment).toEqual('text');
done();
});
}).catch(done.fail);
});

it('fullTextSearch: $diacriticSensitive - false', (done) => {
Expand Down
5 changes: 4 additions & 1 deletion spec/Schema.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ describe('SchemaController', () => {
fooSixteen: {type: 'String'},
fooEighteen: {type: 'String'},
fooNineteen: {type: 'String'},
}, levelPermissions, config.database))
}, levelPermissions, {}, config.database))
.then(actualSchema => {
const expectedSchema = {
className: 'NewClass',
Expand Down Expand Up @@ -304,6 +304,9 @@ describe('SchemaController', () => {
fooNineteen: {type: 'String'},
},
classLevelPermissions: { ...levelPermissions },
indexes: {
_id_: { _id: 1 }
}
};

expect(dd(actualSchema, expectedSchema)).toEqual(undefined);
Expand Down
Loading

0 comments on commit 4bccf96

Please sign in to comment.