[Groonga-commit] groonga/gcs [master] Support search domain names specified by the path

Back to archive index

null+****@clear***** null+****@clear*****
2012年 7月 12日 (木) 13:11:04 JST


SHIMODA Hiroshi	2012-07-12 13:11:04 +0900 (Thu, 12 Jul 2012)

  New Revision: 16624c6bbcbc188691e26934fcdfe30d56e10331
  https://github.com/groonga/gcs/commit/16624c6bbcbc188691e26934fcdfe30d56e10331

  Log:
    Support search domain names specified by the path

  Modified files:
    lib/api/2011-02-01/bootstrap.js
    lib/domain.js
    test/domain.test.js

  Modified: lib/api/2011-02-01/bootstrap.js (+6 -0)
===================================================================
--- lib/api/2011-02-01/bootstrap.js    2012-07-12 11:33:36 +0900 (1e4096b)
+++ lib/api/2011-02-01/bootstrap.js    2012-07-12 13:11:04 +0900 (645a532)
@@ -9,8 +9,14 @@ exports.search = require('./search');
 exports.registerHandlers = function(application, database) {
   application.get('/',
                   exports.configuration.createHandler(database));
+
   application.post('/' + exports.version + '/documents/batch',
                    exports.batch.createHandler(database));
+  application.get('/gcs/:domain/' + exports.version + '/documents/batch',
+                  exports.batch.createHandler(database));
+
   application.get('/' + exports.version + '/search',
                   exports.search.createHandler(database));
+  application.get('/gcs/:domain/' + exports.version + '/search',
+                  exports.search.createHandler(database));
 };

  Modified: lib/domain.js (+14 -0)
===================================================================
--- lib/domain.js    2012-07-12 11:33:36 +0900 (7cdb9c1)
+++ lib/domain.js    2012-07-12 13:11:04 +0900 (fd6b0d2)
@@ -56,6 +56,10 @@ Domain.prototype = {
         return domainNameFromHost;
     }
 
+    var domainNameFromPath = Domain.getNameFromPath(source.url);
+    if (domainNameFromPath)
+      return domainNameFromPath;
+
     throw new Error('no domain name');
   },
   get tableName() {
@@ -121,6 +125,16 @@ Domain.getNameFromHost = function(host) {
   return '';
 };
 
+Domain.getNameFromPath = function(path) {
+  var domainMatcher = /^\/gcs\/([^\/]+)\//;
+
+  var match = path.match(domainMatcher);
+  if (match)
+    return match[1];
+
+  return '';
+};
+
 
 exports.MINIMUM_FIELD_NAME_LENGTH = 3;
 exports.MAXIMUM_FIELD_NAME_LENGTH = 64;

  Modified: test/domain.test.js (+20 -0)
===================================================================
--- test/domain.test.js    2012-07-12 11:33:36 +0900 (7e1d596)
+++ test/domain.test.js    2012-07-12 13:11:04 +0900 (4b2c69e)
@@ -123,6 +123,26 @@ suite('domain', function() {
         assert.equal(name, '');
       });
     });
+
+    suite('getNameFromPath', function() {
+      test('valid, lower case and number', function() {
+        var path = '/gcs/test0123/';
+        var name = Domain.getNameFromPath(path);
+        assert.equal(name, 'test0123');
+      });
+
+      test('valid, lower case, hyphen and number', function() {
+        var path = '/gcs/test-0123/';
+        var name = Domain.getNameFromPath(path);
+        assert.equal(name, 'test-0123');
+      });
+
+      test('invalid', function() {
+        var path = '/gcs';
+        var name = Domain.getNameFromPath(path);
+        assert.equal(name, '');
+      });
+    });
   });
 
   suite('IndexField', function() {
-------------- next part --------------
HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B...
Download 



Groonga-commit メーリングリストの案内
Back to archive index