[Groonga-commit] groonga/gcs [master] getSynonymsSync sohould work even if there is no synonyms table

Zurück zum Archiv-Index

null+****@clear***** null+****@clear*****
2012年 8月 9日 (木) 16:29:55 JST


SHIMODA Hiroshi	2012-08-09 16:29:55 +0900 (Thu, 09 Aug 2012)

  New Revision: 6ade8e09bbf0def5efc76bf90e542298be626753
  https://github.com/groonga/gcs/commit/6ade8e09bbf0def5efc76bf90e542298be626753

  Log:
    getSynonymsSync sohould work even if there is no synonyms table

  Modified files:
    lib/database/domain.js

  Modified: lib/database/domain.js (+16 -12)
===================================================================
--- lib/database/domain.js    2012-08-09 16:13:52 +0900 (b7860e9)
+++ lib/database/domain.js    2012-08-09 16:29:55 +0900 (6a132b4)
@@ -256,6 +256,9 @@ Domain.prototype = {
     if (!this.context)
       throw new Error('no context');
 
+    if (!this.isSynonymsTableAvailableSync())
+      return {};
+
     var options = {
           table: this.synonymsTableName,
           limit: -1,
@@ -277,14 +280,23 @@ Domain.prototype = {
     if (!this.context)
       throw new Error('no context');
 
-    try {
+    this.setupBlankSynonymsTable();
+
+    var values = Object.keys(synonyms).map(function(key) {
+          return {_key: key, synonyms: synonyms[key]};
+        });
+    this.context.commandSync('load', {
+      table: this.synonymsTableName,
+      values: JSON.stringify(values)
+    });
+  },
+
+  setupBlankSynonymsTable: function() {
+    if (this.isSynonymsTableAvailableSync()) {
       this.context.commandSync('table_remove', {
         table: this.synonymsTableName
       });
-    } catch (error) {
-      // The synonym table should be inexistent. Do nothing.
     }
-
     this.context.commandSync('table_create', {
       name: this.synonymsTableName,
       flags: nroonga.TABLE_HASH_KEY,
@@ -297,14 +309,6 @@ Domain.prototype = {
       type: nroonga.ShortText,
       flags: nroonga.COLUMN_VECTOR
     });
-
-    var load = Object.keys(synonyms).map(function(key) {
-      return {_key: key, synonyms: synonyms[key]};
-    });
-    this.context.commandSync('load', {
-      table: this.synonymsTableName,
-      values: JSON.stringify(load)
-    });
   },
 
   isSynonymsTableAvailableSync: function() {
-------------- next part --------------
HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B...
Download 



Groonga-commit メーリングリストの案内
Zurück zum Archiv-Index