[Groonga-commit] groonga/gcs [master] Raise "ResourceNotFound" error for invalid index field options

アーカイブの一覧に戻る

YUKI Hiroshi null+****@clear*****
Fri Nov 16 17:16:45 JST 2012


YUKI Hiroshi	2012-11-16 17:16:45 +0900 (Fri, 16 Nov 2012)

  New Revision: 50eca83109eedfe77c2374ea86bf59cfadefa0a2
  https://github.com/groonga/gcs/commit/50eca83109eedfe77c2374ea86bf59cfadefa0a2

  Log:
    Raise "ResourceNotFound" error for invalid index field options

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

  Modified: lib/api/2011-02-01/configuration.js (+31 -0)
===================================================================
--- lib/api/2011-02-01/configuration.js    2012-11-16 16:57:59 +0900 (2a0573e)
+++ lib/api/2011-02-01/configuration.js    2012-11-16 17:16:45 +0900 (a73dd13)
@@ -281,6 +281,35 @@ function createIndexFieldStatus(options) {
   return indexFieldStatus;
 }
 
+var TEXT_TYPE_FIELD_OPTIONS = [
+      'IndexField.TextOptions.DefaultValue',
+      'IndexField.TextOptions.FacetEnabled',
+      'IndexField.TextOptions.ResultEnabled'
+    ];
+var LITERAL_TYPE_FIELD_OPTIONS = [
+      'IndexField.LiteralOptions.DefaultValue',
+      'IndexField.LiteralOptions.FacetEnabled',
+      'IndexField.LiteralOptions.ResultEnabled',
+      'IndexField.LiteralOptions.SearchEnabled'
+    ];
+var UINT_TYPE_FIELD_OPTIONS = [
+      'IndexField.LiteralOptions.DefaultValue'
+    ];
+
+function assertValidFieldOptions(request, type, domainName) {
+  var validOptions = type == 'text' ? TEXT_TYPE_FIELD_OPTIONS :
+                     type == 'literal' ? LITERAL_TYPE_FIELD_OPTIONS :
+                     UINT_TYPE_FIELD_OPTIONS;
+  
+  var options = Object.keys(request.query).filter(function(name) {
+        return /^IndexField\.[^\.]+Options\./.test(name);
+      });
+  if (options.some(function(name) {
+        return validOptions.indexOf(name) < 0;
+      }))
+    throw new errors.NotFoundError('Domain not found: ' + domainName);
+}
+
 function getFieldOption(option, request, type) {
   if (type == 'text')
     return request.query['IndexField.TextOptions.' + option];
@@ -307,6 +336,8 @@ handlers.DefineIndexField = function(context, request, response, config) {
         return field;
       });
 
+  assertValidFieldOptions(request, fieldType, domainName);
+
   var facetEnabled = getFieldOption('FacetEnabled', request, fieldType);
   if (facetEnabled !== undefined)
     field.facetEnabled = facetEnabled.toLowerCase() == 'true';
-------------- next part --------------
HTML����������������������������...
ダウンロード 



More information about the Groonga-commit mailing list
アーカイブの一覧に戻る