bripkens / lucene

Node.js lib to transform: lucene query → syntax tree → lucene query
MIT License
72 stars 33 forks source link

Problem stringifying the AST with a parenthesized negated expression #29

Closed vsetka closed 4 years ago

vsetka commented 4 years ago

If we have a parenthesized expression that has a start (no left-hand expression), parenthesis is not placed correctly when stringifying the AST.

Example:

const { parse, toString } = require('lucene')

toString(parse('my.prop:value1 AND (NOT _exists_:other.prop OR other.prop:value2)'))
// Result is -> "my.prop:value1 AND NOT (_exists_:other.prop OR other.prop:value2)"

At a glance, the fix should be simple. Check if parenthesized is set when concatenating start and make sure start is not set when adding an opening parenthesis for a parenthesized left-hand.

bripkens commented 4 years ago

Thank you again for reporting and fixing!

bripkens commented 4 years ago

Fix is released as version 2.1.1

vsetka commented 4 years ago

No problem! Thank you for putting together this very useful module 👍