When a Node has term: 0, the query returned by toString() will lack a value:
> 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'.
I think this is due to checking falsy values in these places:
|
if (ast.term || (ast.term === '' && ast.quoted)) { |
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": 0to"term": "0"fixes the problem, returning'field:0'.I think this is due to checking falsy values in these places:
lucene/lib/toString.js
Line 52 in 961ecf2
lucene/lib/toString.js
Line 77 in 961ecf2
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.