FATS - Fast Access Tree System
Table of Contents
Programming Interfaces
MS-Basic for OS/2


The  FATS matchcode commands create a full-text index with the content of your data tables or -files.
Every word and every number is incorporated into the index, an "inverted list" is generated.

This index enables FATS to find each data record by specification of any terms in fractions of a second.

The following Microsoft Basic example demonstrates the use of the FATS matchcode commands:

 "MC" Create Matchcode File
(Define, create and open a Matchcode-Index-File.)
 "MB" Build Matchcode
(Build the Matchcode-Index.)
 "O" Open Indexfile
(Makes a index file available for access.)
 "MS" Search in Matchcode
(Query the matchcode index, and setup an result set.)

PRINT "This program needs the extended version of FATS (FATSX.OBJ or FATSXO16.DLL)"
PRINT "It tests the 'MC', 'MB', 'MS' and 'MA' commands"
PRINT
PRINT "Up to version 6.0 of the basic compiler all strings were administered"
PRINT "in the data segment of the application. Starting from the version 7.0"
PRINT "the entire memory can be used by strings (compiler flag /Fs)."
PRINT
PRINT "To compile and link the test program, use ONE of the following methods:"
PRINT
PRINT "  1. METHOD: Linking FATS to the program"
PRINT
PRINT "     BC TST2_ENG /Lp"
PRINT "     LINK TST2_ENG fatsx.obj fats_mb6.obj"
PRINT
PRINT "    or if you use Far-Strings:"
PRINT
PRINT "     BC TST2_ENG /Lp /Fs"
PRINT "     LINK TST2_ENG fatsx.obj fats_mb7.obj"
PRINT
PRINT "  2. METHOD: Calling the Dynamic Link Library"
PRINT
PRINT "     BC TST2_ENG /Lp"
PRINT "     LINK TST2_ENG fatsmb6d.obj fatsxo16.lib    (call FATSXO16.DLL)"
PRINT
PRINT "    or with Far-Strings:"
PRINT
PRINT "     BC TST2_ENG /Lp /Fs"
PRINT "     LINK TST2_ENG fatsmb7d.obj fatsxo16.lib"
PRINT
INPUT "Please press the [ENTER] key ...", X$
PRINT


REM  -------> Activation of Network Operation
REM
REM  FATS is standardly equiped for the network environment.
REM  Nearly all commands can be executed both in single workstation
REM  and network environment. With the  "Y" Auto Refresh command you
REM  determine the behavior of FATS accessing all index files.
REM  Normally it is sufficient to apply this instruction one time at
REM  the program start whereby the specified access mode will apply
REM  to all coming opened files, i.e. they are accessed either with
REM  network (Y\2) or single workstation access (Y\0).

CALL FATSBASIC("Y\2", ERRORCODE%, RECNO&, KEYLEN%)


REM  -------> Open data file

PRINT "Opening data file ..."

OPEN "R", #1, "CUSTOMER.DAT", 128
FIELD #1, 1 AS DELETEDMARK$,_
          5 AS CUSTID$,_
         25 AS NAME$,_
         25 AS JOB$,_
         25 AS STREET$,_
          5 AS ZIP$,_
         20 AS CITY$


REM  ========================================================================
REM            Creating Matchcode Index
REM  ========================================================================


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

PRINT
PRINT "Creating matchcode index file ..."

CALL FATSBASIC("MC\CUSTOMER.FTS\\1\I1\I2\I3", ERRORCODE%, RECNO&, KEYLEN%)
IF ERRORCODE% <> 0 THEN

  PRINT
  PRINT "FATS errorcode: "; ERRORCODE%; " (command: MC)"
  GOTO ENDE

END IF

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

PRINT
PRINT "Building matchcode index"
PRINT
INPUT "Please press the [ENTER] key ...", X$

CURRECNO& = 0

REM  While indexing sequential data resources, the number specified
REM  via "RecNo" should correspond to the physical record number
REM  i.e. the first data record has number 1, the second record number 2..,
REM  in the case of data records marked as deleted, the content of the
REM  data columns is not specified ("MB\{FileNo}\{RecNo}").
REM
REM  The Build Matchcode (MB) command demands an ascending number as a
REM  "RecNo" argument i.e. the matchcode can not usually be indexed in
REM  the logical order of an index-key.
REM  The example program MCSORT.bas shows how an application
REM  program might use the "MC" command to create the
REM  matchcode index in sorted order.

DO

  GET #1, CURRECNO& + 1

  IF NOT EOF(1) THEN

    CURRECNO& = CURRECNO& + 1

    CMND$ = "MB\1\" + STR$(CURRECNO&)

    IF DELETEDMARK$ = " " THEN

      CMND$ = CMND$ + "\" + RTRIM$(NAME$)
      CMND$ = CMND$ + "\" + RTRIM$(JOB$)
      CMND$ = CMND$ + "\" + RTRIM$(ZIP$ + " " + CITY$)

    END IF

    CALL FATSBASIC(CMND$, ERRORCODE%, RECNO&, KEYLEN%)

    IF ERRORCODE% <> 0 THEN

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

      PRINT "FATS errorcode: "; ERRORCODE%; " (command: MB)"
      EXIT DO
    END IF

    PRINT "  "; NAME$; " --> RecNo "; CURRECNO&

  ELSE

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

    CALL FATSBASIC("MB\1\0", ERRORCODE%, RECNO&, KEYLEN%)

  END IF

LOOP WHILE NOT EOF(1)


IF CURRECNO& = 0 THEN

  PRINT
  PRINT "Error opening the file CUSTOMER.DAT"
  PRINT "Please create the file using the test programs"
  PRINT "TST0_ENG.BAS or TST1_ENG.BAS"

  GOTO ENDE

END IF


REM  ========================================================================
REM            Matchcode Search
REM  ========================================================================


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

CALL FATSBASIC("O\CUSTOMER.FTS\1", ERRORCODE%, RECNO&, KEYLEN%)


REM  -------> Search in Search-Group 1 (NAME)
REM
REM  The command   "MS" Search in Matchcode searches the matchcode
REM  index and fills the result set with the record- resp. ID-numbers
REM  of data records which include the searched terms. If FATS finds
REM  the requested terms, it returns the record- resp. ID-number of
REM  the first hit in the "dwRecno" variable and a errorcode of 0.
REM  The result set can then be read out with the browser commands
REM  ("MA", "ME", "MN", "MP" ...).
REM
REM  The syntax of the command string:
REM
REM    szCmnd = "MS\{FileNo}\{Flags}\{Total}\{SearchGrp1}[\{SearchGrp2}...]"
REM
REM    FileNo     File number
REM
REM    Flags      The search procedure can be adjusted by the specification
REM               of different flags. You find a description of the flags
REM               in the command reference.
REM
REM    Total      Maximum number of hits in the result set:
REM
REM                 0  All hits are set into the result set. This regulation
REM                    works very fast, however, no sorting occurs by means of
REM                    hit quality.
REM
REM                >0  It is attempted to put the specified number of hits into
REM                    the result set. These hits are subjected to a sorting
REM                    concerning their quality and then put into one of
REM                    7 sorting groups.
REM
REM    SearchGrp#  The in search group # searched terms.
REM
REM
REM  Different FATS commands can be used for further processing
REM  of the result table, depending on the program logic.
REM  The following example prints all hits on the output device:

PRINT
PRINT "We now search for all customers with the first name Michael."
PRINT
INPUT "Please press the [ENTER] key ...", X$
PRINT

CMND$ = "MS\1\\0\michael"

DO

  CALL FATSBASIC(CMND$, ERRORCODE%, RECNO&, KEYLEN%)
  IF ERRORCODE% <> 0 THEN EXIT DO

  GET #1, RECNO&
  PRINT NAME$; " | "; JOB$
  PRINT ZIP$; " "; CITY$; " (#"; RECNO&; ")"
  PRINT

  CMND$ = "MA\1\" + STR$(RECNO&)

LOOP WHILE NOT ERRORCODE%


REM  The following browser commands are supported by FATS:
REM
REM    "MF" - Get First Result
REM    "ML" - Get Last Result
REM    "MP" - Get Previous Result
REM    "MN" - Get Next Result
REM    "MA" - Get Next Result After
REM    "ME" - Get Previous Result Before


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

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

CMND$ = "MS\1\\0\\trans\nev"

DO

  CALL FATSBASIC(CMND$, ERRORCODE%, RECNO&, KEYLEN%)
  IF ERRORCODE% <> 0 THEN EXIT DO

  GET #1, RECNO&
  PRINT NAME$; " | "; JOB$
  PRINT ZIP$; " "; CITY$; " (#"; RECNO&; ")"
  PRINT

  CMND$ = "MA\1\" + STR$(RECNO&)

LOOP WHILE NOT ERRORCODE%


REM  --------> Close matchcode index file

CALL FATSBASIC("K\1", ERRORCODE%, RECNO&, KEYLEN%)

ENDE:

CLOSE #1

© 2008  GCS Software, Udo Gertz