Hi there! Would it be possible through c# to actually do a windows search (the one you find in Vista from the menu with higlighting (e.g you write 'fire' and get 'firefox')).
Thanks :)
-
Windows search uses an index to achieve the results by querying the index as the text in the search field is updated. In order for this to work the engine must be capable of returning results very quickly so a collection which is very efficient for lookups is a good idea.
You would then query the hashtable when the text in the search box changes.
-
Yes, this is possible with the Windows Desktop Search (WDS) API. You'll need the SDK, which even provides a .Net assembly if I recall correctly. Then look at the documentation to learn how to query the WDS index. It's quite simple, here's the C# example they provide:
OleDbConnection conn = new OleDbConnection( "Data Source=(local);Initial Catalog=Search.CollatorDSO;Integrated Security=SSPI;User ID=<username>;Password=<password>"); OleDbDataReader rdr = null; conn.Open(); OleDbCommand cmd = new OleDbCommand("SELECT Top 5 System.ItemPathDisplay FROM SYSTEMINDEX", conn); rdr = cmd.ExecuteReader(); while (rdr.Read()) { Console.WriteLine(rdr[0]); } rdr.Close(); conn.Close();
When I used this in a project awhile back, the query string I used was built something like this:
CSearchManager SearchManager = new CSearchManager(); CSearchCatalogManager CatalogManager = SearchManager.GetCatalog("SystemIndex"); CSearchQueryHelper QueryHelper = CatalogManager.GetQueryHelper(); string connection_string = QueryHelper.ConnectionString;
Then to do a simple file search:
QueryHelper.QueryWhereRestrictions = "AND scope='file:'"; QueryHelper.QuerySorting = "System.ItemNameDisplay ASC"; string sqlQuery = QueryHelper.GenerateSQLFromUserQuery(Filename);
From the documentation you can see how to build queries that get you the results you need.
Now, a quick note. I was able to build a Vista Start Search clone, however, I did it by first scanning link files in the places where Vista stores Start Menu links (%appdata%\Microsoft\Windows\Start Menu & C:\ProgramData\Microsoft\Windows\Start Menu), then asynchronously loading WDS results in the background, which replicates Start Search behavior better than relying solely on WDS.
Johannes : Thanks :) I just wonder what is the field: User ID=;Password= . My username and password on my system/windows-account? Thx
0 comments:
Post a Comment