如何在sphinxQL全文搜索中转义特殊字符?
在sphinx变更日志中,它说0.9.8:
“添加了对查询语言的查询转义支持,以及EscapeString() API调用”
我可以假设,应该支持转义特殊的sphinx字符(@,!, -, ...) 也适用于 sphinxQL?如果是这样,也许有人可以给我举一个例子。我是 无法在文档或网络上的其他地方找到任何有关它的信息。
如果搜索短语包含特殊字符之一,如何进行全文搜索(使用 spinxQL)?我非常不喜欢在索引过程中“掩盖”它们的想法。
谢谢!
in the sphinx changelog it says for 0.9.8:
"added query escaping support to query language, and EscapeString() API call"
can i assume, that there should be support for escaping special sphinx characters (@, !,
-, ...) for sphinxQL, too? if so, maybe someone could point me to an example on this. i'm
unable to find anything about it in the documentation or elsewhere on the net.
how do you do fulltext search (using spinxQL), if the search-phrase contains one of the special characters? i don't like the idea very much to "mask" them during indexing.
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PHP 版本的 sphinxapi 转义函数在测试中对我不起作用。此外,它不提供针对 SQL 注入类型字符(例如单引号)的保护。
我需要这个函数:
注意 Sphinx 特定字符上的额外反斜杠。我认为发生的情况是,他们将整个查询通过 SQL 解析器,该解析器删除了用于 SQL 目的的“无关”转义反斜杠(即“\&”->“&”)。然后,它将 MATCH 子句放入全文解析器,然后突然出现“&”是一个特殊字符。因此,您需要在开头添加额外的反斜杠。
The PHP version of the sphinxapi escape function did not work for me in tests. Also, it provides no protection against SQL-injection sorts of characters (e.g. single quote).
I needed this function:
Note the extra backslashes on the Sphinx-specific characters. I think what happens is that they put your whole query through an SQL parser, which removes escape backslashes 'extraneous' for SQL purposes (i.e. '\&' -> '&'). Then, it puts the MATCH clause through the fulltext parser, and suddenly '&' is a special character. So, you need the extra backslashes in the beginning.
每个 API ( php/python/java/ruby ) 中都有相应的函数 EscapeString,但要使转义与 SphinxQL 一起工作,您必须在应用程序中编写类似的内容,因为 SphinxQL 没有此类函数。
该函数本身是在线的,
您可以轻松地将其转换为您的应用程序的代码。
There are corresponding functions EscapeString in each API ( php/python/java/ruby ) but to make escaping work with SphinxQL you have to write something similar in your application as SphinxQL hasn't such function.
The function itself is onliner
you could easy translate it to code of your application.