Windows Search 4 查询 - Delphi 示例

发布于 2024-09-07 13:22:07 字数 320 浏览 8 评论 0原文

以下网页介绍了以编程方式查询 Windows 搜索:

http://msdn.microsoft。 com/en-us/library/aa965362.aspx

有人有使用 Delphi/Pascal 的示例吗?

我想到的例子相当简单:

  1. 搜索某些文件类型。
  2. 搜索文件中的特定文本。
  3. 将上述搜索限制到特定路径。

The following web page describes querying Windows Search programmatically:

http://msdn.microsoft.com/en-us/library/aa965362.aspx

Does anyone have examples using Delphi/Pascal?

Examples I have in mind are fairly simple:

  1. Search for certain file types.
  2. Search for specific text within files.
  3. Limit these above searches to a certain path.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜声 2024-09-14 13:22:07

这是我不久前所做的一个 - 请注意它可能已经过时:

const
  GENERAL_COLUMNS = '"System.Itemname", "System.Size", "System.DateCreated", "System.ItemDate",' +
                    '"System.ItemFolderPathDisplay", "System.Search.AutoSummary", "System.ItemType"';

  IMAGE_COLUMNS = '"System.Image.HorizontalSize", "System.Image.VerticalSize", '+
                  '"System.Image.BitDepth", "System.Image.Compression", '+
                  '"System.Photo.CameraModel", "System.Photo.DateTaken", "System.Photo.Flash"';
  MUSIC_COLUMNS = '"System.Music.Artist", "System.Music.Genre", "System.Music.TrackNumber", '+
                  '"System.Audio.Compression", "System.Audio.SampleRate", '+
                  '"System.DRM.IsProtected", "System.Music.AlbumTitle", "System.Rating", '+
                  '"System.Audio.EncodingBitrate"';

procedure TWDSDataSource.RetrieveDataFromDB;
var
  manager : ISearchManager;
  catalogManager : ISearchCatalogManager;
  queryHelper : ISearchQueryHelper;
  wQuery : string;
  temp : PWideChar;
  sTemp : string;
begin
  manager := CoCSearchManager.Create;
  if Succeeded(manager.GetCatalog('SystemIndex',catalogManager)) then
  begin
    if Succeeded(catalogManager.GetQueryHelper(queryHelper)) then
    begin
      if fMaxResults  0 then
        queryHelper.Set_QueryMaxResults(fMaxResults);

      queryHelper.Set_QuerySelectColumns(GENERAL_COLUMNS + ',' + MUSIC_COLUMNS + ',' + IMAGE_COLUMNS);
      queryHelper.GenerateSQLFromUserQuery(PWideChar(fQuery),temp);
      wQuery := temp;

      queryHelper.Get_ConnectionString(temp);
      sTemp := temp;
      dataset := CreateComObject(CLASS_Recordset) as _Recordset;
      dataset.CursorLocation := adUseClient;
      dataset.Open(wQuery, stemp, adOpenForwardOnly, adLockReadOnly, adCmdText);
      dataset.Set_ActiveConnection(nil);
      bDatabaseFailed := false;
    end else
      bDatabaseFailed := true;
  end else
    bDatabaseFailed := true;
end;

我认为这一切都非常不言自明, fQuery 是您要执行的查询。

问候
基思

Here's one I did a while ago - be aware that it may be out of date:

const
  GENERAL_COLUMNS = '"System.Itemname", "System.Size", "System.DateCreated", "System.ItemDate",' +
                    '"System.ItemFolderPathDisplay", "System.Search.AutoSummary", "System.ItemType"';

  IMAGE_COLUMNS = '"System.Image.HorizontalSize", "System.Image.VerticalSize", '+
                  '"System.Image.BitDepth", "System.Image.Compression", '+
                  '"System.Photo.CameraModel", "System.Photo.DateTaken", "System.Photo.Flash"';
  MUSIC_COLUMNS = '"System.Music.Artist", "System.Music.Genre", "System.Music.TrackNumber", '+
                  '"System.Audio.Compression", "System.Audio.SampleRate", '+
                  '"System.DRM.IsProtected", "System.Music.AlbumTitle", "System.Rating", '+
                  '"System.Audio.EncodingBitrate"';

procedure TWDSDataSource.RetrieveDataFromDB;
var
  manager : ISearchManager;
  catalogManager : ISearchCatalogManager;
  queryHelper : ISearchQueryHelper;
  wQuery : string;
  temp : PWideChar;
  sTemp : string;
begin
  manager := CoCSearchManager.Create;
  if Succeeded(manager.GetCatalog('SystemIndex',catalogManager)) then
  begin
    if Succeeded(catalogManager.GetQueryHelper(queryHelper)) then
    begin
      if fMaxResults  0 then
        queryHelper.Set_QueryMaxResults(fMaxResults);

      queryHelper.Set_QuerySelectColumns(GENERAL_COLUMNS + ',' + MUSIC_COLUMNS + ',' + IMAGE_COLUMNS);
      queryHelper.GenerateSQLFromUserQuery(PWideChar(fQuery),temp);
      wQuery := temp;

      queryHelper.Get_ConnectionString(temp);
      sTemp := temp;
      dataset := CreateComObject(CLASS_Recordset) as _Recordset;
      dataset.CursorLocation := adUseClient;
      dataset.Open(wQuery, stemp, adOpenForwardOnly, adLockReadOnly, adCmdText);
      dataset.Set_ActiveConnection(nil);
      bDatabaseFailed := false;
    end else
      bDatabaseFailed := true;
  end else
    bDatabaseFailed := true;
end;

I think it's all pretty self explanatory, fQuery is the query you want to execute.

Regards
Keith

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文