Skip to Main Content

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, REN.

Asked: August 31, 2017 - 1:38 pm UTC

Last updated: September 01, 2017 - 4:31 pm UTC

Version: 12.1.1

Viewed 10K+ times! This question is

You Asked

Hi,

I am using oracle 12.1, Catsearch query "a but not b" working with catsearch(column, 'a - b', null)>0. But I am unable to only query "not b".

Here is a test:
create table test_catsearch(name varchar2(100)); 
insert into  test_catsearch(name) values('Lisa Smith');
insert into  test_catsearch(name) values('Bart Simpson');
insert into  test_catsearch(name) values('Lisa Simpson');
create index cat_test on TEST_CATSEARCH(name) indextype is CTXSYS.CTXCAT;


"simpson not bart" returning 'Lisa Simpson' works fine:
SELECT name FROM TEST_CATSEARCH t WHERE CATSEARCH(name, 'simpson - bart', null)> 0 ;


Error DRG-50901 when using '-' for "not bart"
SELECT name FROM TEST_CATSEARCH t WHERE CATSEARCH(name, ' - bart', null)> 0 ;

Changing condition doesn't make a difference:
SELECT name FROM TEST_CATSEARCH t WHERE CATSEARCH(name, 'bart', null)<=0 ; -- changing condition on score not working, same result as first query
SELECT name, score(1) FROM TEST_CATSEARCH t WHERE CATSEARCH(name, 'bart', null)<=0 ; --ORA-29908: missing primary invocation for ancillary operator

Neither does using logical "NOT"
SELECT name FROM TEST_CATSEARCH t WHERE NOT(CATSEARCH(name, 'bart', null)>0);--logical not on condition doesn't have impact on result neither

My question is:
Is there an alternative to query only "not b" with catsearch()?
Catsearch() returns number, but seems not the same way as score in context query. Does it mean anything else the >0 at the end of condition?

with LiveSQL Test Case:

and Chris said...

There isn't a basic not in catsearch. You could emulate it by minusing the rows that do contain this value from the whole table:

SELECT name FROM TEST_CATSEARCH
minus
SELECT name FROM TEST_CATSEARCH t WHERE CATSEARCH(name, 'bart', null)> 0 ;

NAME          
Lisa Simpson  
Lisa Smith 


...but you're scanning the data twice for that.

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Ye REN, September 06, 2017 - 4:06 pm UTC

Thank you for your response

More to Explore

Design

New to good database design? Check out Chris Saxon's full fundamentals class.