Today I received a new task: create a simple aspx page using the Microsoft index server to query. I didn't use it before, so I firstly search some info with the help of google and codeproject website.
According to the resources on the internet, to create search pages and result pages there are two ways to do this. One is using use fairly simple IDQ and HTX files. The other one is using Asp.net with the help of ADO.Net.
With Index server, developers could query index server in the same manner that they would query a database.
Some important things to consider basically:
1 consider what document properties and meta-data the user can search
2 how those results are to be displayed.
3 to limit their search to a particular scope
4 how results are sorted and how many appear on a page
In fact, these four points are so simple to design. With the help of TextBox, Button, DataGrid control, you can do it easily. Here is my Demo code.
Before running the code, firstly you should configure the Index Service.
1. Click Start, and then click Control Panel.
2. Double-click Administrative Tools.
3. Click Computer management.
4. Expand Services and Applications.
The detailed operation steps is from Microsoft KB .
說了半天英文,好累。說說這個功能的核心,這句話“developers could query index server in the same manner that they would query a database”我最最關心了。什麼意思呢?
1、按照與關聯式資料庫相同的訪問方式,那麼資料庫在哪裡?
看Data Source='" + strCatalog + "'"; // 就是資料來源。
資料來源的訪問方式 Provider=MSIDXS.1;
strCatalog 就是你在Index Service 下看到的System, Web ,這個是作業系統已經建立好的目錄,當然你還可以建立自己的Catalog,就相當於建立一個資料庫。
2、查詢什麼,那麼查詢語句如何寫呢。
看看定義的strQuery ,我的理解好像就是這個資料庫裡有1張表,有這些固定的欄位,例如檔案名稱、路徑、大小等資訊,使用了一個SQL Server自建的函數SCOPE()等等,誰有相關的詳細資料,可以共用共用。
string strCatalog,strQuery,connString ;
strCatalog = "TestCatalog";
strQuery = "Select DocTitle,Filename,Size,PATH,URL from SCOPE() where FREETEXT('" +TextBox1.Text.Trim()+ "')";
connString = "Provider=MSIDXS.1;Integrated Security .='';Data Source='" + strCatalog + "'";
OleDbConnection1.ConnectionString = connString;
OleDbDataAdapter OleDbDataAdapter1 = new OleDbDataAdapter(strQuery,OleDbConnection1);
參考資料:
http://support.microsoft.com/kb/820105/EN-US/
http://support.microsoft.com/kb/308202
http://www.codeproject.com/aspnet/search.asp#xx982415xx