Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Falsy numbers as term values lead to invalid queries in toString() #48

Open
saeub opened this issue Dec 8, 2021 · 0 comments
Open

Falsy numbers as term values lead to invalid queries in toString() #48

saeub opened this issue Dec 8, 2021 · 0 comments

Comments

@saeub
Copy link

saeub commented Dec 8, 2021

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)) {

if (ast.term_min) {

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant