null+****@clear*****
null+****@clear*****
2012年 7月 6日 (金) 15:24:15 JST
SHIMODA Hiroshi 2012-07-06 15:24:15 +0900 (Fri, 06 Jul 2012) New Revision: ad2b5eb74fc152c74e3d283167d64858410a9166 https://github.com/groonga/gcs/commit/ad2b5eb74fc152c74e3d283167d64858410a9166 Log: Implement DeleteIndexField action Modified files: lib/api/2011-02-01/configuration.js test/api-configuration.test.js Modified: lib/api/2011-02-01/configuration.js (+39 -0) =================================================================== --- lib/api/2011-02-01/configuration.js 2012-07-06 14:56:09 +0900 (c41f9cc) +++ lib/api/2011-02-01/configuration.js 2012-07-06 15:24:15 +0900 (62671a8) @@ -233,6 +233,45 @@ handlers.DefineIndexField = function(database, request, response) { }); }; +function createDeleteIndexFieldResponse(options) { + return '<?xml version="1.0"?>\n' + + '<DefineIndexFieldResponse xmlns="' + XMLNS + '">' + + '<DefineIndexFieldResult/>' + + '<ResponseMetadata>' + + '<RequestId>' + (options.requestId || '') + '</RequestId>' + + '</ResponseMetadata>' + + '</DefineIndexFieldResponse>'; +} + +handlers.DeleteIndexField = function(database, request, response) { + var domain = new Domain(request); + + var fieldName = request.query['IndexFieldName'] || ''; + var field = domain.getIndexField(fieldName); + + var options = { + table: domain.tableName, + name: field.columnName + }; + database.commandDeferred('column_remove', options) + .next(function(data) { + var termsOptions = { + table: domain.termsTableName, + name: field.indexColumnName + }; + return database.commandDeferred('column_remove', termsOptions); + }) + .next(function() { + response.contentType('application/xml'); + response.send(createDeleteIndexFieldResponse()); + }) + .error(function(error) { + var body = createCommonErrorResponse('InternalFailure', error.message); + response.contentType('application/xml'); + return response.send(body, 400); + }); +}; + exports.createHandler = function(database) { return function(request, response, next) { var message, body; Modified: test/api-configuration.test.js (+48 -0) =================================================================== --- test/api-configuration.test.js 2012-07-06 14:56:09 +0900 (5f843b9) +++ test/api-configuration.test.js 2012-07-06 15:24:15 +0900 (b0b15e6) @@ -210,6 +210,54 @@ suite('Configuration API', function() { }); }); + test('Get, Action=DeleteIndexField', function(done) { + var path = '/?DomainName=companies&Action=CreateDomain&Version=2011-02-01'; + utils.get(path, { + 'Host': 'cloudsearch.localhost' + }) + .next(function(response) { + var path = '/?DomainName=companies&IndexField.IndexFieldName=name&' + + 'Action=DefineIndexField&Version=2011-02-01'; + return utils.get(path); + }) + .next(function(response) { + var path = '/?DomainName=companies&IndexFieldName=name&' + + 'Action=DeleteIndexField&Version=2011-02-01'; + return utils.get(path); + }) + .next(function(response) { + var expected = { + statusCode: 200, + body: '<?xml version="1.0"?>\n' + + '<DeleteIndexFieldResponse xmlns="' + XMLNS + '">' + + '<DeleteIndexFieldResult/>' + + '<ResponseMetadata>' + + '<RequestId></RequestId>' + + '</ResponseMetadata>' + + '</DeleteIndexFieldResponse>' + }; + var actual = { + statusCode: response.statusCode, + body: response.body + }; + assert.deepEqual(actual, expected); + + var dump = database.commandSync('dump', { + tables: 'companies' + }); + var expected = 'table_create companies_BigramTerms ' + + 'TABLE_PAT_KEY|KEY_NORMALIZE ShortText ' + + '--default_tokenizer TokenBigram\n' + + 'table_create companies TABLE_HASH_KEY ShortText'; + assert.equal(dump, expected); + + done(); + }) + .error(function(error) { + done(error); + }); + }); + test('Get, no version', function(done) { var path = '/?Action=unknown'; utils.get(path, { -------------- next part -------------- HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B... 下载