Navigation Menu

Skip to content

Commit

Permalink
getSynonymsSync sohould work even if there is no synonyms table
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Aug 9, 2012
1 parent ca4fb3c commit 6ade8e0
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions lib/database/domain.js
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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() {
Expand Down

0 comments on commit 6ade8e0

Please sign in to comment.