问题描述
嗨,汤姆,
我的问题可能是非常基本的,但我发现在使用查询松弛功能以及 '%' 通配符时遇到了一些麻烦。
因此,我想用 {} 转义查询中的所有字符,然后作为后缀添加 % 以进行前缀搜索,但没有运气。
使用逃生字符,我无法获得任何结果,但是当它们没有逃脱时,它就可以正常工作。
你能简单解释一下为什么吗?
“%” 是否会自动转义所有字符,还是应该手动编写一个自定义函数,该函数将使用单个运算符 “\” 转义所有特殊字符?
我的问题可能是非常基本的,但我发现在使用查询松弛功能以及 '%' 通配符时遇到了一些麻烦。
因此,我想用 {} 转义查询中的所有字符,然后作为后缀添加 % 以进行前缀搜索,但没有运气。
使用逃生字符,我无法获得任何结果,但是当它们没有逃脱时,它就可以正常工作。
-- WORKS
contains(i.name,
'
lawn%
', 1) > 0
-- DOESN'T
contains(i.name,
'
{lawn}%
', 1) > 0
你能简单解释一下为什么吗?
“%” 是否会自动转义所有字符,还是应该手动编写一个自定义函数,该函数将使用单个运算符 “\” 转义所有特殊字符?
专家解答
我向下午罗杰·福特 (Roger Ford) 询问有关Oracle的文字。他的回答是:
You cannot use { } in conjunction with %.
If you search for {lawn}% it will actually rewite internally to "{lawn} %" - note the space in front of the %. That causes it to become a two-word query which will match "the word lawn followed by any other word" - assuming it doesn't fail with "too many expansions", which it generally will.
The solution is to use backslash-escaping instead - \l\a\w\n\%
or even better decide whether you actually need to escape the ordinary characters in the first place.
This is covered in my blog post about my query parser:
https://blogs.oracle.com/searchtech/oracle-text-query-parser
You cannot use { } in conjunction with %.
If you search for {lawn}% it will actually rewite internally to "{lawn} %" - note the space in front of the %. That causes it to become a two-word query which will match "the word lawn followed by any other word" - assuming it doesn't fail with "too many expansions", which it generally will.
The solution is to use backslash-escaping instead - \l\a\w\n\%
or even better decide whether you actually need to escape the ordinary characters in the first place.
This is covered in my blog post about my query parser:
https://blogs.oracle.com/searchtech/oracle-text-query-parser
文章转载自ASKTOM,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




