全文檢索搜尋,全文檢索搜尋引擎

來源:互聯網
上載者:User

全文檢索搜尋,全文檢索搜尋引擎

最近使用到了全文檢索搜尋功能,這裡對這一功能做個簡單介紹。

什麼叫做全文檢索搜尋呢,效果如下:

 

在搜尋方塊中輸入任意漢字或者片語,系統會自動在特定資料庫中檢索包含這個字或者片語的資訊。

我的實現過程是將這個功能單獨做成了一個控制項,使用的使用直接引用這個控制項,然後給資料來源賦值,並且重寫資料校正方法即可。

實現代碼如下:

<span style="white-space:pre"></span>protected override void AutoCompleteExtender_GetDataSource(string sPrefix, int iCount, object context, ref IEnumerable result){if (GetDataSource != null){var dataSource = GetDataSource(sPrefix, context);if (dataSource != null){var typeName = "";foreach (var data in dataSource){typeName = data.GetType().AssemblyQualifiedName;break;}result = new object[] { dataSource, typeName };}}}protected override string SaveClientState(){string result = string.Empty;if (this.SelectedData != null){result = JSONSerializerExecute.SerializeWithType(this.SelectedData);}return result;}protected override void LoadClientState(string clientState){if (!string.IsNullOrEmpty(clientState)){IList state = JSONSerializerExecute.Deserialize<IList>(clientState);this.SelectedData = state;}}/// <summary>/// 從用戶端回掉,驗證輸入的內容/// </summary>/// <param name="chkString">通過這個參數傳入的資訊進行資料校正</param>/// <param name="context">使用者佈建的上下文</param>[ScriptControlMethod]public virtual object[] CheckInput(string chkString, object context){if (ValidateInput != null){var data = ValidateInput(chkString, context);if (data.Count > 0){object[] result = new object[] { data, data[0].GetType().AssemblyQualifiedName };return result;}}return null;}
頁面javascript

//回掉後台驗證成功後調用這個進行處理,如果結果為1個則,直接建立SPAN並顯示,多個則彈出對話方塊讓使用者進行選擇_onValidateInvokeComplete: function (result) {this._setInvokingStatus(false);if (this._autoCompleteControl) {this._autoCompleteControl.set_isInvoking(false);}var obj = null;if (result && result.length == 2) {var data = result[0];var dataType = result[1];if (data.length > 1)//多於一個{for (var i = 0; i < data.length; i++) {data[i].__type = dataType;}var sFeature = "dialogWidth:500px; dialogHeight:300px;center:yes;help:no;resizable:yes;scroll:no;status:no";data.nameTable = $NT;data.keyName = this.get_dataKeyName();data.displayPropName = this.get_dataDisplayPropName();data.descriptionPropName = this.get_dataDescriptionPropName(); var resultStr = window.showModalDialog(this.get_selectObjectDialogUrl(), data, sFeature);obj = data[resultStr];}else {obj = data[0];obj.__type = dataType;}}if (obj != null) {this._tmpText = "";if (this._multiSelect == false) {this.set_selectedData(new Array());}if (this._allowSelectDuplicateObj || !this._checkDataInList(obj))Array.add(this.get_selectedData(), obj);this.notifyDataChanged();}this.setInputAreaText();},loadClientState: function (value) {if (value && value != "") {var state = Sys.Serialization.JavaScriptSerializer.deserialize(value);if (state != null && state.length) {this.set_selectedData(state);}}},saveClientState: function () {var state = "";var data = this.get_selectedData();for (var i = 0; i < data.length; i++) {data[i]._dataType = undefined;}if (data) {state = Sys.Serialization.JavaScriptSerializer.serialize(data);}return state;},dataBind: function () {this.setInputAreaText();},add_checkDataMask: function (handler) {this.get_events().addHandler("onCheckDataMask", handler);},remove_checkDataMask: function (handler) {this.get_events().removeHandler("onCheckDataMask", handler);}}

資料校正

protected IEnumerable CommonAutoCompleteWithSelectorControl1_GetDataSource(string chkstring, object context)        {            IEnumerable result = null;            if (chkstring.IsNotWhiteSpace())                result = OtherFieldData.SearchKeyPointInfoByCnName(chkstring);            return result;        }        protected IList CommonAutoCompleteWithSelectorControl1_ValidateInput(string chkstring, object context)        {            IList result = null;            if (chkstring.IsNotWhiteSpace())                result = OtherFieldData.SearchKeyPointInfoByCnName(chkstring);            return result;        }
     將資料顯示功能作為公用部分抽取出來,然後封裝起來,留下資料來源綁定借口和資料校正借口,以實現控制項的複用。


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.