如何在sphinxQL全文搜索中转义特殊字符? [英] How to escape special characters in sphinxQL fulltext search?

查看:223
本文介绍了如何在sphinxQL全文搜索中转义特殊字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在sphinx更改日志中,它表示为0.9.8:

in the sphinx changelog it says for 0.9.8:

添加了查询转义支持查询语言,而EscapeString()API调用

"added query escaping support to query language, and EscapeString() API call"

我可以假设,还应该支持为sphinxQL转义特殊狮身人面像(@,!,
- ,...)?如果是这样,也许有人可以指出一个例子。我在
无法在文档或网络上的其他地方找到任何内容。

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.

如何搜索短语包含特殊字符之一,您如何进行全文搜索(使用spinxQL)?我不喜欢这个想法在索引期间掩盖他们。

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.

谢谢!

推荐答案

在每个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.

函数本身是onliner

The function itself is onliner

def EscapeString(self, string):
 return re.sub(r"([=\(\)|\-!@~\"&/\\\^\$\=])", r"\\\1", string)

你可以轻松地将其翻译成

you could easy translate it to code of your application.

这篇关于如何在sphinxQL全文搜索中转义特殊字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆