是否有一种方法来调用SearchIndexer与参数?(或者有其他方法来完成标题所说的?)
我试着看了各种MSDN文章,但他们似乎都建议我使用库。但是当我运行搜索时,它运行了,我没有下载任何类型的库。
在XP时代,您可以转到索引服务属性并执行查询。我在Windows 7中没有看到。
谢谢。
下面是一个示例查询。请注意,它不使用Windows 7 SDK。
using System;
using System.Data.OleDb;
namespace FileSearchingExe
{
class MainProgram
{
static void Main(string[] args)
{
string sqlQuery = "SELECT TOP 10 "System.ItemPathDisplay", "System.DateModified" FROM "SystemIndex" WHERE CONTAINS(*,'"urSearchWord*"') " +
"AND scope='file:C:/SomeFolder' ORDER BY System.ItemPathDisplay DESC"; //note the forwardslash in the scope parameter.
// --- Perform the query ---
// create an OleDbConnection object which connects to the indexer provider with the windows application
using (System.Data.OleDb.OleDbConnection conn = new OleDbConnection("provider=Search.CollatorDSO.1;EXTENDED PROPERTIES="Application=Windows""))//queryHelper.ConnectionString))
{
// open the connection
conn.Open();
// now create an OleDB command object with the query we built above and the connection we just opened.
using (OleDbCommand command = new OleDbCommand(sqlQuery, conn))
{
// execute the command, which returns the results as an OleDbDataReader.
using (OleDbDataReader WDSResults = command.ExecuteReader())
{
while (WDSResults.Read())
{
// col 0 is our path in display format
Console.WriteLine("{0}, {1}", WDSResults.GetString(0), WDSResults.GetDateTime(1).ToString());
}
}
}
}
}
}
}
然而,它改编自Windows 7 SDK中的DSearch示例。((SDK) winui WindowsSearch DSearch样品。[SDK]通常是"C:Program FilesMicrosoft SDK Windowsv7.1"
注意,如果您使用SDK的ISearchQueryHelper
,可以使SQL查询更容易(但在我看来稍微不那么灵活)。要使用这个类和相关的类,您需要引用Microsoft.Search.Interop
,它不作为dll包含在Windows 7 SDK中。然而,您可以通过使用TlbImp.exe(类型库导入器,在[SDK]bin中)在SearchAPI上以dll形式获取它。tlb文件(在[SDK]Lib)。
我希望这篇文章能帮助那些需要在Windows 7或更高版本中以编程方式连接到Windows搜索的人。