在 C# 中进行 Windows 突出显示搜索

发布于 2024-07-19 02:51:22 字数 99 浏览 5 评论 0原文

是否可以通过c# 来实际进行Windows 搜索(您在Vista 中从带有突出显示的菜单中找到的搜索(例如您写“fire”并得到“firefox”))。

谢谢 :)

Would it be possible through c# to actually do a windows search (the one you find in Vista from the menu with higlighting (e.g you write 'fire' and get 'firefox')).

Thanks :)

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

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

发布评论

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

评论(2

迷途知返 2024-07-26 02:51:22

是的,这可以通过 Windows 桌面搜索 (WDS) API 实现。 您需要 SDK ,如果我没记错的话,它甚至提供了一个 .Net 程序集。 然后查看文档了解如何查询WDS索引。 这很简单,这是他们提供的 C# 示例:

OleDbConnection conn = new OleDbConnection(
    "Data Source=(local);Initial Catalog=Search.CollatorDSO;Integrated Security=SSPI;User ID=<username>;Password=<password>");

OleDbDataReader rdr = null;

conn.Open();

OleDbCommand cmd = new OleDbCommand("SELECT Top 5 System.ItemPathDisplay FROM SYSTEMINDEX", conn);

rdr = cmd.ExecuteReader();

while (rdr.Read())
{
    Console.WriteLine(rdr[0]);
}

rdr.Close();
conn.Close();

当我不久前在项目中使用它时,我使用的查询字符串是这样构建的:

CSearchManager SearchManager = new CSearchManager();
CSearchCatalogManager CatalogManager = SearchManager.GetCatalog("SystemIndex");
CSearchQueryHelper QueryHelper = CatalogManager.GetQueryHelper();
string connection_string = QueryHelper.ConnectionString;

然后进行简单的文件搜索:

QueryHelper.QueryWhereRestrictions = "AND scope='file:'";
QueryHelper.QuerySorting = "System.ItemNameDisplay ASC";
string sqlQuery = QueryHelper.GenerateSQLFromUserQuery(Filename);

从文档中您可以看到如何构建查询为您带来所需的结果。

现在,快速说明一下。 我能够构建 Vista 开始搜索克隆,但是,我首先扫描 Vista 存储开始菜单链接的位置中的链接文件 (%appdata%\Microsoft\Windows\Start Menu & C:\ProgramData\Microsoft\ Windows\开始菜单),然后在后台异步加载 WDS 结果,这比仅依赖 WDS 更好地复制开始搜索行为。

Yes, this is possible with the Windows Desktop Search (WDS) API. You'll need the SDK, which even provides a .Net assembly if I recall correctly. Then look at the documentation to learn how to query the WDS index. It's quite simple, here's the C# example they provide:

OleDbConnection conn = new OleDbConnection(
    "Data Source=(local);Initial Catalog=Search.CollatorDSO;Integrated Security=SSPI;User ID=<username>;Password=<password>");

OleDbDataReader rdr = null;

conn.Open();

OleDbCommand cmd = new OleDbCommand("SELECT Top 5 System.ItemPathDisplay FROM SYSTEMINDEX", conn);

rdr = cmd.ExecuteReader();

while (rdr.Read())
{
    Console.WriteLine(rdr[0]);
}

rdr.Close();
conn.Close();

When I used this in a project awhile back, the query string I used was built something like this:

CSearchManager SearchManager = new CSearchManager();
CSearchCatalogManager CatalogManager = SearchManager.GetCatalog("SystemIndex");
CSearchQueryHelper QueryHelper = CatalogManager.GetQueryHelper();
string connection_string = QueryHelper.ConnectionString;

Then to do a simple file search:

QueryHelper.QueryWhereRestrictions = "AND scope='file:'";
QueryHelper.QuerySorting = "System.ItemNameDisplay ASC";
string sqlQuery = QueryHelper.GenerateSQLFromUserQuery(Filename);

From the documentation you can see how to build queries that get you the results you need.

Now, a quick note. I was able to build a Vista Start Search clone, however, I did it by first scanning link files in the places where Vista stores Start Menu links (%appdata%\Microsoft\Windows\Start Menu & C:\ProgramData\Microsoft\Windows\Start Menu), then asynchronously loading WDS results in the background, which replicates Start Search behavior better than relying solely on WDS.

清风夜微凉 2024-07-26 02:51:22

Windows 搜索使用索引,通过在搜索字段中的文本更新时查询索引来获得结果。 为了使其工作,引擎必须能够非常快速地返回结果,因此对于查找非常有效的集合是一个好主意。

然后,当搜索框中的文本发生更改时,您可以查询哈希表。

Windows search uses an index to achieve the results by querying the index as the text in the search field is updated. In order for this to work the engine must be capable of returning results very quickly so a collection which is very efficient for lookups is a good idea.

You would then query the hashtable when the text in the search box changes.

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