fts(fast text search)是快速文本搜索引擎,使用它要先初始化一下:
下面是摘录自vcl60/MAINDIR/Samples/Delphi/FTSDEMO例子一段代码(建议这个例子认真看看):
procedure TForm1.Open1Click(Sender: TObject);
var
sIdxName : String;
lRecno: Longint;
begin
{ Create HitList object }
HitList := TStringList.Create;
HitList.Duplicates := dupIgnore;
if OpenDialog1.Execute then
begin
{ Close any currently-active table }
if ApDS1.Active then
Close1Click( Sender );
{ Open Table }
ApDS1.DatabaseName := ExtractFilePath( OpenDialog1.FileName );
ApDS1.TableName := ExtractFileName( OpenDialog1.FileName );
ApDS1.Open;
edSearch.Enabled := True;
case Ord( ApDS1.TableType ) of
Ord(ttSXFOX): panTableType.Caption := 'TableType: ttSXFOX';
Ord(ttSXNTX): panTableType.Caption := 'TableType: ttSXNTX';
Ord(ttSXNSX): panTableType.Caption := 'TableType: ttSXNSX';
end;
{ Change file extension to .IA }
sIdxName := ChangeFileExt( OpenDialog1.FileName, '.IA' );
{ See if index already exists. If so, open it; If not, create it }
GetMem( cpIdxStr, ApDS1.RecSize+1 );
if FileExists( sIdxName ) then
Fts1.Open( sIdxName, 20, FTS_EXCL )
else
begin
ShowMessage( 'Creating ' + sIdxName );
Fts1.CreateIndex( sIdxName, 20, 2, True, 1 );
Gauge1.Visible := True;
lRecNo := 0;
with ApDS1 do
begin
Gauge1.Max := RecCount;
GoTop;
Screen.Cursor := crHourGlass;
while not Eof do
begin
ApolloGetRecord( cpIdxStr );
lRecno := Fts1.Add( cpIdxStr );
if lRecno < 0 then
ShowMessage( 'Error Adding Key: ' + IntToStr( lRecno ));
Gauge1.Position := Trunc( lRecno );
Skip( 1 );
{ Allows moving form, switching windows, etc., during processing }
Application.ProcessMessages;
end;
GoTop;
end;
{ IMPORTANT: Close and reopen the .IA file to _insure_ flushed buffers }
Fts1.Close;
Fts1.Open( sIdxName, 20, FTS_EXCL );
Gauge1.Position := Trunc( lRecno );
Screen.Cursor := crDefault;
Gauge1.Visible := False;
Gauge1.Position := 0;
sLastSrch := '';
end;
ShowMessage( IntToStr( Fts1.NumRecs ) + ' keys in ' + sIdxName + '.' );
{ Display Grid and set focus to Search box }
DBGrid1.Visible := True;
Close1.Enabled := True;
edSearch.SetFocus;
end;