null+****@clear*****
null+****@clear*****
2012年 7月 6日 (金) 17:10:35 JST
SHIMODA Hiroshi 2012-07-06 17:10:35 +0900 (Fri, 06 Jul 2012) New Revision: 820cfbada121010a08b300813b1592bf6f6aa666 https://github.com/groonga/gcs/commit/820cfbada121010a08b300813b1592bf6f6aa666 Log: Implement IndexDocuments action Modified files: lib/api/2011-02-01/configuration.js test/api-configuration.test.js Modified: lib/api/2011-02-01/configuration.js (+52 -0) =================================================================== --- lib/api/2011-02-01/configuration.js 2012-07-06 16:27:59 +0900 (450b845) +++ lib/api/2011-02-01/configuration.js 2012-07-06 17:10:35 +0900 (4f5237b) @@ -258,6 +258,58 @@ handlers.DeleteIndexField = function(database, request, response) { } }; +function createIndexDocumentsResponse(options) { + return '<?xml version="1.0"?>\n' + + '<IndexDocumentsResponse xmlns="' + XMLNS + '">' + + '<IndexDocumentsResult>' + + '<FieldNames>' + + options.fieldNames.map(function(fieldName) { + return '<member>' + fieldName + '</member>'; + }).join('') + + '</FieldNames>' + + '</IndexDocumentsResult>' + + '<ResponseMetadata>' + + '<RequestId>' + (options.requestId || '') + '</RequestId>' + + '</ResponseMetadata>' + + '</IndexDocumentsResponse>'; +} + +handlers.IndexDocuments = function(database, request, response) { + var domain = new Domain(request); + var indexColumns = database.columnListSync(domain.termsTableName); + indexColumns = indexColumns.filter(function(column) { + return column.flags.indexOf(Database.COLUMN_INDEX) > -1; + }); + try { + indexColumns.forEach(function(column) { + database.commandSync('column_remove', { + table: domain.termsTableName, + name: column.name + }); + database.commandSync('column_create', { + table: domain.termsTableName, + name: column.name, + flags: column.flags, + type: column.type, + source: column.source + }); + }); + response.contentType('application/xml'); + response.send(createIndexDocumentsResponse({ + // FieldNames must be field names, not column names. + // However, original field names are completely lost after + // they are created via the API... + fieldNames: indexColumns.map(function(column) { + return column.source; + }) + })); + } catch(error) { + var body = createCommonErrorResponse('InternalFailure', error.message); + response.contentType('application/xml'); + response.send(body, 400); + } +}; + exports.createHandler = function(database) { return function(request, response, next) { var message, body; Modified: test/api-configuration.test.js (+53 -0) =================================================================== --- test/api-configuration.test.js 2012-07-06 16:27:59 +0900 (c0dfa66) +++ test/api-configuration.test.js 2012-07-06 17:10:35 +0900 (bcd405e) @@ -258,6 +258,59 @@ suite('Configuration API', function() { }); }); + test('Get, Action=IndexDocuments', 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&' + + 'Action=IndexDocuments&Version=2011-02-01'; + return utils.get(path); + }) + .next(function(response) { + var expected = { + statusCode: 200, + body: '<?xml version="1.0"?>\n' + + '<IndexDocumentsResponse xmlns="' + XMLNS + '">' + + '<IndexDocumentsResult>' + + '<member>name</member>' + + '</IndexDocumentsResult>' + + '<ResponseMetadata>' + + '<RequestId></RequestId>' + + '</ResponseMetadata>' + + '</IndexDocumentsResponse>' + }; + var actual = { + statusCode: response.statusCode, + body: response.body + }; + assert.deepEqual(actual, expected); + + var dump = database.commandSync('dump', { + tables: 'companies' + }); + var expected = 'table_create companies TABLE_HASH_KEY ShortText\n' + + 'column_create companies name COLUMN_SCALAR ShortText\n' + + 'table_create companies_BigramTerms ' + + 'TABLE_PAT_KEY|KEY_NORMALIZE ShortText ' + + '--default_tokenizer TokenBigram\n' + + 'column_create companies_BigramTerms companies_name ' + + 'COLUMN_INDEX|WITH_POSITION companies name'; + 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...Download