thoward/lucene-query-parser.js

Parser silently removes invalid input for conjunction operators

Opened this issue · 0 comments

As reported in issue #11, the parser currently will drop some invalid input for conjunction operators.

Problem Example:
Given this user input:

foo:bar OR NOT baz:qux

The parser outputs:

{
   "left": {
      "field": "foo",
      "term": "bar",
      "similarity": null,
      "boost": null,
      "prefix": null
   },
   "operator": "OR",
   "right": {
      "field": "baz",
      "term": "qux",
      "similarity": null,
      "boost": null,
      "prefix": null
   }
}

Note that the operator property is a single string value. The Lucene Query Syntax only supports a single operator for each left/operator/right expression phrase. Inputting two operators is invalid syntax.

The library should detect this and produce an error instead of silently removing the invalid syntax. This behaviour should be parameterized and opt-in so that it does not cause a breaking change. The error should indicate where in the input the error was detected and what class of parsing error was found, in a structured manner, so that the application code may correctly report this to the user.