Skip to content

Commit

Permalink
Report error for mismatched type index field options
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Nov 21, 2012
1 parent c135106 commit acdef01
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion lib/api/2011-02-01/configuration.js
Expand Up @@ -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() {
Expand All @@ -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);
Expand Down

0 comments on commit acdef01

Please sign in to comment.