FATS - Fast Access Tree System
Inhaltsverzeichnis
Programmierschnittstellen
MS-Pascal für OS/2


Mit den  FATS-Matchcode Befehlen läßt sich auf einfachste Weise ein Volltext-Index mit dem Inhalt der von Ihnen gewünschten Spalten bzw. Felder einer Datentabelle bzw. -datei erstellen.
Jedes Wort und jede Zahl wird in den Index aufgenommen, es wird eine "invertierte Liste" erstellt.

Dieser Index ermöglicht es FATS, jeden Datensatz durch Angabe beliebiger Begriffe in Sekundenbruchteilen zu finden.

FATS stellt dem Anwendungsprogramm unmittelbar nach der Suche eine Liste aller gefundener Satznummern bzw. Primary-Keys zur Verfügung.

Das nachfolgende Microsoft Pascal Beispiel demonstriert die Verwendung der FATS Matchcode-Befehle:

(*
   FATS Extended Demo for MS Pascal / IBM Pascal

   This program needs the extended version of FATS (FATSXM.OBJ or FATSXO16.DLL)
   It tests the 'MC', 'MB', 'MS' and 'MA' commands
*) 

program TST2_ENG (input, output);

type

  custrec = record
      DELETEDMARK: char;
      ID: lstring(5);
      NAME: lstring(25);
      JOB: lstring(25);
      STREET: lstring(25);
      ZIP: lstring(5);
      CITY: lstring(20);
   end;

const

  fn_cust = 'CUSTOMER.DAT';

var

  szCmnd: lstring(255);
  szFATSkey: lstring(255);
  uFATSError: word;
  dwFATSRecno: integer4;

  hCustomer: file of custrec;
  cdata: custrec;
  dwCurRecno: integer4;
  szRecno: lstring(8);
  cChar: char;


function FATSCALL (vars cmnd: lstring; vars errorcode: word;
                   vars fatskey: lstring) : integer4; extern;


begin

  writeln ('FATS Extended test program (commands "MC", "MB", "MS" and "MA")');
  writeln ('This Test Program was designed for Microsoft Pascal');
  writeln;
  writeln ('To compile and link the test program, use ONE of the following methods:');
  writeln;
  writeln ('  1. METHOD: Linking FATS to the program');
  writeln;
  writeln ('     PAS1 TST2_ENG');
  writeln ('     PAS2');
  writeln ('     LINK TST2_ENG FATSX.OBJ FATS_MSP.OBJ');
  writeln;
  writeln ('  2. METHOD: Calling the Dynamic Link Library');
  writeln;
  writeln ('     PAS1 TST2_ENG');
  writeln ('     PAS2');
  writeln ('     LINK TST2_ENG FATSMSPD.OBJ FATSXO16.LIB    (call FATSXO16.DLL)');
  writeln;
  writeln ('Please press the [ENTER] key ...');

  read( cChar );


  (*
     -------> Open data file
  *) 

  writeln ('Opening data file ...');

  assign  (hCustomer, fn_cust);
  hCustomer.mode:=direct;
  reset (hCustomer);


  (*
     ========================================================================
               Creating Matchcode Index
     ========================================================================
  *) 


  (*
     -------> Creating Matchcode Index File
   
     With the command  "MC" Create Matchcode File, the most important
     query facilities are determined already while creating the
     matchcode index file. With the search-group flag ("I#"), several
     logically related data columns can be registered in a common index
     so that a query to this index resp. search group extends automatically
     over all these columns. A matchcode file manages up to 32 search
     groups that can be used for joined queries (using the "AND"-operator).
   
     In this example the following search groups are defined:
   
       Search Group    Fields
   
           I1          NAME
           I2          JOB
           I3          ZIP & CITY
   
     The syntax of the command string:
   
       szCmnd = "MC\{FileName}\{Flags}\{FileNo}\{Col1def}[\{Col2def}]"
   
         FileName   Filename, perhaps with an additional path
                    (i.e. C:/DATA/CUSTOMER.FMS or CUSTOMER.FMS)
   
         Flags      Reserved, not used at the moment
   
         FileNo     File number
   
         Col#def    Definition of data column # (flags, separated by comma).
                    The content of the corresponding data columns is transferred
                    the commands "MB", "MI" and "MD" later in the order determined
                    by this command.
   
                    I#  The content of the data column becomes part of search
                        group #. You can combine several columns into a logical
                        search group (e.g. first name, surname).
   
                    C   The content of the data column is edited for word overall
                        searching, i.e. a search for "motorca" e.g. finds
                        "motorcar" and "motor caravan".
   
                    N   Numbers are handled as words, i.e. during a search
                        according to "150", "12150" e.g. is also found.
   

  *)  

  writeln;
  writeln ('Creating matchcode index file ...');

  szCmnd:='MC\CUSTOMER.FTS\\1\I1\I2\I3';
  dwFATSRecno:=FATSCALL(szCmnd, uFATSError, szFATSkey);

  If uFATSError <> 0 Then Begin

    writeln;
    write ('FATS Errorcode: '); write (uFATSError);
    writeln (' (Command: MC)');
    writeln;

    Return;

  End;


  (*
     -------> Insert text into the matchcode index
   
     After the matchcode file was generated, the content of the
     data columns may be with the command  "MB" Build Matchcode
     inserted into the matchcode index. The position of the
     data columns within the command string ("Col#data") corresponds
     to that with the call of command Create Matchcode File ("MC")
     determined definition.
   
     The syntax of the command string:
   
       szCmnd = "MB\{FileNo}\{RecNo}\{Col1data}[\{Col2data}[\{Col3data}]]"
   
         FileNo     File number
   
         RecNo      <> 0 Record- resp. id-number
                    == 0 Stop Build, no more records
   
         Col#data   Content of data column #
   
   
     The following sample program code indexes contents of the
     entire data file within a loop:

  *)  

  writeln;
  writeln ('Building matchcode index');
  writeln;
  writeln ('Please press the [ENTER] key ...');
  writeln;

  read( cChar );


  dwCurRecno:=0;

  Repeat

    seek(hCustomer, dwCurRecno + 1);
    get(hCustomer);

    If NOT EOF( hCustomer ) Then Begin

      dwCurRecno:=dwCurRecno + 1;
      cdata:=hCustomer^;

      szCmnd:='MB\1\';
      If encode(szRecno, dwCurRecno:8) Then concat(szCmnd, szRecno);

      If cdata.DELETEDMARK = ' ' Then Begin

        concat (szCmnd, '\');
        concat (szCmnd, cdata.NAME);
        concat (szCmnd, '\');
        concat (szCmnd, cdata.JOB);
        concat (szCmnd, '\');
        concat (szCmnd, cdata.ZIP);
        concat (szCmnd, ' ');
        concat (szCmnd, cdata.CITY);

      End;

      dwFATSRecno:=FATSCALL(szCmnd, uFATSError, szFATSkey);

      If uFATSError <> 0 Then Begin

        (*
           If an error occurred during the execution of the "MB" command,
           the matchcode index file is already closed by FATS.
        *) 

        write ('FATS Errorcode: '); write (uFATSError);
        writeln (' (Command: MB)');
        writeln;
        break;

      End;

      writeln (cdata.NAME,' --> RecNo ', dwCurRecno:-8);

    End Else Begin


      (*
         After the last record was inserted the creating process
         has to be terminated with the command "MB\{FileNo}\0".
         Because this command closes the matchcode index file you don't
         have to do a close command.
      *) 

      szCmnd:='MB\1\0';
      dwFATSRecno:=FATSCALL(szCmnd, uFATSError, szFATSkey);
      break;

    End;

  Until uFATSError <> 0;


  If dwCurRecno = 0 Then Begin

    writeln;
    writeln( 'Error opening the file CUSTOMER.DAT' );
    writeln( 'Please create the file using one of the test programs' );
    writeln( 'TST0_ENG.PAS or TST1_ENG.PAS' );
    return;
  End;


  (*
     ========================================================================
               Matchcode Search
     ========================================================================
  *) 


  (*
     -------> Open matchcode index file
   
     With the command  "O" Open Indexfile you open an existing
     matchcode index file with the opening flags defined with
     the command  "Y" Auto Refresh. After the file was opened
     it can be accessed under the file number you specified.

  *)  

  szCmnd:='O\CUSTOMER.FTS\1';
  dwFATSRecno:=FATSCALL(szCmnd, uFATSError, szFATSkey);


  (*
     -------> Search in Search-Group 1 (NAME)
   
   
  *) 

  writeln;
  writeln ('We now search for all customers with the first name Michael.');
  writeln;
  writeln ('Please press the [ENTER] key ...');
  writeln;

  read( cChar );


  szCmnd:='MS\1\\0\michael';

  Repeat

    dwFATSRecno:=FATSCALL(szCmnd, uFATSError, szFATSkey);

    If uFATSError = 0 Then Begin

      seek(hCustomer, dwFATSRecno);
      get(hCustomer);
      cdata:=hCustomer^;

      writeln(cdata.NAME, ' | ', cdata.JOB);
      writeln(cdata.ZIP, ' ', cdata.CITY, '(#', dwFATSRecno:-8, ')');
      writeln;

      szCmnd:='MA\1\';
      If encode(szRecno, dwFATSRecno:8) Then concat(szCmnd, szRecno);

    End;

  Until uFATSError <> 0;


  (*
     --------> Joined search in Search-Groups 2 (JOB) and 3 (ZIP/CITY)
  *) 

  writeln;
  writeln ('We are now doing a joined search over the search groups');
  writeln ('2 (Job) and 3 (Zip, City) to find all people from nevada');
  writeln ('who are related to the transportation industry.');
  writeln;
  writeln ('Please press the [ENTER] key ...');
  writeln;

  read( cChar );


  szCmnd:='MS\1\\0\\trans\nev';

  Repeat

    dwFATSRecno:=FATSCALL(szCmnd, uFATSError, szFATSkey);

    If uFATSError = 0 Then Begin

      seek(hCustomer, dwFATSRecno);
      get(hCustomer);
      cdata:=hCustomer^;

      writeln(cdata.NAME, ' | ', cdata.JOB);
      writeln(cdata.ZIP, ' ', cdata.CITY, '(#', dwFATSRecno:-8, ')');
      writeln;

      szCmnd:='MA\1\';
      If encode(szRecno, dwFATSRecno:8) Then concat(szCmnd, szRecno);

    End;

  Until uFATSError <> 0;


  (*
     --------> Close matchcode index file
  *) 

  szCmnd:='K\1';
  dwFATSRecno:=FATSCALL(szCmnd, uFATSError, szFATSkey);

  close( hCustomer );

End.

© 2008  GCS Software, Udo Gertz