null+****@clear*****
null+****@clear*****
2012年 8月 9日 (木) 12:25:28 JST
SHIMODA Hiroshi 2012-08-09 12:25:28 +0900 (Thu, 09 Aug 2012) New Revision: 39212b6afb1959f8bdf6c691793aab9df95483fb https://github.com/groonga/gcs/commit/39212b6afb1959f8bdf6c691793aab9df95483fb Log: Add Domain#getSynonymsSync() Modified files: lib/database/domain.js test/database-domain.test.js Modified: lib/database/domain.js (+26 -1) =================================================================== --- lib/database/domain.js 2012-08-08 18:43:28 +0900 (c1994ee) +++ lib/database/domain.js 2012-08-09 12:25:28 +0900 (666dedf) @@ -22,6 +22,10 @@ var INDEX_SUFFIX = exports.INDEX_SUFFIX = Domain.INDEX_SUFFIX = 'index'; +var SYNONYMS_COLUMN = + exports.SYNONYMS_COLUMN = + Domain.SYNONYMS_COKUMN = 'synonyms' + function assertValidDomainName(domain) { if (typeof domain != 'string') throw new Error('domain name must be a string'); @@ -248,9 +252,30 @@ Domain.prototype = { }); }, + getSynonymsSync: function() { + if (!this.context) + throw new Error('no context'); + + var options = { + table: this.synonymTableName, + match_columns: '_key,' + SYNONYMS_COLUMN + }; + var synonyms = this.context.commandSync('select', options); + + synonyms = nroonga.formatResults(synonyms); + Object.keys(synonyms).sort().forEach(function(key) { + var terms = synonyms[key]; + terms = JSON.parse(terms); + synonyms[key] = terms.sort(); + }); + + return synonyms; + }, + updateSynonymsSync: function(synonymOptions) { if (!this.context) throw new Error('no context'); + var synonyms = synonymOptions.synonyms; try { @@ -269,7 +294,7 @@ Domain.prototype = { }); this.context.commandSync('column_create', { table: this.synonymTableName, - name: 'synonyms', + name: SYNONYMS_COLUMN, type: nroonga.ShortText, flags: nroonga.COLUMN_VECTOR }); Modified: test/database-domain.test.js (+17 -0) =================================================================== --- test/database-domain.test.js 2012-08-08 18:43:28 +0900 (e1668e5) +++ test/database-domain.test.js 2012-08-09 12:25:28 +0900 (7f2d002) @@ -331,6 +331,23 @@ suite('database', function() { assert.equal(dumpExpected, dumpActual); }); + test('getSynonymsSync', function() { + var domain = new Domain('companies', context); + domain.updateSynonymsSync({ + synonyms: { + tokio: ['tonkin', 'tokyo'], + dekkaido: 'hokkaido' + } + }); + + var expectedSynonyms = { + dekkaido: ['hokkaido'], + tokio: ['tokyo', 'tonkin'] + }; + var synonyms = domain.getSynonymsSync(); + assert.deepEqual(synonyms, expectedSynonyms); + }); + test('getAll', function() { var domain3 = new Domain('domain3', context); domain3.createSync(); -------------- next part -------------- HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B... 下載