[Groonga-commit] groonga/gcs [master] Move "getIndexFieldsSync" from Database to Domain (because they are referenced circularly)

Back to archive index

null+****@clear***** null+****@clear*****
2012年 7月 11日 (水) 19:09:28 JST


SHIMODA Hiroshi	2012-07-11 19:09:28 +0900 (Wed, 11 Jul 2012)

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

  Log:
    Move "getIndexFieldsSync" from Database to Domain (because they are referenced circularly)

  Modified files:
    lib/api/2011-02-01/search.js
    lib/batch/processor.js
    lib/database.js
    lib/domain.js

  Modified: lib/api/2011-02-01/search.js (+1 -1)
===================================================================
--- lib/api/2011-02-01/search.js    2012-07-11 19:05:08 +0900 (ca53882)
+++ lib/api/2011-02-01/search.js    2012-07-11 19:09:28 +0900 (9514317)
@@ -37,7 +37,7 @@ exports.createHandler = function(database) {
     var startedAt = new Date();
     var domain = new Domain(request);
     var query = request.query.q || '';
-    var matchIndexFields = database.indexFieldsSync(domain.name);
+    var matchIndexFields = domain.getIndexFieldsSync(database);
     matchIndexFields = matchIndexFields.filter(function(field) {
       return field.type == 'text';
     });

  Modified: lib/batch/processor.js (+1 -1)
===================================================================
--- lib/batch/processor.js    2012-07-11 19:05:08 +0900 (3a2a615)
+++ lib/batch/processor.js    2012-07-11 19:09:28 +0900 (972f1d4)
@@ -24,7 +24,7 @@ Processor.prototype = {
     if (this._indexFields) {
       return self._indexFields;
     } else {
-      var fields = this.database.indexFieldsSync(this.domain.name);
+      var fields = this.domain.getIndexFieldsSync(this.database);
       return this._indexFields = fields;
     }
   },

  Modified: lib/database.js (+0 -33)
===================================================================
--- lib/database.js    2012-07-11 19:05:08 +0900 (bcfed53)
+++ lib/database.js    2012-07-11 19:09:28 +0900 (aac4848)
@@ -2,7 +2,6 @@ var nroonga = require('nroonga');
 var Deferred = require('jsdeferred').Deferred;
 var path = require('path');
 var mkdirp = require('mkdirp');
-var Domain = require('./domain').Domain;
 
 var ShortText =
       exports.ShortText =
@@ -102,38 +101,6 @@ Database.prototype = {
       return column.name.charAt(0) !== '_';
     });
     return ordinalColumns;
-  },
-  indexFieldsSync: function(domainName) {
-    var tableName = (new Domain(domainName)).tableName;
-    var columns = this.ordinalColumnsSync(tableName);
-    var fields = columns.map(this.columnToIndexField);
-    return fields;
-  },
-  columnToIndexField: function(column) {
-    // XXX The "name" must be the field name given by the user,
-    // not normalized. Because there is no such information in the
-    // database and currently the column name is luckly equals to the
-    // given field name, we can use the column name.
-    var name = column.name;
-
-    var type;
-    if (column.type == 'var') {
-      if (column.range == ShortText)
-        type = 'text';
-    } else if (column.type == 'fix') {
-      if (column.range == UInt32)
-        type = 'uint';
-      else if (column.range == ShortText)
-        type = 'literal';
-    }
-    if (!type)
-      throw new Error('unknown unfixed column '+column.name);
-
-    return {
-      name: name,
-      columnName: column.name,
-      type: type
-    };
   }
 };
 

  Modified: lib/domain.js (+32 -0)
===================================================================
--- lib/domain.js    2012-07-11 19:05:08 +0900 (c778ed6)
+++ lib/domain.js    2012-07-11 19:09:28 +0900 (706d246)
@@ -74,6 +74,38 @@ Domain.prototype = {
     return this.indexFields[field] ||
            (this.indexFields[field] = new IndexField(field, this));
   },
+  getIndexFieldsSync: function(database) {
+    var tableName = ;
+    var columns = database.ordinalColumnsSync(this.tableName);
+    var fields = columns.map(this.columnToIndexField);
+    return fields;
+  },
+  columnToIndexField: function(column) {
+    // XXX The "name" must be the field name given by the user,
+    // not normalized. Because there is no such information in the
+    // database and currently the column name is luckly equals to the
+    // given field name, we can use the column name.
+    var name = column.name;
+
+    var type;
+    if (column.type == 'var') {
+      if (column.range == Database.ShortText)
+        type = 'text';
+    } else if (column.type == 'fix') {
+      if (column.range == Database.UInt32)
+        type = 'uint';
+      else if (column.range == Database.ShortText)
+        type = 'literal';
+    }
+    if (!type)
+      throw new Error('unknown unfixed column '+column.name);
+
+    return {
+      name: name,
+      columnName: column.name,
+      type: type
+    };
+  },
   get synonymTableName() {
     if (!this._synonymTableName)
       this._synonymTableName = this.tableName + '_synonyms';
-------------- next part --------------
HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B...
下载 



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