[Groonga-commit] groonga/gcs [master] Convert batch to record by Domain itself

アーカイブの一覧に戻る

YUKI Hiroshi null+****@clear*****
Thu Dec 6 19:43:49 JST 2012


YUKI Hiroshi	2012-12-06 19:43:49 +0900 (Thu, 06 Dec 2012)

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

  Log:
    Convert batch to record by Domain itself

  Modified files:
    lib/batch/processor.js
    lib/database/domain.js
    test/database-domain.test.js

  Modified: lib/batch/processor.js (+2 -11)
===================================================================
--- lib/batch/processor.js    2012-12-06 19:27:31 +0900 (415c9f0)
+++ lib/batch/processor.js    2012-12-06 19:43:49 +0900 (8b47ced)
@@ -97,20 +97,11 @@ Processor.prototype = {
   loadOneBatchSync: function(batch, results) {
     switch (batch.type) {
       case 'add':
-        var record = { id: batch.id };
-        Object.keys(batch.fields).forEach(function(key) {
-          record[key] = batch.fields[key];
-          if (Array.isArray(batch.fields[key])) {
-            var field = this.domain.getIndexField(key);
-            if (!field.multipleValues)
-              field.upgradeToMultipleValuesSync();
-          }
-        }, this);
-        this.domain.addRecordSync(record);
+        this.domain.addDocumentSync(batch);
         results.adds++;
         break;
       case 'delete':
-        this.domain.deleteRecordSync(batch.id);
+        this.domain.deleteDocumentSync(batch.id);
         results.deletes++;
         break;
     }

  Modified: lib/database/domain.js (+24 -4)
===================================================================
--- lib/database/domain.js    2012-12-06 19:27:31 +0900 (bcf1e75)
+++ lib/database/domain.js    2012-12-06 19:43:49 +0900 (3df310d)
@@ -577,15 +577,35 @@ Domain.prototype = {
     return grnDumpRecord;
   },
 
-  addRecordSync: function(record) {
-    record = this.toGrnDumpRecord(record);
+  addDocumentSync: function(document) {
+    this.indexDocumentSync(document);
+    return this;
+  },
+  indexDocumentSync: function(document) {
+    var record = { id: document.id };
+    Object.keys(document.fields).forEach(function(key) {
+      record[key] = document.fields[key];
+      if (Array.isArray(document.fields[key])) {
+        var field = this.getIndexField(key);
+        if (!field.multipleValues)
+          field.upgradeToMultipleValuesSync();
+      }
+    }, this);
+
+    grnDumpRecord = this.toGrnDumpRecord(record);
     this.context.commandSync('load', {
       table: this.tableName,
-      values: JSON.stringify([record])
+      values: JSON.stringify([grnDumpRecord])
     });
+
+    return this;
   },
 
-  deleteRecordSync: function(id) {
+  deleteDocumentSync: function(id) {
+    this.deleteIndexedDocumentSync(id);
+    return this;
+  },
+  deleteIndexedDocumentSync: function(id) {
     this.context.commandSync('delete', {
       table: this.tableName,
       key: id

  Modified: test/database-domain.test.js (+16 -4)
===================================================================
--- test/database-domain.test.js    2012-12-06 19:27:31 +0900 (0e0a1e6)
+++ test/database-domain.test.js    2012-12-06 19:43:49 +0900 (fd520f7)
@@ -674,7 +674,20 @@ suite('database', function() {
         temporaryDatabase = undefined;
       });
 
-      test('addRecordSync', function() {
+      test('addDocumentSync', function() {
+        var document = {
+              id: 'id1',
+              fields: {
+                address: 'Shibuya, Tokyo, Japan',
+                age: 1,
+                description: '',
+                email_address: 'info �� razil.jp',
+                name: 'Brazil',
+                product: 'groonga'
+              }
+            };
+        domain.addDocumentSync(document);
+
         var record = {
               id: 'id1',
               address: 'Shibuya, Tokyo, Japan',
@@ -684,13 +697,12 @@ suite('database', function() {
               name: 'Brazil',
               product: 'groonga'
             };
-        domain.addRecordSync(record);
         assert.deepEqual(domain.dumpSync(), [record]);
       });
 
-      test('deleteRecordSync', function() {
+      test('deleteDocumentSync', function() {
         utils.loadDumpFile(context, __dirname + '/fixture/companies/data.grn');
-        domain.deleteRecordSync('id1');
+        domain.deleteDocumentSync('id1');
 
         var actualDump = domain.dumpSync();
         var found = actualDump.some(function(record) {
-------------- next part --------------
HTML����������������������������...
ダウンロード 



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