[Groonga-commit] groonga/gcs [master] Move codes to create index columns from configuration API to IndexField

Back to archive index

null+****@clear***** null+****@clear*****
2012年 7月 12日 (木) 18:57:56 JST


SHIMODA Hiroshi	2012-07-12 18:57:56 +0900 (Thu, 12 Jul 2012)

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

  Log:
    Move codes to create index columns from configuration API to IndexField

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

  Modified: lib/api/2011-02-01/configuration.js (+2 -24)
===================================================================
--- lib/api/2011-02-01/configuration.js    2012-07-12 18:52:04 +0900 (9f20503)
+++ lib/api/2011-02-01/configuration.js    2012-07-12 18:57:56 +0900 (6c128f7)
@@ -195,32 +195,10 @@ handlers.DefineIndexField = function(context, request, response) {
   var field = domain.getIndexField(fieldName);
 
   var createdAt = new Date();
-  var alterTableName = domain.termsTableName;
-  var columnType = field.fieldTypeToColumnType(fieldType);
   var resultEnabled = fieldType != 'literal'; 
   try {
-    if (fieldType == 'uint' || fieldType == 'literal') {
-      context.commandSync('table_create', {
-        name: field.alterTableName,
-        flags: nroonga.TABLE_HASH_KEY,
-        key_type: field.fieldTypeToAlterTableKeyType(fieldType)
-      });
-      alterTableName = field.alterTableName;
-    }
-    context.commandSync('column_create', {
-      table: domain.tableName,
-      name: field.columnName,
-      flags: nroonga.COLUMN_SCALAR,
-      type: columnType
-    });
-    context.commandSync('column_create', {
-      table: alterTableName,
-      name: field.indexColumnName,
-      flags: nroonga.INDEX_COLUMN_DEFAULT_FLAGS,
-      type: domain.tableName,
-      source: field.columnName
-    });
-
+    field.type = fieldType;
+    field.createSync();
     response.contentType('application/xml');
     response.send(createDefineIndexFieldResponse({
       fieldName: fieldName,

  Modified: lib/database/index-field.js (+30 -1)
===================================================================
--- lib/database/index-field.js    2012-07-12 18:52:04 +0900 (5231c69)
+++ lib/database/index-field.js    2012-07-12 18:57:56 +0900 (3fc8796)
@@ -121,7 +121,7 @@ IndexField.prototype = {
 
     var column = this.column;
     if (!column)
-      throw new Error('the column '+this.columnName+' is not created yet');
+      throw new Error('the index field ' + this.name + ' is not created yet');
 
     if (column.type == 'var') {
       if (column.range == nroonga.ShortText)
@@ -139,6 +139,35 @@ IndexField.prototype = {
     return this._type = type
   },
 
+  createSync: function() {
+    var alterTableName = this.domain.termsTableName;
+
+    var type = this.type;
+    var columnType = this.fieldTypeToColumnType(type);
+
+    if (type == 'uint' || type == 'literal') {
+      this.context.commandSync('table_create', {
+        name: this.alterTableName,
+        flags: nroonga.TABLE_HASH_KEY,
+        key_type: this.fieldTypeToAlterTableKeyType(type)
+      });
+      alterTableName = this.alterTableName;
+    }
+
+    this.context.commandSync('column_create', {
+      table: this.domain.tableName,
+      name: this.columnName,
+      flags: nroonga.COLUMN_SCALAR,
+      type: columnType
+    });
+    this.context.commandSync('column_create', {
+      table: alterTableName,
+      name: this.indexColumnName,
+      flags: nroonga.INDEX_COLUMN_DEFAULT_FLAGS,
+      type: this.domain.tableName,
+      source: this.columnName
+    });
+  },
   deleteSync: function() {
     var type = this.type;
     if (type == 'uint' || type == 'literal') {
-------------- next part --------------
HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B...
Download 



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