Oracle Context index returning inconsistent results

From: Robert Buda <rjbuda_at_budaconsulting.com>
Date: Mon, 26 Jan 2009 10:43:23 -0500
Message-ID: <002201c97fcc$d2c7dfa0$1500a8c0_at_BudaConsulting.local>



I am working on a system that uses oracle con-text.

If I conduct the following search from sql using the contains clause, my results are not consistent. If anyone has any ideas on what may be wrong, please let me know. I have tried rebuilding the index and made sure that it is synchronized before issuing the query. I get inconsistent results like this on two systems, although they have different data so the inconsistencies differ a bit. Here are the details. Thank you for taking the time to look at this.

I have two rows in my inventory table with the following values in the inventory number column. I have displayed the value of inventorynumber surrounded by arrows as well as the dump of the value to demonstrate that there is nothing before or after the inventory number value in either row.  

SQL> select inventorynumber,
  2 '-->'||inventorynumber||'<--' surrounded,   3 dump(inventorynumber) dumped
  4 from inventory
  5 where inventorynumber = '05:1254C'   6

SQL> /  

INVENTORYNUMBER  SURROUNDED        DUMPED
05:1254C         -->05:1254C<--    Typ=1 Len=8:48,53,58,49,50,53,52,67

SQL> l
  1 select inventorynumber,
  2 '-->'||inventorynumber||'<--' surrounded,   3 dump(inventorynumber) dumped
  4 from inventory
  5 where inventorynumber = '97:0273C'   6*

SQL> /

INVENTORYNUMBER  SURROUNDED       DUMPED
97:0273C         -->97:0273C<--   Typ=1 Len=8: 57,55,58,48,50,55,51,67

Now when I use the contains clause to get the data, the results differ: When I use the first value above, no rows are returned

SQL> select *
  2 from inventory
  3 where contains (title,'05:1254C') > 0

no rows selected

When I use the second value a row is returned properly

SQL> select inventorynumber
  2 from inventory
  3 where contains (title,'97:0273C') > 0 ;

97:0273C  

And here is the interesting part: if I use the first value with a % after the value, I get the proper result: The percent sign should not be necessary!

SQL> select inventorynumber
  2 from inventory
  3 where contains (title,'05:1254C%') > 0  

05:1254C

There is a domain index on the title column of the table that is set up like this:

ctx_ddl.create_preference('INVENTORYSEARCH_USER_DATASTORE',
'user_datastore');

ctx_ddl.set_attribute('INVENTORYSEARCH_USER_DATASTORE', 'procedure',
'CTXSYS.PROCINVENTORYSEARCH');

create index SASDB.INVENTORYSEARCH_INDX_02 on SASDB.INVENTORY(title)

      indextype is ctxsys.context
      parameters ('datastore INVENTORYSEARCH_USER_DATASTORE');
 

This is a computed index using the store procedure PROCINVENTORYSEARCH defined as:

create or replace procedure PROCINVENTORYSEARCH(

    p_id in rowid,
    p_lob IN OUT clob) IS
begin

    for c1 in (select distinct art.LNAME||' '||inv.TITLE||'
'||invcat.DESCRIPTION combo, inv.INVENTORYNUMBER

           from sasdb.INVENTORY inv, sasdb.ARTISTS art, sasdb.INVENTORYPROFILES invprof,

                sasdb.CATEGORIES invcat
            where inv.artist_id = art.artist_id(+)
            and inv.inventory_id = invprof.inventory_id(+)
            and invprof.category_id = invcat.category_id(+)
            and inv.rowid = p_id)
    loop
        -- assemble into p_lob ANY data you want
        -- indexed.
        dbms_lob.copy( p_lob,(c1.combo||'

'||c1.INVENTORYNUMBER),dbms_lob.getlength((c1.combo||'
'||c1.INVENTORYNUMBER)));

    end loop;
end;  

Bob Buda

--
http://www.freelists.org/webpage/oracle-l
Received on Mon Jan 26 2009 - 09:43:23 CST

Original text of this message