【问题标题】:substring search with CTXCAT index doesn't work even after enabling substring index during index creation即使在创建索引期间启用子字符串索引后,使用 CTXCAT 索引进行子字符串搜索也不起作用
【发布时间】:2021-11-21 15:52:21
【问题描述】:

我正在尝试在 Oracle DB 表的列上创建文本索引 (CTXCAT)。创建索引时,我已将子字符串搜索设置为 TRUE。但是创建索引后,当我进行子字符串搜索时,我看不到任何结果。

表的DDL

"
  CREATE TABLE "INSTANCE_REPO"."CUSTOMERS" 
   (    "UUID" VARCHAR2(50), 
    "NAME" VARCHAR2(50), 
    "IDENTIFIER" VARCHAR2(50)
   ) SEGMENT CREATION IMMEDIATE 
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 
 NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "USERS" "

索引创建命令

begin 
ctx_ddl.create_preference('catsearch_preferences', 'BASIC_WORDLIST'); 
ctx_ddl.set_attribute('catsearch_preferences','SUBSTRING_INDEX', 'TRUE');
end;

CREATE INDEX customer_cat ON CUSTOMERS(NAME) 
  INDEXTYPE IS CTXSYS.CTXCAT 
  PARAMETERS ('WORDLIST catsearch_preferences');

子字符串搜索查询(在插入的行上)

INSERT INTO customers(UUID,NAME,IDENTIFIER) VALUES ('500000','helloworld','HELLOWORLD');

Select * from customers where CATSEARCH(NAME, '*ello*', null) > 0

Select * from customers where CATSEARCH(NAME, '%ello%', null) > 0

结果截图

【问题讨论】:

    标签: sql database oracle indexing full-text-indexing


    【解决方案1】:

    catsearch 查询不支持前导通配符;为此,您可以使用查询模板切换到context 语法:

    create table customers (    
      uuid varchar2(50), 
      name varchar2(50), 
      identifier varchar2(50)
    ) ;
    
    begin 
      ctx_ddl.create_preference('catsearch_preferences', 'BASIC_WORDLIST'); 
      ctx_ddl.set_attribute('catsearch_preferences','SUBSTRING_INDEX', 'TRUE');
    end;
    /
    
    create index customer_cat on customers(name) 
      indextype is ctxsys.ctxcat 
      parameters ('WORDLIST catsearch_preferences');
      
    insert into customers(uuid,name,identifier) 
      values ('500000','helloworld','HELLOWORLD');
    
    select * from customers 
    where  catsearch ( 
      name, 
      '*ell*', 
      null
    ) > 0;
    
    no rows selected
    
    select * from customers 
    where  catsearch ( 
      name, 
      'hell*', 
      null
    ) > 0;
    
    UUID     NAME         IDENTIFIER   
    500000   helloworld   HELLOWORLD    
    
    select * from customers 
    where  catsearch ( 
      name, 
      '<query>
        <textquery grammar="context">
          %ello%
        </textquery>
       </query>', 
      null
    ) > 0;
    
    UUID     NAME         IDENTIFIER   
    500000   helloworld   HELLOWORLD    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-13
      • 2020-07-23
      • 1970-01-01
      • 2022-01-02
      • 2015-11-25
      • 2013-10-10
      相关资源
      最近更新 更多