/// <summary> /// 检索并获取浏览结果 /// </summary> /// <param name="strServerUrl">服务器URL。如果==""或者==null,表示用this.ServerUrl</param> /// <param name="strQueryXml"></param> /// <param name="bGetBrowseCols">是否要获得浏览列</param> /// <param name="strError"></param> /// <returns>-2 用户中断;-1 一般错误;0 未命中; >=1 正常结束,返回命中条数</returns> public long SearchAndBrowse( string strServerUrl, string strQueryXml, bool bGetBrowseCols, out string strError) { strError = ""; if (strServerUrl == null || strServerUrl == null) strServerUrl = this.ServerUrl; RmsChannel channelSave = channel; channel = Channels.GetChannel(strServerUrl); if (channel == null) { strError = "get channel error"; return -1; } try { // 检索 long lRet = channel.DoSearch(strQueryXml, "default", "", // strOuputStyle out strError); if (lRet == -1) return -1; if (lRet == 0) return 0; // 循环获取结果 long nHitCount = lRet; long nStart = 0; long nCount = 10; long nIndex = 0; for(;;) { Application.DoEvents(); // 出让界面控制权 if (stop != null) { if (stop.State != 0) { strError = "用户中断"; return -2; } } List<string> aPath = null; ArrayList aLine = null; if (bGetBrowseCols == false) { lRet = channel.DoGetSearchResult( "default", nStart, nCount, "zh", this.stop, out aPath, out strError); } else { lRet = channel.DoGetSearchFullResult( "default", nStart, nCount, "zh", this.stop, out aLine, out strError); } if (lRet == -1) { strError = "获取检索结果时出错: " + strError; return -1; } if (bGetBrowseCols == false) nStart += aPath.Count; else nStart += aLine.Count; // 触发事件 if (this.BrowseRecord != null) { int nThisCount = 0; if (bGetBrowseCols == false) nThisCount = aPath.Count; else nThisCount = aLine.Count; for (int j = 0; j < nThisCount; j++) { BrowseRecordEventArgs e = new BrowseRecordEventArgs(); e.SearchCount = nHitCount; e.Index = nIndex ++; if (bGetBrowseCols == false) { e.FullPath = strServerUrl + "?" + (string)aPath[j]; } else { string[] cols = (string[])aLine[j]; e.FullPath = strServerUrl + "?" + cols[0]; // 丢掉第一列 e.Cols = new string[Math.Max(cols.Length - 1, 0)]; Array.Copy(cols, 1, e.Cols, 0, cols.Length - 1); } this.BrowseRecord(this, e); if (e.Cancel == true) { if (e.ErrorInfo == "") strError = "用户中断"; else strError = e.ErrorInfo; return -2; } } } if (nStart >= nHitCount) break; // 2006/9/24 add 防止nStart + nCount越界 if (nStart + nCount > nHitCount) nCount = nHitCount - nStart; else nCount = 10; } return nHitCount; } finally { channel = channelSave; } }