oracle Oracle全文,CONTAINS()的语法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13150767/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 01:12:51  来源:igfitidea点击:

Oracle full text, the syntax of CONTAINS()

oraclefull-text-search

提问by gfytd

contains(columnname, 'ABC')=0

this means search for the data which doesn't contain word 'ABC'

这意味着搜索不包含单词“ABC”的数据

contains(columnname, 'ABC and XYZ')=0
contains(columnname, 'ABC or XYZ')=0

what do these 2 sql mean? I tested them, there's no syntax error, but they didn't work as I expected, the 'and' seems like an 'or', and 'or' seems like an 'and', could anyone help to explain this? all doc found in google are for contains()>0, those're not what I need.

这两个sql是什么意思?我测试了它们,没有语法错误,但它们没有按我预期的那样工作,'and' 看起来像一个 'or',而 'or' 看起来像一个 'and',谁能帮忙解释一下?在 google 中找到的所有文档都用于 contains()>0,那些不是我需要的。

thanks in advance.

提前致谢。

回答by A.B.Cade

According to oracle documentation, the containsfunction :

根据oracle文档,该contains功能:

returns a relevance score for every row selected

为选定的每一行返回相关性分数

If you ask for

如果你要求

contains(columnname, 'ABC')=0

You actually ask for a score of 0which means: columnname doesn't contain 'ABC'

您实际上要求得分,0这意味着:列名不包含“ABC”

According to the docs:

根据文档:

In an AND query, the score returned is the score of the lowest query term

In an OR query, the score returned is the score for the highest query term

在 AND 查询中,返回的分数是最低查询词的分数

在 OR 查询中,返回的分数是最高查询词的分数

So if you ask for:

所以如果你要求:

contains(columnname, 'ABC and XYZ')=0

then if either 'ABC' or'XYZ' has a score of 0it will have the lowest score and that's what you'll get from the function, so you're actually asking for: columnname doesn't contain 'ABC' or 'XYZ' (at least one of them).

那么如果“ABC”“XYZ”的得分0最低,这就是你从函数中得到的,所以你实际上是在要求:列名不包含“ABC”或“XYZ” '(至少其中之一)。

Same thing for the or-

同样的事情 or-

contains(columnname, 'ABC or XYZ')=0

only if both 'ABC' and'XYZ' have the score of 0the function will return 0, so you're actually asking for: columnname doesn't contain 'ABC' and 'XYZ' (both of them).

仅当 'ABC''XYZ' 都具有该0函数的分数时才会返回0,所以您实际上是在要求: columnname 不包含 'ABC' 和 'XYZ'(两者)。

IMHO, this behaviour is correct since it meets De-Moragan's Laws

恕我直言,这种行为是正确的,因为它符合德莫拉根定律