[Groonga-commit] groonga/gcs [master] Report error for mismatched type index field options

Back to archive index

YUKI Hiroshi null+****@clear*****
Wed Nov 21 19:10:25 JST 2012


YUKI Hiroshi	2012-11-21 19:10:25 +0900 (Wed, 21 Nov 2012)

  New Revision: acdef018866e1da501c73444d5b756671d036a14
  https://github.com/groonga/gcs/commit/acdef018866e1da501c73444d5b756671d036a14

  Log:
    Report error for mismatched type index field options

  Modified files:
    lib/api/2011-02-01/configuration.js

  Modified: lib/api/2011-02-01/configuration.js (+22 -1)
===================================================================
--- lib/api/2011-02-01/configuration.js    2012-11-21 19:00:15 +0900 (cf5e6f1)
+++ lib/api/2011-02-01/configuration.js    2012-11-21 19:10:25 +0900 (d838816)
@@ -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);
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index