From acdef018866e1da501c73444d5b756671d036a14 Mon Sep 17 00:00:00 2001 From: YUKI Hiroshi Date: Wed, 21 Nov 2012 19:10:25 +0900 Subject: [PATCH] Report error for mismatched type index field options --- lib/api/2011-02-01/configuration.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/api/2011-02-01/configuration.js b/lib/api/2011-02-01/configuration.js index cf5e6f1..d838816 100644 --- a/lib/api/2011-02-01/configuration.js +++ b/lib/api/2011-02-01/configuration.js @@ -322,6 +322,25 @@ function getFieldOption(option, request, type) { return request.query[optionName]; } +function assertHaveNoMismatchedTypeOption(request, type) { + var textOptions = Object.keys(request.query).filter(function(name) { + return TEXT_FIELD_OPTIONS.indexOf(name) > -1; + }); + var literalOptions = Object.keys(request.query).filter(function(name) { + return LITERAL_FIELD_OPTIONS.indexOf(name) > -1; + }); + var uintOptions = Object.keys(request.query).filter(function(name) { + return UINT_FIELD_OPTIONS.indexOf(name) > -1; + }); + + if (type == 'text' && (literalOptions.length || uintOptions.length)) + throw new error.FieldOptionConflictError('A text IndexField may only specify textOptions'); + if (type == 'literal' && (textOptions.length || uintOptions.length)) + throw new error.FieldOptionConflictError('A literal IndexField may only specify literalOptions'); + if (type == 'uint' && (textOptions.length || literalOptions.length)) + throw new error.FieldOptionConflictError('A uint IndexField may only specify uintOptions'); +} + handlers.DefineIndexField = function(context, request, response, config) { var domainName = request.query.DomainName || ''; var domain = handleDomanValidationError(function() { @@ -333,7 +352,9 @@ handlers.DefineIndexField = function(context, request, response, config) { var fieldName = request.query['IndexField.IndexFieldName'] || ''; var fieldType = request.query['IndexField.IndexFieldType'] || ''; var field = handleIndexFieldValidationError(function() { - return domain.getIndexField(fieldName).setType(fieldType).validate(); + var field = domain.getIndexField(fieldName).setType(fieldType).validate(); + assertHaveNoMismatchedTypeOption(request, fieldType); + return field; }); var facetEnabled = getFieldOption('FacetEnabled', request, fieldType);