Open saeub opened 2 years ago
When a Node has term: 0, the query returned by toString() will lack a value:
term: 0
toString()
> const lucene = require("lucene"); > lucene.toString({ ... "left": { ..... "field": "field", ..... "fieldLocation": { ....... "start": { ......... "offset": 0, ......... "line": 1, ......... "column": 1 ......... }, ....... "end": { ......... "offset": 5, ......... "line": 1, ......... "column": 6 ......... } ....... }, ..... "term": 0, // <----- ..... "quoted": false, ..... "regex": false, ..... "termLocation": { ....... "start": { ......... "offset": 6, ......... "line": 1, ......... "column": 7 ......... }, ....... "end": { ......... "offset": 7, ......... "line": 1, ......... "column": 8 ......... } ....... }, ..... "similarity": null, ..... "boost": null, ..... "prefix": null ..... } ... }); 'field:'
Changing "term": 0 to "term": "0" fixes the problem, returning 'field:0'.
"term": 0
"term": "0"
'field:0'
I think this is due to checking falsy values in these places:
https://github.com/bripkens/lucene/blob/961ecf24d2dc3bd18d700d4c8a5cb1cfbac13106/lib/toString.js#L52 https://github.com/bripkens/lucene/blob/961ecf24d2dc3bd18d700d4c8a5cb1cfbac13106/lib/toString.js#L77
Of course, a workaround is to always use strings as term values, but allowing numbers and returning an invalid query like this is very confusing.
When a Node has
term: 0
, the query returned bytoString()
will lack a value:Changing
"term": 0
to"term": "0"
fixes the problem, returning'field:0'
.I think this is due to checking falsy values in these places:
https://github.com/bripkens/lucene/blob/961ecf24d2dc3bd18d700d4c8a5cb1cfbac13106/lib/toString.js#L52 https://github.com/bripkens/lucene/blob/961ecf24d2dc3bd18d700d4c8a5cb1cfbac13106/lib/toString.js#L77
Of course, a workaround is to always use strings as term values, but allowing numbers and returning an invalid query like this is very confusing.