Kouhei Sutou
null+****@clear*****
Thu Apr 10 18:13:41 JST 2014
Kouhei Sutou 2014-04-10 18:13:41 +0900 (Thu, 10 Apr 2014) New Revision: 991738867250bf3cba1a7cd0637e7336c1ba68ac https://github.com/droonga/fluent-plugin-droonga/commit/991738867250bf3cba1a7cd0637e7336c1ba68ac Message: search: handle syntax error in query syntax input Added files: test/command/suite/search/condition/query/syntax_error.catalog.json test/command/suite/search/condition/query/syntax_error.expected test/command/suite/search/condition/query/syntax_error.test Modified files: lib/droonga/searcher.rb Modified: lib/droonga/searcher.rb (+19 -2) =================================================================== --- lib/droonga/searcher.rb 2014-04-10 18:12:57 +0900 (4cd8b6d) +++ lib/droonga/searcher.rb 2014-04-10 18:13:41 +0900 (0808c96) @@ -63,6 +63,18 @@ module Droonga end end + class SyntaxError < ErrorMessages::BadRequest + attr_reader :syntax + attr_reader :input + def initialize(syntax, input) + detail = { + "syntax" => syntax, + "input" => input, + } + super("Syntax error: syntax:<#{syntax}> input:<#{input}>", detail) + end + end + def initialize(context) @context = context end @@ -262,7 +274,8 @@ module Droonga matchTo.parse(match_columns, :syntax => :script) options[:default_column] = matchTo end - if condition["query"] + query = condition["query"] + if query options[:syntax] = :query if condition["defaultOperator"] default_operator_string = condition["defaultOperator"] @@ -278,7 +291,11 @@ module Droonga if condition["allowColumn"] options[:allow_column] = true end - expression.parse(condition["query"], options) + begin + expression.parse(query, options) + rescue Groonga::SyntaxError + raise SyntaxError.new("query", query) + end elsif condition["script"] # "script" is ignored when "query" is also assigned. options[:syntax] = :script Added: test/command/suite/search/condition/query/syntax_error.catalog.json (+34 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/search/condition/query/syntax_error.catalog.json 2014-04-10 18:13:41 +0900 (15732c5) @@ -0,0 +1,34 @@ +{ + "datasets": { + "Droonga": { + "fact": "Memos", + "schema": { + "Memos": { + "type": "Hash", + "keyType": "ShortText", + "columns": { + "content": { + "type": "Scalar", + "valueType": "Text" + } + } + }, + "Terms": { + "type": "PatriciaTrie", + "keyType": "ShortText", + "columns": { + "memos_index": { + "type": "Index", + "valueType": "Memos", + "indexOptions": { + "sources": [ + "content" + ] + } + } + } + } + } + } + } +} Added: test/command/suite/search/condition/query/syntax_error.expected (+48 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/search/condition/query/syntax_error.expected 2014-04-10 18:13:41 +0900 (bb19507) @@ -0,0 +1,48 @@ +{ + "inReplyTo": "request-id", + "statusCode": 400, + "type": "search.result", + "body": { + "name": "SyntaxError", + "message": "Syntax error: syntax:<query> input:<(>", + "detail": { + "syntax": "query", + "input": "(" + } + }, + "errors": { + "sources0": { + "statusCode": 400, + "body": { + "name": "SyntaxError", + "message": "Syntax error: syntax:<query> input:<(>", + "detail": { + "syntax": "query", + "input": "(" + } + } + }, + "sources1": { + "statusCode": 400, + "body": { + "name": "SyntaxError", + "message": "Syntax error: syntax:<query> input:<(>", + "detail": { + "syntax": "query", + "input": "(" + } + } + }, + "sources2": { + "statusCode": 400, + "body": { + "name": "SyntaxError", + "message": "Syntax error: syntax:<query> input:<(>", + "detail": { + "syntax": "query", + "input": "(" + } + } + } + } +} Added: test/command/suite/search/condition/query/syntax_error.test (+33 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/search/condition/query/syntax_error.test 2014-04-10 18:13:41 +0900 (5e9422e) @@ -0,0 +1,33 @@ +# -*- js -*- +#@require-catalog-version 2 +#@disable-logging +{ + "type": "add", + "dataset": "Droonga", + "body": { + "table": "Memos", + "key": "droonga", + "values": { + "content": "Droonga is fun!" + } + } +} +#@enable-logging +{ + "type": "search", + "dataset": "Droonga", + "body": { + "queries": { + "memos": { + "source": "Memos", + "condition": { + "matchTo": ["content"], + "query": "(" + }, + "output": { + "elements": ["count"] + } + } + } + } +} -------------- next part -------------- HTML����������������������������...Download