// 填充列表 // parameters: // strReason 检索过程注释 // hit_param 携带了参数,但是要被复制后,将新对象进入队列 int FillList( string strFullPath, OneHit hit_param, string strWeightList, /* string strSearchStyle, int nCurWeight, int nThreshold, string strReason, * */ out string strError) { strError = ""; // Color color = Color.FromArgb(255,255,200); // string strNumber = ""; OneHit hit = new OneHit(hit_param); /* hit.From = hit_param.From; hit.Key = hit_param.Key; hit.SearchStyle = hit_param.SearchStyle; hit.Weight = hit_param.Weight; * */ ItemInfo info = null; string strPath = ResPath.GetReverseRecordPath(strFullPath); // 根据path寻找已经存在的item ListViewItem item = (ListViewItem)m_tableItem[strPath]; if (item == null) { item = new ListViewItem(strPath, 0); /* strNumber = Convert.ToString(nCurWeight); if (nCurWeight >= nThreshold) { strNumber = "*" + strNumber; item.BackColor = color; } item.SubItems.Add(strNumber); item.SubItems.Add(strReason); * */ this.listView_browse.Items.Add(item); m_tableItem[strPath] = item; info = new ItemInfo(); item.Tag = info; info.Hits.Add(hit); } else { /* // 把已经存在的weight值加上本次新值 if (nCurWeight != 0) { string strExistWeight = item.SubItems[1].Text; // 去掉可能存在的引导'*'字符 if (strExistWeight.Length > 0 && strExistWeight[0] == '*') strExistWeight = strExistWeight.Substring(1); int nOldValue = 0; try { nOldValue = Convert.ToInt32(strExistWeight); } catch { } int nValue = nOldValue + nCurWeight; strNumber = Convert.ToString(nValue); if (nValue >= nThreshold) { strNumber = "*" + strNumber; if (nOldValue < nThreshold) item.BackColor = color; } item.SubItems[1].Text = strNumber; } string strOldReason = item.SubItems[2].Text; if (strOldReason != "") item.SubItems[2].Text += ";"; item.SubItems[2].Text += strReason; */ info = (ItemInfo)item.Tag; Debug.Assert(info != null, ""); info.Hits.Add(hit); } int nHitIndex = GetHitIndex(info.Hits, hit.From); Debug.Assert(nHitIndex >= 0, ""); // 获得具体一次命中的weight值 // 如果列表中的数字不够nHitIndex那么多个,则取最后一个的值 // parameters: // strWeightList 原始的weight属性定义,形态为"100,50,20"或者"50" // nHitIndex 当前命中的这一次为总共命中的多少次 hit.Weight = GetWeight(strWeightList, nHitIndex); return 0; }
public OneHit(OneHit hit_param) { this.From = hit_param.From; this.Key = hit_param.Key; this.SearchStyle = hit_param.SearchStyle; this.Weight = hit_param.Weight; }
// 针对一个from进行检索 int SearchOneFrom( string strServerUrl, string strDbName, string strFrom, string strKey, string strSearchStyle, string strWeight, // int nThreshold, long nMax, out string strError) { this.SearchPanel.BrowseRecord -= new BrowseRecordEventHandler(BrowseRecordNoColsCallBack); this.SearchPanel.BrowseRecord += new BrowseRecordEventHandler(BrowseRecordNoColsCallBack); try { /* if (strSearchStyle == "") strSearchStyle = "exact"; * */ /* this.m_strSearchStyle = strSearchStyle; // 2009/3/2 this.m_nCurWeight = nWeight; // 为事件处理函数所预备 this.m_nThreshold = nThreshold; * */ // 2007/4/5 改造 加上了 GetXmlStringSimple() string strQueryXml = "<target list='" + StringUtil.GetXmlStringSimple(strDbName + ":" + strFrom) // 2007/9/14 + "'><item><word>" + StringUtil.GetXmlStringSimple(strKey) + "</word><match>" + GetFirstQuerySearchStyle(strSearchStyle) + "</match><relation>=</relation><dataType>string</dataType><maxCount>" + Convert.ToString(nMax) + "</maxCount></item><lang>zh</lang></target>"; this.SearchPanel.BeginLoop("正在针对库 '" + strDbName + "' 检索 '" + strKey + "'"); this.m_hit = new OneHit(); this.m_hit.Key = strKey; this.m_hit.From = strFrom; this.m_hit.SearchStyle = strSearchStyle; this.m_strWeightList = strWeight; // this.m_strSearchReason = "key='" + strKey + "', from='" +strFrom + "', weight=" + Convert.ToString(nWeight); long lRet = 0; try { // return: // -2 用户中断 // -1 一般错误 // 0 未命中 // >=1 正常结束,返回命中条数 lRet = this.SearchPanel.SearchAndBrowse( strServerUrl, strQueryXml, false, out strError); return (int)lRet; } finally { this.SearchPanel.EndLoop(); } } finally { this.SearchPanel.BrowseRecord -= new BrowseRecordEventHandler(BrowseRecordNoColsCallBack); } }