Stellen Sie eine Verbindung zur Windows -Desktop -Suche auf dem Remote -Computer her

StackOverflow https://stackoverflow.com/questions/8340410

  •  26-10-2019
  •  | 
  •  

Frage

Ich habe ein Programm geerbt, das Windows Desktop Search (WDS) auf einem Remote -Server verwendet, um indizierte PDFSS zu durchsuchen. Der ursprüngliche Codierer hat den größten Teil des Codes verwendet, um die Programmierung von VB 6 -Style -Style zu erhalten. Wenn er auf die Windows -Desktop -Suche zugegriffen hat, verwendet er ADO -Datensatz -Objekte.

Leider funktionieren die Code -Samples von Microsoft nicht für mich, da ich immer wieder einen Fehler bekomme: "iErrorinfo.getDescription ist mit E_FAIL (0x80004005) fehlgeschlagen."

Hier ist der Code, den ich verwenden möchte, und die Abfrage, die ich sende:

Anfrage:

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();

Der Fehler tritt in der letzten Zeile auf. Jede Hilfe und/oder Gedanken wären sehr geschätzt. Vielen Dank für Ihre Zeit.

Waten

War es hilfreich?

Lösung

Ich frage mich, ob es Ihre Frage ist (falsche Zitate an den falschen Stellen). Das ist meins:

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

Andere Tipps

Ich denke, Ihr Befehl ist ein Timing! Fügen Sie die Zeile wie folgt hinzu:

// 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.

Die Standardverbindung beträgt nur 30 Sekunden. Wenn Sie also mehr Zeit hinzufügen, kann die Verbindung geöffnet bleiben und die Aufgabe erledigen. Wenn das Befehlszeitlimit überschritten wird, schlägt das Gleichgewicht der Suche fehl. Deshalb ist der Fehler "getDescription" fehlgeschlagen.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top