Windows搜索 - 在C#全文搜索 [英] Windows search - full text search in c#

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

问题描述

我要寻找一个code,获取使用Windows搜索的全文搜索结果(应该在Vista中,7可和8默认情况下)。

I am looking for a code that gets results of full text search using Windows search (it should be available in Vista, 7 and 8 by default).

我已经在这里找到了一些问题,有些文章在MSDN上,但他们都没有确切一些code,它的工作原理。我曾尝试使用Windows API code包(因为它被提及的接口,Windows搜索中的一个),但它返回的结果只为文件名,而不是全文。

I have found some questions here and some texts on msdn, but none of them have some exact code that works. I have tried with Windows API Code Pack (as it is mentioned as one of the interfaces to Windows Search), but it returns results only for file names, not for full text.

推荐答案

下面是code,做的工作 - 例如,在我去到搜索词在桌面文件夹假:

Here is the code that does work - in example I made it to search for the word "dummy" in the desktop folder:

string connectionString = "Provider=Search.CollatorDSO;Extended Properties=\"Application=Windows\"";
OleDbConnection connection = new OleDbConnection(connectionString);

string query = @"SELECT System.ItemName FROM SystemIndex " +
   @"WHERE scope ='file:" + System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "' and FREETEXT('dummy')";
OleDbCommand command = new OleDbCommand(query, connection);
connection.Open();

List<string> result = new List<string>();

OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
    result.Add(reader.GetString(0));
}

connection.Close();

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

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