Add Indexes to Schema API (#4240)
* 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
This commit is contained in:
committed by
Florent Vilmart
parent
6a1510729a
commit
4bccf96ae7
@@ -31,7 +31,8 @@ const fullTextHelper = () => {
|
||||
const request = {
|
||||
method: "POST",
|
||||
body: {
|
||||
subject: subjects[i]
|
||||
subject: subjects[i],
|
||||
comment: subjects[i],
|
||||
},
|
||||
path: "/1/classes/TestObject"
|
||||
};
|
||||
@@ -280,42 +281,18 @@ 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"
|
||||
}
|
||||
]
|
||||
},
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'test'
|
||||
}
|
||||
});
|
||||
}).then(() => {
|
||||
return databaseAdapter.createIndex('TestObject', {random: 'text'});
|
||||
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: {
|
||||
@@ -334,12 +311,91 @@ 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.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.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: {
|
||||
$search: {
|
||||
$term: 'coffee'
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
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.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) => {
|
||||
|
||||
Reference in New Issue
Block a user