使在C#中的窗口亮点搜索 [英] make a windows highlight search in c#

查看:189
本文介绍了使在C#中的窗口亮点搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有可能通过C#来真正地执行Windows搜索(一个你从higlighting菜单在Vista中找到(比如你写'火',让'火狐'))。

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')).

感谢:)

推荐答案

是的,这是可能与Windows桌面搜索(WDS)API。你需要的 SDK ,它甚至还提供了.NET程序集,如果我没有记错。再看看文档,了解如何查询WDS索引。这很简单,这里是他们提供的C#示例:

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.

现在,快速注意到。我是能够建立一个Vista的开始搜索克隆,但是,我做到了通过在Vista中的商店开始菜单链接(%APPDATA%\Microsoft\Windows\Start菜单和放大器的地方第一次扫描链接文件; C:\ ProgramData\Microsoft\Windows\Start菜单),然后异步加载WDS导致在后台,它复制开始搜索行为不是单纯的依靠WDS更好。

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.

这篇关于使在C#中的窗口亮点搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆