简体   繁体   English

连接到远程计算机上的Windows桌面搜索

[英]Connect to Windows Desktop Search on Remote Machine

I inherited a program which is using Windows Desktop Search (WDS) on a remote server to search indexed PDFss. 我继承了一个程序,该程序正在远程服务器上使用Windows桌面搜索(WDS)搜索索引的PDFss。 The original coder did most of the code using VB 6 style programming, so when he accessed the Windows Desktop Search, he uses ADO Recordset objects. 原始编码员使用VB 6样式编程来完成大多数代码,因此当他访问Windows桌面搜索时,他使用ADO Recordset对象。

Unfortunately, the code samples from Microsoft aren't working for me, as I keep getting an error saying "IErrorInfo.GetDescription failed with E_FAIL(0x80004005)." 不幸的是,来自Microsoft的代码示例对我不起作用,因为我不断收到错误消息“IErrorInfo.GetDescription因E_FAIL(0x80004005)而失败”。

Here is the code I am trying to use and the query I am sending: 这是我要使用的代码和正在发送的查询:

Query: 查询:

SELECT "System.ItemPathDisplay" 
FROM "server"."SystemIndex" 
WHERE CONTAINS(*,'"widget*" AND "foo*"',1033) 
AND ("SCOPE" = 'file://server/networkshare') 
AND Contains(System.ItemType,'"txt"')  
ORDER BY System.ItemPathDisplay ASC 

Code: 码:

// Thie uses SearchAPI interop assembly
CSearchManager manager = new CSearchManager();

// the SystemIndex catalog is the default catalog that windows uses
CSearchCatalogManager catalogManager = manager.GetCatalog("SystemIndex");

// get the ISearchQueryHelper which will help us to translate AQS --> SQL necessary to query the indexer
CSearchQueryHelper queryHelper = catalogManager.GetQueryHelper();

queryHelper.QueryWhereRestrictions = string.Format("AND (\"SCOPE\" = 'file://{0}/{1}')", "server", "networkshare");

// set the number of results we want
if (maxRows > 0)
{
   queryHelper.QueryMaxResults = maxRows;
}

// set the columns we want
queryHelper.QuerySelectColumns = "System.ItemPathDisplay";

if (sortCol != "System.ItemPathDisplay")
{
   // unless a sort column is specified in which case we will add that column too
   queryHelper.QuerySelectColumns = "System.ItemPathDisplay," + sortCol;
}

// if we have a file pattern 
if (filePattern.Length > 0)
{
   // then we add file pattern restriction, mapping cmd line style wildcards to SQL style wildcards
   string pattern = filePattern;
   pattern = pattern.Replace("*","%");
   pattern = pattern.Replace("?", "_");

   if (pattern.Contains("%") || pattern.Contains("_"))
   {
      queryHelper.QueryWhereRestrictions += " AND System.FileName LIKE '" + pattern + "' ";
   }
   else
   {
      // if there are no wildcards we can use a contains which is much faster as it uses the index
      queryHelper.QueryWhereRestrictions += " AND Contains(System.FileName, '" + pattern + "') ";
   }
}

// if we have file extensions
if (exts != null)
{
   // then we add a constraint against the System.ItemType column in the form of
   // Contains(System.ItemType, '.txt OR .doc OR .ppt') 
   queryHelper.QueryWhereRestrictions += " AND Contains(System.ItemType,'";
   bool fFirst = true;
   foreach (string ext in exts)
   {
      if (!fFirst)
      {
         queryHelper.QueryWhereRestrictions += " OR ";
      }
      queryHelper.QueryWhereRestrictions += "\""+ext+"\"";
      fFirst = false;
   }
   queryHelper.QueryWhereRestrictions += "') ";
}

// and we always have a sort column and direction, either the default or the one specified in the parameters
// so append an ORDER BY statement for it
queryHelper.QuerySorting = sortCol + " " + sortDirection;

// Generate SQL from our parameters, converting the userQuery from AQS->WHERE clause
string sqlQuery = queryHelper.GenerateSQLFromUserQuery(userQuery);

sqlQuery = sqlQuery.Replace("FROM \"SystemIndex\"", string.Format("FROM \"{0}\".\"SystemIndex\"", "server"));

// if they asked to show the sqlQuery
if (fShowQuery)
{
   // then output it to the console
   Console.WriteLine(sqlQuery);
}

// --- Perform the query ---
// create an OleDbConnection object which connects to the indexer provider with the windows application
System.Data.OleDb.OleDbConnection conn = new OleDbConnection(queryHelper.ConnectionString);

// open it
conn.Open();

// now create an OleDB command object with the query we built above and the connection we just opened.
OleDbCommand command = new OleDbCommand(sqlQuery, conn);

// execute the command, which returns the results as an OleDbDataReader.
OleDbDataReader WDSResults = command.ExecuteReader();

The error happens on the last line. 错误发生在最后一行。 Any help and/or thoughts would be greatly appreciated. 任何帮助和/或想法将不胜感激。 Thanks for your time. 谢谢你的时间。

Wade

I wonder if it's your Query (wrong quotes in the wrong places). 我想知道这是否是您的查询(在错误的位置使用了错误的引号)。 This is mine: 这是我的:

SELECT System.ItemName, System.ItemPathDisplay, System.ItemType, 
       System.Search.Rank 
FROM servername.SYSTEMINDEX 
WHERE SCOPE='file://servername/WebContent' 
AND System.ItemType <> 'Directory' 
AND ( 
   CONTAINS(System.Search.Contents,'*asdf*') 
   OR
   CONTAINS(System.FileName,'*asdf*')
)

I think your command is timing out! 我认为你的命令已超时了! Try adding the line as follows: 尝试添加以下行:

// now create an OleDB command object with the query we built above and the connection we just opened.
OleDbCommand command = new OleDbCommand(sqlQuery, conn);
command.commandTimeout=0; <-- This will keep the connection open until it completes.

The default connection is only 30 seconds, so adding more time will allow the connection to remain open and complete the task. 默认连接只有30秒,因此增加时间将使连接保持打开状态并完成任务。 If the command timeout is exceeded then the balance of the lookup fails, hence why you get the error "GetDescription" failed. 如果超过了命令超时,则查找平衡将失败,因此,为什么您会收到错误“ GetDescription”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM