Menu

How to index blob column?

Help
2014-03-17
2014-03-25
  • Igor Kovalyov

    Igor Kovalyov - 2014-03-17

    For indexing blob column I added clob column wich is always null,
    made pl/sql function to convert blob data to clob and used ExtraCols to specify this function call in index creation.

    Is there more simple way to index blob column without adding clob column?

     
  • Marcelo F. Ochoa

    Igor:
    BLOB is not supported by LDI because there is no way to know the encoding form of the information stored on it.
    The trick is to use ExtraCols parameter and PLSQL function to convert a BLOB to CLOB (utf8) or VARCHAR2 (32K max.)
    for example for a table:

    create table test (id number primary key, myblob BLOB)

    an index like this:

    create index test_lidx on test(id) parameters
    ('IncludeMasterColumn:false;ExtraCols:Pkg.MyBlobToClob(myblob) "text";DefaultColumn:text');

    the pragma restriction for above function should be:

    PRAGMA RESTRICT_REFERENCES (MyBlobToClob, WNDS, WNPS, RNDS, RNPS)

    usually during indexing time a common use case is to index first 10K of text, in that case a simple BLOB->VARCHAR2 function will do the job.
    Best regards, Marcelo.
    PD: Note that IncludeMasterColumn:false parameters means that id will be not indexed, only blob column will be indexed as text field, if you want to index also id column remove this parameter. DefaultColumn:text is added to change Lucene default column field name that if not added will be ID which is the master column of the index.

     

Log in to post a comment.