null+****@clear*****
null+****@clear*****
2012年 7月 27日 (金) 14:59:05 JST
Kouhei Sutou 2012-07-27 14:59:05 +0900 (Fri, 27 Jul 2012) New Revision: 53ff4dc4852cfbc77c30e4242f250b8a3e35be03 https://github.com/groonga/gcs/commit/53ff4dc4852cfbc77c30e4242f250b8a3e35be03 Log: BqTranslator: support string value only expression Modified files: lib/bq-translator.js test/bq-translator.test.js Modified: lib/bq-translator.js (+21 -0) =================================================================== --- lib/bq-translator.js 2012-07-27 14:50:55 +0900 (ec2336b) +++ lib/bq-translator.js 2012-07-27 14:59:05 +0900 (4997227) @@ -17,6 +17,27 @@ BooleanQueryTranslator.prototype = { translate: function(query) { return this.translateTinia(query); }, + translateExpression: function(query, context) { + var value = ""; + var is_string_literal = (query[context.offset] == "'"); + if (is_string_literal) { + context.offset++; + for (; context.offset < query.length; context.offset++) { + var character = query[context.offset]; + if (character == "'") { + context.offset++; + break; + } + + if (character == "\\") { + context.offset++; + character = query[context.offset]; + } + value += character; + } + } + return value; + }, translateTinia: function(query) { var matched = null; Modified: test/bq-translator.test.js (+15 -0) =================================================================== --- test/bq-translator.test.js 2012-07-27 14:50:55 +0900 (6d1e66a) +++ test/bq-translator.test.js 2012-07-27 14:59:05 +0900 (352c868) @@ -12,6 +12,17 @@ function testQuery(label, expected, query) { }); } +function testExpression(label, expected, expression) { + test('expression: ' + label + ': ' + + '<' + expression + '> -> <' + expected + '>', function() { + var translator = new BooleanQueryTranslator(); + var context = { + offset: 0 + }; + assert.equal(expected, translator.translateExpression(expression, context)); + }); +} + suite('BoolanQueryTranslator', function() { testQuery("expression", 'type:"ModelName"', @@ -22,4 +33,8 @@ suite('BoolanQueryTranslator', function() { testQuery("group: quoted expression", '"query query" type:"ModelName"', "(and 'query query' type:'ModelName')"); + + testExpression("value only: stirng", + "keyword1 keyword2", + "'keyword1 keyword2'"); }) -------------- next part -------------- HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B... Download