Windows Desktop Search(WDS) 3.0 in .NET

  • 5003
  • 0
  • C#
  • 2008-07-22

Windows Desktop Search(WDS) 3.0 in .NET

WDS(桌面搜尋)是Microsoft新推出的搜尋引擎,好用在於能夠尋找檔案內文資料,不過需要有相對應的應用軟體(如果要查word,就必需安裝word),而且還可以檢視縮圖,相當的好用。

前陣子利用了這套軟體完成了搜尋上傳檔案的功能:p

 1.連線字串:

Provider=Search.CollatorDSO;Extended Properties='Application=Windows';

 

2.在WDS中設定要建立索引的目錄:

image

3.程式碼:

*需要特別注意的是SCOPE的設定,也就是索引建立的位置。

 

private String desktopSearching(string fileContent)
{
	string fileName = "";
	List<string> file = new List<string>();
	string searchDirPath = @"file:" + Server.MapPath("../Upload");
	//取得檔案列表
	string strQuery = String.Format(@"SELECT System.Search.Rank, System.ItemNameDisplay, System.DateModified, System.Size, System.Title, System.ApplicationName, System.ItemUrl FROM systemindex WHERE FREETEXT(*, '""{0}""') AND ""SCOPE""='{1}'", fileContent, searchDirPath);
	DataTable dt = new DataTable();
	OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["FullTextConnectionString"].ConnectionString);
	conn.Open();
	OleDbDataAdapter cmd = new OleDbDataAdapter(strQuery, conn);
	cmd.Fill(dt);
	conn.Close();
	
	for (int i = 0; i < dt.Rows.Count; i++)
	{
		file.Add(String.Format("'{0}'",dt.Rows[i][1].ToString()));
	}
	string[] items = file.ToArray();
	if (file.Count > 0)
		fileName = String.Format(" AND F_NAME IN ({0})", String.Join(",", items));
	else
		fileName = " AND F_NAME IN ('')";
	return fileName;
}

PS:如果有需要詳細的檔案資訊可查詢 Shell Properties(MSDN)

DotBlog 的標籤:,