oraclecloboracle-text

oracle - can I use contain and near with a clob? Need to speed up query


We have a query that takes 48 minutes to run a search on a clob. The query is written as if it is not a clob column and uses contains and near. This search for 3 words within a certain word distance from each other is important. I'm needing to speed this up and want to do an index on the clob, but don't know if that would work and don't fully understand how to do it. I found this from Tom Burleson http://www.dba-oracle.com/t_clob_search_query.htm OR https://asktom.oracle.com/pls/apex/asktom.search?tag=oracle-text-contains-search-with-near-is-very-slow , but can't figure out how to do it with contains and near to enable the search of 3 words withing a certain distance from each other.

current script:

SELECT clob_field 
FROM clob_table 
WHERE contains(clob_field,'NEAR (((QUICK),(FOX),(LAZY)),5)') > 0;

Want to use something like this if it will act like indexing:

SELECT clob_field
FROM clob_table
WHERE contains(dbms_lob.substr(clob_field,'near(((QUICK),(FOX),(LAZY)),5)')) > 0;

If not, I need to do indexing, but I don't quite understand how to use CTXCAT and CONTEXT (https://docs.oracle.com/cd/A91202_01/901_doc/text.901/a90122/ind4.htm). I also don't like what I read here that says that if one uses CTXCAT for indexing a clob you have to use CONTEXT, or something like that. It can't affect the other queries that are done on this field.

Thanks in advance!


Solution

  • Contains won't work unless it is globally indexed, so I had to index the field and then could get the original query working.