YUKI Hiroshi
null+****@clear*****
Thu Aug 23 14:12:00 JST 2012
YUKI Hiroshi 2012-08-23 14:12:00 +0900 (Thu, 23 Aug 2012) New Revision: 16f7ccb80f24e5c15605cf72d5e1401ad72601d1 https://github.com/groonga/gcs/commit/16f7ccb80f24e5c15605cf72d5e1401ad72601d1 Log: Use "==" operator to search literal fields Modified files: lib/bq-translator.js Modified: lib/bq-translator.js (+25 -6) =================================================================== --- lib/bq-translator.js 2012-08-23 12:55:33 +0900 (02d9e79) +++ lib/bq-translator.js 2012-08-23 14:12:00 +0900 (2e5e07b) @@ -13,6 +13,7 @@ * (not ...) */ +var IndexField = require('./database').IndexField; function BooleanQueryTranslator(query) { this.query = query; @@ -226,6 +227,7 @@ BooleanQueryTranslator.prototype = { this.offset++; var tokens = []; + var type = field ? this.getField(field).type : "text" ; var value = ""; var self = this; var addKeywordToken = function() { @@ -252,8 +254,12 @@ BooleanQueryTranslator.prototype = { } if (character == " " || character == "+") { - addKeywordToken(); - tokens.push("&&"); + if (type == "literal") { + value += character; + } else { + addKeywordToken(); + tokens.push("&&"); + } } else if (character == "|") { addKeywordToken(); tokens.push("||"); @@ -280,10 +286,15 @@ BooleanQueryTranslator.prototype = { this.throwTranslateError("close single quote for string value is missing"); }, translateExpressionValueStringKeyword: function(field, value) { - var operator = "@"; - if (value[value.length - 1] == "*") { - operator = "@^"; - value = value.substring(0, value.length - 1); + var operator; + if (!field || this.getField(field).type == "text") { + operator = "@"; + if (value[value.length - 1] == "*") { + operator = "@^"; + value = value.substring(0, value.length - 1); + } + } else { + operator = "=="; } return this.constructBinaryOperation(field, operator, "\"" + value + "\""); }, @@ -390,6 +401,14 @@ BooleanQueryTranslator.prototype = { return expressions[0]; } } + }, + getField: function(fieldName) { + var field; + if (this.domain) + field = this.domain.getIndexField(fieldName); + if (!field) + field = new IndexField(fieldName).setType("text"); + return field; } }; -------------- next part -------------- HTML����������������������������... 下载