-1

SQL DB2/400 : Is there somebody has tried to work wth FullText.

If i can have a sql exemple code, it will be great .

I would like, for exemple, to use it with a clob column.

Many thanks

  • What do you mean by *FullText*? I'm not sure DB2/400 even had full text searching... DB2 for i5 I believe introduced *DB2 Text Extender* which supported full text searches. *Db2 OmniFind* replaced those in v6(?) of IBM i and is the product supported on the latest release (v7.3) of the platform formerly know as AS/400. – Charles Mar 11 '19 at 19:41
  • What is it you are actually trying to accomplish? Can you provide sample input and desired output? – WarrenT Jun 17 '19 at 22:08

1 Answers1

1

This pulls out all of space delimited words from mylib.myfile[mytext] and puts them into a table with two columns. I limit the word length to 15 cause really when do users type in words longer than 15 chars anyways and I've probably already found a match on the 1st 15 and presented a list to the user.

I copied this technique off the interweb.

CREATE TABLE mylib.myidx AS
(                                   
  WITH SPLITTER (ID, START, E, SECTION, ORIGINAL, NUM) AS 
  ( SELECT UID, 1, LOCATE(' ', mytext), CAST('' AS VARCHAR(8000)), mytext, 0  
      FROM mylib/myfile                                               
    UNION ALL
    SELECT ID, E + 1,
           CASE WHEN LOCATE(' ',ORIGINAL, E + 1) > 0
                THEN LOCATE(' ', ORIGINAL, E + 1)
                ELSE LENGTH(ORIGINAL) + 1
             END,
           SUBSTRING(ORIGINAL, START, E - START), 
           ORIGINAL, NUM + 1
      FROM SPLITTER
      WHERE E > START
  )                 
  SELECT ID AS UID                                                 
        ,CAST(SECTION AS VARCHAR(15)) AS SECTION                         
    FROM SPLITTER
    WHERE LENGTH(SECTION)>1                                 
)
WITH DATA;            
WarrenT
  • 4,502
  • 19
  • 27
danny117
  • 5,581
  • 1
  • 26
  • 35
  • Thanks ! I don’t understand this syntax. « Splitter » is a SQL key word ? I understand you create an index on a physical table. Is it possible to use this technique on clob column ? Many thanks for your help ! – Jchristophe Cherid Mar 12 '19 at 19:30
  • The first select uninion back on itself to the end of the first word and so on. – danny117 Mar 12 '19 at 21:12
  • @JchristopheCherid SPLITTER will be found defined at the top of the answer sql. – MandyShaw Mar 13 '19 at 21:19
  • Hi, thanks for answer Can someone tell me if "OmniFind Text Search Server for DB2 for i" is free, or we have to pay for this ? – Jchristophe Cherid Mar 15 '19 at 10:00
  • Hi @danny117 I'm playing with your SQL request and it's very top. Do you think there is a way to update automatically your "mylib.myidx" everi time a new record is added in "mylib/myfile" ? Many thanks for help ! – Jchristophe Cherid Mar 15 '19 at 13:27
  • Hi, Can someone explain SQL key word "SECTION" and "START" ? Thanks ! – Jchristophe Cherid Mar 15 '19 at 16:36
  • Section is column name of output. – danny117 Mar 15 '19 at 16:43
  • Re START, look at the definition of SPLITTER at the top, you will see it as a column there (along with SECTION). – MandyShaw Mar 16 '19 at 10:45
  • "Splitter" is a name being assigned to the [common table expression](https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_72/db2/rbafzcomtexp.htm) following "AS". "(ID, START, E, SECTION, ORIGINAL, NUM)" are names assigned to the result fields of the common table expression (or CTE). You might think of a CTE as a temporary intermediate workfile, at least in theory. The body of a CTE is a [fullselect](https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_72/db2/rbafzmark.htm) which is a UNION of [subselects](https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_72/db2/rbafzsubselect.htm) – WarrenT Jun 17 '19 at 22:04