Windows Search SDK

Setup Environment
1. Install Microsoft Windows SDK

2. Install Microsoft Windows Search SDK

How to Add Indexing Location

CSearchManager searchManager = new CSearchManager();
CSearchCatalogManager catalogManager = searchManager.GetCatalog("SystemIndex");
CSearchCrawlScopeManager crawlScopeManager = catalogManager.GetCrawlScopeManager();

crawlScopeManager.AddUserScopeRule(@"file:///D:\My Documents\", 1, 1, 1);
crawlScopeManager.SaveAll();

catalogManager.Reindex();

How to Search Indexed Location

CSearchManager searchManager = new CSearchManager();
CSearchCatalogManager catalogManager = searchManager.GetCatalog("SystemIndex");

CSearchQueryHelper queryHelper = catalogManager.GetQueryHelper();
queryHelper.QueryWhereRestrictions = @"AND scope='file:D:\My Documents\'";

string sql = queryHelper.GenerateSQLFromUserQuery("Hello World");

using (OleDbConnection conneciton = new OleDbConnection(queryHelper.ConnectionString))
{
	using (OleDbCommand command = new OleDbCommand(sql, conneciton))
	{
		conneciton.Open();
		using (OleDbDataReader dataReader = command.ExecuteReader())
		{
			while (dataReader.Read())
			{
				Console.WriteLine(dataReader[0]);
			}
		}
	}
}

References

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s