【问题标题】:Oracle Contains failed working for phrase containing "not" wordOracle 包含对包含“非”字的短语的工作失败
【发布时间】:2020-07-04 16:30:00
【问题描述】:

我正在尝试在表中搜索“未放置”之类的短语,其中 col 由“indextype is ctxsys.context”索引

select * from 
table
where contains (col, 'not placed')>0

没有“NOT”字样,搜索工作绝对正常,没有任何问题。

只要在搜索短语中添加“not”,就会引发以下问题 -

ORA-29902: error in executing ODCIIndexStart() routine
ORA-20000: Oracle Text error:
DRG-50901: text query parser syntax error on line 1, column 1  
29902. 00000 -  "error in executing ODCIIndexStart() routine"
*Cause:    The execution of ODCIIndexStart routine caused an error.
*Action:   Examine the error messages produced by the indextype code and
           take appropriate action.

我什至尝试对“not”字使用转义序列,但它无法识别“not”字本身

【问题讨论】:

  • where instr(col, 'not placed') > 0 说什么?
  • 尝试使用{}将搜索字符串包装成contains (col, '{not placed}')>0
  • @Littlefoot 这不能使用,因为 col 大小很大,我们需要一个索引来处理它
  • @Tejash 这是给出“放置”的记录的结果并否定“不”的存在

标签: sql oracle oracle12c text-search


【解决方案1】:

notnot 运算符的保留字。您需要转义它以使用contains 搜索此值。为此,请用花括号 {} 将其括起来。

它也是默认停用词之一。这些不包含在索引中。

这将创建一个带有空停止列表的索引。所以它包括每个单词:

create table t (
  c1 varchar2(100)
);

insert into t values ( 'placed' );
insert into t values ( 'not placed' );
insert into t values ( 'something else' );
insert into t values ( 'file is placed in folder' ); 
insert into t values ( 'file is not placed in folder' ); 
commit;

create index i 
  on t ( c1 ) 
  indextype is ctxsys.context
  parameters (
    'stoplist ctxsys.empty_stoplist sync(on commit)'
  );

select * from t 
where  contains (c1, 'placed') > 0;

C1                             
placed                          
not placed                      
file is placed in folder        
file is not placed in folder  

select * from t 
where  contains (c1, 'not placed') > 0;

ORA-29902: error in executing ODCIIndexStart() routine
ORA-20000: Oracle Text error:
DRG-50901: text query parser syntax error on line 1, column 1  

select * from t 
where  contains (c1, '{not} placed') > 0;

C1                             
not placed                      
file is not placed in folder    

但您可能想创建自己的custom stop list

【讨论】:

  • 如果像下面这样操作会失败 - 插入 t 值('文件没有放在文件夹中');插入 t 值('文件放置在文件夹中'); select * from t where contains (c1, '{not} placed') > 0;结果 - 未放置,文件未放置在文件夹中,文件已放置在文件夹中,
  • Not 是一个停用词 - 您需要创建一个排除此词的停用词列表。示例更新
  • 谢谢克里斯!有效。有关创建 ctxsys 索引的更多详细信息,此链接很有用 - livesql.oracle.com/apex/livesql/file/…
猜你喜欢
  • 2015-04-27
  • 1970-01-01
  • 2013-10-04
  • 2012-12-07
  • 2021-06-13
  • 2018-09-11
  • 2012-03-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多