Issue #1 new

Queries with parenthesis fail

Jamie Ivanov
created an issue

Queries with parenthesis fail which makes me think that nested structures cannot be generated.

print(Parser().parse('(taco:cat)'))

results in:

Traceback (most recent call last):
  File "script.py", line 503, in <module>
    pt_parser()
  File "script.py", line 486, in pt_parser
    result = p.parse('(taco:cat)')
  File "/Library/Python/2.7/site-packages/mgoquery.py", line 90, in parse
    r = self._parser.parseString(s)
  File "/Library/Python/2.7/site-packages/pyparsing.py", line 1006, in parseString
    raise exc
pyparsing.ParseException: Expected """ (at char 0), (line:1, col:1)

A query like this can not be converted:

(metric:if_octets.rx AND _missing_:tacocat) AND ((plugin_instance:eth*) AND (plugin:interface) AND (host:localhost) AND NOT (env:dev))

This project has so much potential and I would love it if this were possible.

Comments (3)

  1. Eric Larson repo owner

    Jamie Ivanov That is correct. When I wrote this library (which was a long time ago!) I didn't have much time and didn't want to dive too deep into a recursive parser. With that in mind, I do think it is an interesting project. I'll move the repo to github (where I do most of my work these days) and can try to address it.

    Thanks for taking a look!

  2. Jamie Ivanov reporter

    Eric Larson Please feel free to send me a link to the github repo! I've actually taken a number of ideas that you've started and combined it with a lot of my own learning to be able to produce a valid MongoDB query that supports multiple levels of Lucene parenthesis, AND, NOT, OR, lists of values, wildcards to MongoDB regex, and a few other goodies. I need to work on ranges, greater/less-thans, and a few other enhancements but my work was sparked because of what you have started. Kudos to you good sir.

    I believe I sent you a direct email at some point and I'm not sure if you can see my email address on here but you can reach me at <first name> <dot> <last name> <at> gmail <dot> com; my name can be found on Link URLin/jamieivanov) profile.

  3. Log in to comment