Question

I know I can use ctx_query.count_hits to count the number of document matching a query, and similarly, I can use

count(*) where CONTAINS(...)

But these are only options if I actually have a query. Those functions throw an exception if I pass an empty string as a query (thanks oracle...). So,

Is there a way to count the total number of document indexed by my oracle.text index?

Was it helpful?

Solution

The preferred way is to use CTX_REPORT Package, either describe_index

set long 50000
select ctx_report.describe_index('MYINDEX') from dual;

will give you the number of indexed documents in docid count column:

===========================================================================
                             INDEX DESCRIPTION
===========================================================================
index name:                    "SCHEMA"."MYINDEX"
index id:                      1130
index type:                    context

status:                        INDEXED

full optimize token:
full optimize count:
docid count:                   6909265
nextid:                        6909266

Alternatively, use index_stats:

create table output (result CLOB);

  declare
    x clob := null;
  begin
    ctx_report.index_stats('MYINDEX',x);
    insert into output values (x);
    commit;
    dbms_lob.freetemporary(x);
  end;
  /

set long 32000
set head off
set pagesize 10000
select * from output;
===========================================================================
           STATISTICS FOR "SCHEMA"."MYINDEX"
===========================================================================
indexed documents:                                             6,909,265

Also useful to get the size of the index:

set long 50000
select ctx_report.index_size('MYINDEX') from dual;

OTHER TIPS

You can use the CTX... views:

select idx_name, idx_table_owner, idx_table, idx_docid_count 
from ctx_user_indexes
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top