我注意到 ravendb
的 python 客户端有一个奇怪的解析问题。
当我使用这个查询时
query_result = list(session.query().where_equals("url",url).select("Id","htmlCode","url"))
知道 url = "http://www.mywebsite.net/"
错误堆栈的相关部分如下:
File "/usr/local/lib/python3.5/dist-packages/pyravendb/store/session_query.py", line 71, in __iter__
return self._execute_query().__iter__()
File "/usr/local/lib/python3.5/dist-packages/pyravendb/store/session_query.py", line 307, in _execute_query
includes=self.includes)
File "/usr/local/lib/python3.5/dist-packages/pyravendb/d_commands/database_commands.py", line 286, in query
raise exceptions.ErrorResponseException(response["Error"][:100])
pyravendb.custom_exceptions.exceptions.ErrorResponseException: Lucene.Net.QueryParsers.ParseException: Could not parse: 'url:http://www.mywebsite.net/' --->
但是,如果我简单地向查询中的 url 参数添加一个简单的 ' '
,它可以正常工作而不会出现任何解析错误(但是 dosent 会返回一个结果,因为语法不一样)。
我想为 github 上的 pyravendb
做贡献,但我不确定它在哪里解析参数,它可能为此调用了 lucene
。
知道为什么简单的空格会妨碍正确的解析吗?
最佳答案
你发送给lucene的查询是这个url:http://www.mywebsite.net/
lucene 键将是 url
,值应该是 http://www.mywebsite.net/
因为你在 http://www.mywebsite.net/
中有 :
lucene 解析器会“混淆”并引发解析错误。(拆分键,值特殊字符是:
)
要解决您的问题,您需要转义 url 参数中的 :
,然后将其提供给查询,这样您的 url 参数应如下所示:
http\://www.mywebsite.net/
关于为什么简单的空格会阻止正确解析的问题,是因为 lucene 中的空格表示要查找的另一个参数。 (您可以在使用 where_in 方法时看到我们构建的查询)
这个问题将在下一个版本的pyravendb中修复(当前版本是1.3.1.1)
关于python - pyravendb查询参数解析错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42486689/