jurismarches / luqum

A lucene query parser generating ElasticSearch queries and more !
Other
188 stars 40 forks source link

ISO 8601 date with timezone fails to parse without doublequotes #96

Open chkp-shacharah opened 1 year ago

chkp-shacharah commented 1 year ago

Hi,

I'm experiencing errors parsing lucene strings that refer to a date-time value with timezone that is not wrapped with double-quotes. See for example:

>>> from luqum.parser import parser
>>> condition_tree = parser.parse('time:["2023-06-13T04:51:28+00:00" TO now]') # <--- WORKS
>>> condition_tree = parser.parse('time:[2023-06-13T04:51:28+00:00 TO now]')  # <-- FAILS 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/var/lang/lib/python3.8/site-packages/ply/yacc.py", line 333, in parse
    return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
  File "/var/lang/lib/python3.8/site-packages/ply/yacc.py", line 1201, in parseopt_notrack
    tok = call_errorfunc(self.errorfunc, errtoken, self)
  File "/var/lang/lib/python3.8/site-packages/ply/yacc.py", line 192, in call_errorfunc
    r = errorfunc(token)
  File "/var/lang/lib/python3.8/site-packages/luqum/parser.py", line 357, in p_error
    raise ParseSyntaxError("Syntax error in input : %s at %s!" % (error, pos))
luqum.exceptions.ParseSyntaxError: Syntax error in input : unexpected  ':' at position 28!

I can surely try to workaround it with patching the input and wrapping it with double-quotes, but since Elasticsearch accepts this as is - I wonder if this is a real bug that can be fixed here. https://www.elastic.co/guide/en/elasticsearch/reference/7.10/query-dsl-query-string-query.html#query-string-top-level-params

time_zone (Optional, string) Coordinated Universal Time (UTC) offset or IANA time zone used to convert date values in the query string to UTC.

Valid values are ISO 8601 UTC offsets, such as +01:00 or -08:00, and IANA time zone IDs, such as America/Los_Angeles.

alexgarel commented 1 year ago

Hi @shachar-av, thanks for bug report. Would you be able to propose a PR ?