FULLTEXT Verb - Create FULLTEXT File
Syntax
FULLTEXT fileid,template,keyfield{,MODE=string}{,ERR=lineref}
Description
The FULLTEXT verb creates a standard Lucene index file. BBj programs access this index file using standard WRITE RECORD, READ RECORD, and REMOVE calls. Lucene indices provide lightning fast search capability for simple or complex word-based searches over anything from simple fields to fields containing very large text based documents such as documents, reports, detailed comments, etc.
To provide fast, FULLTEXT searching over existing data located in MKEYED, XKEYED or VKEYED files, consider using the Enterprise Manager and SQL to create the FULLTEXT indices. The benefit is that these types of indices provide automatic synchronization between the table’s data file (the MKEYED, XKEYED, or VKEYED file) and the Lucene index. This ensures consistent data and makes it possible to leverage the power of the FULLTEXT index from SQL statements using simple calls to a built in system stored procedure. For complete details, see Using FULLTEXT Files/Indices for Searching and SQL FULLTEXT Indices.
For a thorough discussion of this file type and all the ways BBj leverages
this technology, see Full
Text Indexing and Searching.
Parameter |
Description |
---|---|
fileid |
Name of the new file. Must be unique. |
template |
A string template used to define the record layout and field names used in the records written to the index. The template should include some kind of “primary key” field as well. |
keyfield |
The field in the string template used as the unique, primary key for each record. |
ERR=lineref |
Branch to be taken if an error occurs during execution. |
MODE Options
Currently, no MODE options are recognized.
Example
rem ' fulltext
indexFile$ = "docindex.search"
inputFile$ = "input.txt"
template$ = "ID:C(32),DOCUMENT:C(32767*)"
keyField$ = "ID"
sampleData$ = "The quick brown fox ran across the road."
rem ' Erase leftover temporary work files from previous runs
erase indexFile$,ERR=*next
erase inputFile$,ERR=*next
rem ' Create the sample input text file and write some data
string inputFile$
stringChan = unt
open (stringChan)inputFile$
write (stringChan)sampleData$
close (stringChan)
print "Sample text file created ..."
rem ' Create the FULLTEXT index.
fulltext indexFile$,template$,keyField$
print "FULLTEXT index created ..."
rem ' Read contents of a text file
chan = unt
open (chan)inputFile$
content$ = ""
while 1
read (chan,err=FileFinished)data$
content$ = content$ + data$
wend
FileFinished:
close (chan)
rem ' Write contents of the text file to the index
indexChan = unt
open (indexChan)indexFile$
dim indexRec$:template$
indexRec.id$ = java.util.UUID.randomUUID().toString()
indexRec.document$ = content$
write record (indexChan)indexRec$
print "Finished writing document to index ..."
rem ' Clear out the indexRec$ variable
indexRec$ = ""
rem ' Query the index and look for documents with the word "fox"
read record (indexChan,knum=1,key="fox")indexRec$
print "Executed search and finished reading the document ..."
print "Document ID: ",indexRec.id$
print "Document Contents: ",indexRec.document$
close (indexChan)
rem ' Erase leftover temporary work files
erase indexFile$,ERR=*next
erase inputFile$,ERR=*next
end
See Also
Full Text Indexing and Searching