public
{ Public-Deklarationen }
pSearchMgr : ISearchManager;
pSearchCatMgr : ISearchCatalogManager;
pQueryHelper : ISearchQueryHelper;
pCatStat,
pReason : TOleEnum;
pInxCount : Integer;
pIndexedUrl : PWideChar;
pConnectionString : PWideChar;
pConnectionTimeOut : Cardinal;
pQuery,
pSQL : PWideChar;
pSearchString : PWideChar;
...
procedure TMainForm.FormShow(Sender: TObject);
var
pReasonRes :
string;
begin
pSearchMgr := CoCSearchManager.Create;
try
// the valid catalog is systemindex only!
pSearchMgr.GetCatalog('
SYSTEMINDEX', pSearchCatMgr);
// get some stats: pStatus, pPausedReason
pSearchCatMgr.GetCatalogStatus(pCatStat, pReason);
case pReason
of
CATALOG_PAUSED_REASON_NONE: pReasonRes := '
none';
CATALOG_PAUSED_REASON_HIGH_IO: pReasonRes := '
high io';
CATALOG_PAUSED_REASON_HIGH_CPU: pReasonRes := '
high cpu';
CATALOG_PAUSED_REASON_HIGH_NTF_RATE: pReasonRes := '
high ntf rate';
CATALOG_PAUSED_REASON_LOW_BATTERY: pReasonRes := '
low battery';
CATALOG_PAUSED_REASON_LOW_MEMORY: pReasonRes := '
low memory';
CATALOG_PAUSED_REASON_LOW_DISK: pReasonRes := '
low disk';
CATALOG_PAUSED_REASON_DELAYED_RECOVERY: pReasonRes := '
delayed recovery';
CATALOG_PAUSED_REASON_USER_ACTIVE: pReasonRes := '
user active';
CATALOG_PAUSED_REASON_EXTERNAL: pReasonRes := '
external';
CATALOG_PAUSED_REASON_UPGRADING: pReasonRes := '
upgrading';
end;
case pCatStat
of
CATALOG_STATUS_IDLE: lblStatus.Caption := Format('
Status: %0:s reason: %1:s', ['
idle', pReasonRes]);
CATALOG_STATUS_PAUSED: lblStatus.Caption := Format('
Status: %0:s reason: %1:s', ['
paused', pReasonRes]);
CATALOG_STATUS_RECOVERING: lblStatus.Caption := Format('
Status: %0:s reason: %1:s', ['
recovering', pReasonRes]);
CATALOG_STATUS_FULL_CRAWL: lblStatus.Caption := Format('
Status: %0:s reason: %1:s', ['
full crawl', pReasonRes]);
CATALOG_STATUS_INCREMENTAL_CRAWL: Format('
Status: %0:s reason: %1:s', ['
incremental crawl', pReasonRes]);
CATALOG_STATUS_PROCESSING_NOTIFICATIONS: Format('
Status: %0:s reason: %1:s', ['
notifications', pReasonRes]);
CATALOG_STATUS_SHUTTING_DOWN: Format('
Status: %0:s reason: %1:s', ['
shutting down', pReasonRes]);
end;
// how many items indexed
pSearchCatMgr.NumberOfItems(pInxCount);
lblIdxCount.Caption := Format('
Items currently indexed: %d', [pInxCount]);
// get indexed file
pSearchCatMgr.URLBeingIndexed(pIndexedUrl);
lblIndexer.Caption := Format('
Last indexed %s', [pIndexedUrl]);
// ISearchQueryHelper interface
pSearchCatMgr.GetQueryHelper(pQueryHelper);
// get timeout value
pSearchCatMgr.Get_ConnectTimeout(pConnectionTimeOut);
// get the connectionstring for connection to the oledb
pQueryHelper.Get_ConnectionString(pConnectionString);
// connect to oledb using the pconnectionstring {adoconnection}
con.ConnectionString := pConnectionString;
con.ConnectionTimeout := pConnectionTimeOut;
Con.LoginPrompt := False;
con.Connected := True;
except
on E: EOleException
do
begin
ShowMessage(E.
Message);
end;
end;
end;
// hier gehts los
procedure TMainForm.btnSearchClick(Sender: TObject);
begin
pQuery := '
SELECT Top 5 System.ItemPathDisplay FROM SYSTEMINDEX';
try
// query helper generates a valid sql string...
pQueryHelper.GenerateSQLFromUserQuery(pQuery, pSql);
qry.SQL.Text := pSQL;
qry.Active := True;
// hier kracht es aber gewaltig!
except
on e:
Exception do
begin
ShowMessage(E.
Message);
end;
end;
end;
initialization
CoInitializeEx(
nil, COINIT_MULTITHREADED);
finalization
CoUninitialize;
end.