| ![]() | ||||||||||||||||||||
Mit den 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 VB DOS Beispiel demonstriert die Verwendung der FATS Matchcode-Befehle:
 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.
PRINT "This program needs the extended version of FATS (FATSXWE.EXE)"
PRINT ""
PRINT " Use the logical order of an FATS index file to build"
PRINT " the matchcode index."
PRINT
PRINT "To compile and link the test program, use the following commands:"
PRINT
PRINT " BC MCSORT"
PRINT " LINK MCSORT FATSXVBR.LIB"
PRINT
INPUT "Please press the [ENTER] key ...", X$
PRINT
REM The "Build Matchcode" (MB) command demands an ascending number
REM as a "RecNo" argument i.e. the matchcode can not usually be
REM indexed in the logical order of an index-key.
REM
REM This example program uses the flag K#:# ("MC"-command)
REM to create the matchcode index in sorted order.
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).
REM 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 -------> Opening key file
CALL FATSBASIC("O\CUSTOMER.KEY\2", ERRORCODE%, RECNO&, KEYLEN%)
IF ERRORCODE% <> 0 THEN
PRINT
PRINT "Error opening the file CUSTOMER.KEY"
PRINT "Please create the file using the test programs"
PRINT "TST0_ENG.BAS or TST1_ENG.BAS"
GOTO ENDE
END IF
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 K#:# This switch activates the management of a primary key
REM for this matchcode index file. The first value after
REM the 'K' is the position of the data column within the
REM key (1 == first part), the second value specifies the
REM length of the data column valid as the key.
REM
REM Further adjustments are possible and described in detail
REM in the user manual.
PRINT
PRINT "Creating matchcode index file ..."
CALL FATSBASIC("MC\CUSTSORT.FTS\\1\K1:5\I1\I2\I3", ERRORCODE%, RECNO&, KEYLEN%)
IF ERRORCODE% <> 0 THEN
REM
REM "MC\{Filename}\\{FileNo}\K#:#\I1\I2\I3"
REM
REM The flag K#:# enables the management of a primary key within
REM the matchcode file. FATS normaly only uses the record number
REM during the generation of a result set. In specific situations,
REM if e.g. the physical record number is not known, or does not
REM correspond to the ID specified with the MB-command, the generation
REM of a primary key becomes necessary. The browser commands then also
REM make in addition to the record- or ID-number this key available via
REM the FATSKEY-variable to the application.
REM
REM With the use of this flag, FATS generates a supplementary file with
REM the file extension .FMK which is used for the sequential storage of
REM the key.
PRINT
IF ERRORCODE% = -1 THEN
PRINT "FATS workstation engine is not activated."
PRINT "Please start the program by entering FATSXWE at the command line."
ELSE
PRINT "FATS errorcode: "; ERRORCODE%; " (command: MC)"
END IF
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 in sorted order"
PRINT
INPUT "Please press the [ENTER] key ...", X$
CURRECNO& = 0
CMND$ = "F\2\2"
REM
DO
CALL FATSBASIC(CMND$, ERRORCODE%, RECNO&, KEYLEN%)
IF ERRORCODE% = 0 THEN
GET #1, RECNO&
CURRECNO& = CURRECNO& + 1
CMND$ = "MB\1\" + STR$(CURRECNO&)
REM Add the primary key to the command string
CMND$ = CMND$ + "\" + RTRIM$(CUSTID$)
CMND$ = CMND$ + "\" + RTRIM$(NAME$)
CMND$ = CMND$ + "\" + RTRIM$(JOB$)
CMND$ = CMND$ + "\" + RTRIM$(ZIP$ + " " + CITY$)
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&
CMND$ = "N\2"
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%)
EXIT DO
END IF
LOOP WHILE NOT ERRORCODE%
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\CUSTSORT.FTS\1", ERRORCODE%, RECNO&, KEYLEN%)
REM -------> Search in Search-Group 1 (NAME)
REM
REM
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%, HITID&, KEYLEN%)
IF ERRORCODE% <> 0 THEN EXIT DO
REM
FATSKEY$ = SPACE$(KEYLEN%)
CALL FATSGETKEY(FATSKEY$)
CMND$ = "S\1\2\" + FATSKEY$
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$(HITID&)
LOOP WHILE NOT ERRORCODE%
REM --------> Close all fats files
CALL FATSBASIC("K", ERRORCODE%, RECNO&, KEYLEN%)
ENDE:
CLOSE #1
© 2008
GCS Software, Udo Gertz