How-to: Query Vista Search From Your App
- Posted: Jun 20, 2006 at 1:39 PM
- 28,839 Views
- 12 Comments
Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
Right click “Save as…”
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation,
please create a new thread in our Forums,
or
Contact Us and let us know.
Follow the Discussion
Oops, something didn't work.
What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in. You need to be signed in to Channel 9 to use this feature.What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in and view them all on your notifications page.sign up for email notifications?
Here are a few snippets of relevant source code from the demo:
public partial class Window1 : Window
{
private ImageCollection _foundImages = null;
private string[] _exifProperties = new string[] {
"System.Photo.CameraManufacturer", "System.Photo.CameraModel",
"System.Photo.FNumber", "System.Photo.ExposureTime", "System.Photo.FocalLength",
"System.Photo.ExposureBias", "System.Photo.MeteringMode",
"System.Photo.ColorSpace"};
private string[] _generalProperties = new string[] {
"System.Author", "System.Keywords", "System.File.Description"};
private void OnSearch(object sender, RoutedEventArgs e)
{
string indexerConnString = "provider=Search.CollatorDSO.1;EXTENDED PROPERTIES=\"Application=Windows\"";
using (OleDbConnection conn = new OleDbConnection(indexerConnString))
{
conn.Open();
string keywordValue = SearchBox.Text;
_foundImages.Clear();
GetImageFileResults(keywordValue, conn);
ImageListBox.DataContext = _foundImages;
}
}
private void GetImageFileResults(string keywordValue, OleDbConnection conn)
{
try
{
System.Collections.Hashtable checkNames = new System.Collections.Hashtable();
string sqlString = "Select \"System.Title\", " +
"\"System.DisplayFolder\", \"System.DisplayName\" " +
"FROM systemindex..scope() " +
"WHERE FREETEXT(\"System.CanonicalType\", 'JPG') "/* +
"AND CONTAINS(\"System.Path\", 'file:')"*/;
if (!string.IsNullOrEmpty(keywordValue))
{
sqlString += " AND (\"System.Keywords\" = SOME ARRAY ['" + keywordValue + "'])";
}
OleDbCommand cmd = new OleDbCommand(sqlString, conn);
using (OleDbDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
ImageInfo imageInfo = new ImageInfo();
imageInfo.Title = reader.GetString(0);
string folder = reader.GetString(1);
string name = reader.GetString(2);
// workaround to ignore non-files
if (folder.Length < 2 || folder[1] != ':')
continue;
imageInfo.ImagePath = System.IO.Path.Combine(
folder, name);
// Workaround to ignore peculiar files on non-existent
// volumes that build 5365 seems to return.
if (!System.IO.File.Exists(imageInfo.ImagePath))
continue;
if (imageInfo.ImagePath.Contains("Temporary Internet Files"))
continue;
if (checkNames.ContainsKey(imageInfo.Title))
{
int index = (int)checkNames[(string)imageInfo.Title];
if (_foundImages[index] != null)
{
if (_foundImages[index].Variations == null)
{
ImageCollection variationCollection = new ImageCollection();
variationCollection.Add(imageInfo);
_foundImages[index].Variations = variationCollection;
}
else
{
_foundImages[index].Variations.Add(imageInfo);
}
}
}
else
{
imageInfo.Variations = new ImageCollection();
imageInfo.Variations.Add(imageInfo);
int currentIndex = _foundImages.Count;
checkNames.Add(imageInfo.Title, currentIndex);
_foundImages.Add(imageInfo);
}
}
}
}
catch (OleDbException)
{
// Not finding any results is ok.
}
Btw. Is there a way to get the different columns of a document? I mean in the example with the pictures it is great, but for other documents?
Sheva
{"The ICommandWithParameters interface is not supported by the 'Search.CollatorDSO.1' provider. Command parameters are unsupported with the current provider."}
Copy and past his second post?
btw, how to extract/change metadata from files in Vista?
EDIT: nevermind
The query is searching in the Windows Index database (FROM SYSTEMINDEX..SCOPE).
If, let's say, I don't have my D: drive indexed, how do I perform a search on this drive as well. There is possible to have a syntax like this:
SELECT "System.FileName" FROM "D:\"..etc?
Thanks,
Alin
I tried with a similar code. I was able to get the column name with reader.GetName(0) but the result set was not found. that is , when i say reader.GetString(0), i get the error saying there is no data in the row/column. i tried out with different keywords but still the same result. I also tried using the same keyword in the WDS, then i got some results. My prob is i am not able to get the same result programmatically. The query i am using is:
SELECT DocTitle FROM systemindex..scope() WHERE CONTAINS('" + "Choose" + "')".
here i am searching for the keyword "Choose".
can neone pls help me on this..
It's not working with me. I wonder what is wrong with my computer. Steam Generator Irons
@JoeySachs that's becuase you have windows 7 not windows vista maybe. Mobile Phone Recycling
Remove this comment
Remove this thread
close