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).
我正在寻找一个使用Windows搜索获得全文搜索结果的代码(默认情况下应该可以在Vista,7和8中使用)。
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.
我在这里找到了一些问题,并在msdn上发现了一些文本,但是它们都没有一些确切的代码可行。我尝试过使用Windows API Code Pack(因为它被称为Windows搜索的一个接口),但它只返回文件名的结果,而不是全文。
2 个解决方案
#1
27
Here is the code that does work - in example I made it to search for the word "dummy" in the desktop folder:
以下是可行的代码 - 例如,我在桌面文件夹中搜索“dummy”一词:
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();
#2
1
Take a look at the DSearch example. Windows Search Code Samples
看一下DSearch示例。 Windows搜索代码示例
That's what you want.
那就是你想要的。
#1
27
Here is the code that does work - in example I made it to search for the word "dummy" in the desktop folder:
以下是可行的代码 - 例如,我在桌面文件夹中搜索“dummy”一词:
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();
#2
1
Take a look at the DSearch example. Windows Search Code Samples
看一下DSearch示例。 Windows搜索代码示例
That's what you want.
那就是你想要的。