Esempio n. 1
0
        // 实现IComparable接口的CompareTo()方法,
        // 根据ID比较两个对象的大小,以便排序,
        // 按右对齐方式比较
        // obj: An object to compare with this instance
        // 返回值 A 32-bit signed integer that indicates the relative order of the comparands. The return value has these meanings:
        // Less than zero: This instance is less than obj.
        // Zero: This instance is equal to obj.
        // Greater than zero: This instance is greater than obj.
        // 异常: ArgumentException,obj is not the same type as this instance.
        public override int CompareTo(object obj)
        {
            ClientRecordItem item = (ClientRecordItem)obj;

            return(String.Compare(this.Path, item.Path, true));
        }
Esempio n. 2
0
		// 检索文章
		// return:
		//		-1	error
		//		其他 命中数
		public int Search(
			string strServerUrl,
			string strQueryXml,
			RmsChannelCollection Channels,
			string strLang,
			out string strError)

		{
			strError = "";

			string strMessage = "";

			// 加写锁
			this.m_lock.AcquireWriterLock(m_nLockTimeout);
			try 
			{

				this.File.Clear();	// 清空集合


				//if (page.Response.IsClientConnected == false)	// 灵敏中断
				//	return -1;

				RmsChannel channel = Channels.GetChannel(strServerUrl);
				Debug.Assert(channel != null, "Channels.GetChannel 异常");

				strMessage += "--- begin search ...\r\n";

				DateTime time = DateTime.Now;

				//if (page.Response.IsClientConnected == false)	// 灵敏中断
				//	return -1;

				long nRet = channel.DoSearch(strQueryXml,
                    "default",
                    "", // strOuputStyle
					out strError);
				if (nRet == -1) 
				{
					strError = "检索时出错: " + strError;
					return -1;
				}


				TimeSpan delta = DateTime.Now - time;
				strMessage += "search end. time="+delta.ToString()+"\r\n";

				if (nRet == 0)
					return 0;	// not found

				long lTotalCount = nRet;

				//if (page.Response.IsClientConnected == false)	// 灵敏中断
				//	return -1;

				strMessage += "--- begin get search result ...\r\n";

				time = DateTime.Now;

				long lStart = 0;
				long lPerCount = Math.Min(lTotalCount, 1000);


				for(;;)
				{
					//if (page.Response.IsClientConnected == false)	// 灵敏中断
					//	return -1;


					List<string> aPath = null;
					lPerCount = Math.Min((lTotalCount - lStart), 1000);

					nRet = channel.DoGetSearchResult(
                        "default",
                        lStart,
						lPerCount,
						strLang,
						null,	// stop,
						out aPath,
						out strError);
					if (nRet == -1) 
					{
						strError = "检索库时出错: " + strError;
						return -1;
					}


					delta = DateTime.Now - time;
					strMessage += "get search result end. time="+delta.ToString()+"\r\n";


					if (aPath.Count == 0)
					{
						strError = "检索库时获取的检索结果为空";
						return -1;
					}

					//if (page.Response.IsClientConnected == false)	// 灵敏中断
					//	return -1;

					strMessage += "--- begin build storage ...\r\n";

					time = DateTime.Now;

					int i;
					// 加入新行对象。新行对象中,只初始化了m_strRecID参数
					for(i=0;i<aPath.Count;i++)
					{
						ClientRecordItem item = new ClientRecordItem();
						item.Path = (string)aPath[i];
						this.File.Add(item);

						if ((i % 100) == 0)
						{
							strMessage += "process " + Convert.ToString(i)+ "\r\n";
						}

					}

					delta = DateTime.Now - time;
					strMessage += "build storage end. time="+delta.ToString()+"\r\n";

					lStart += aPath.Count;
					if (lStart >= lTotalCount)
						break;

				}


				return 1;

			}
			finally
			{
				this.m_lock.ReleaseWriterLock();
			}
		}
Esempio n. 3
0
        // 检索文章
        // return:
        //		-1	error
        //		其他 命中数
        public int Search(
            string strServerUrl,
            string strQueryXml,
            RmsChannelCollection Channels,
            string strLang,
            out string strError)
        {
            strError = "";

            string strMessage = "";

            // 加写锁
            this.m_lock.AcquireWriterLock(m_nLockTimeout);
            try
            {
                this.File.Clear();      // 清空集合


                //if (page.Response.IsClientConnected == false)	// 灵敏中断
                //	return -1;

                RmsChannel channel = Channels.GetChannel(strServerUrl);
                Debug.Assert(channel != null, "Channels.GetChannel 异常");

                strMessage += "--- begin search ...\r\n";

                DateTime time = DateTime.Now;

                //if (page.Response.IsClientConnected == false)	// 灵敏中断
                //	return -1;

                long nRet = channel.DoSearch(strQueryXml,
                                             "default",
                                             "", // strOuputStyle
                                             out strError);
                if (nRet == -1)
                {
                    strError = "检索时出错: " + strError;
                    return(-1);
                }


                TimeSpan delta = DateTime.Now - time;
                strMessage += "search end. time=" + delta.ToString() + "\r\n";

                if (nRet == 0)
                {
                    return(0);   // not found
                }
                long lTotalCount = nRet;

                //if (page.Response.IsClientConnected == false)	// 灵敏中断
                //	return -1;

                strMessage += "--- begin get search result ...\r\n";

                time = DateTime.Now;

                long lStart    = 0;
                long lPerCount = Math.Min(lTotalCount, 1000);


                for (; ;)
                {
                    //if (page.Response.IsClientConnected == false)	// 灵敏中断
                    //	return -1;


                    lPerCount = Math.Min((lTotalCount - lStart), 1000);

                    nRet = channel.DoGetSearchResult(
                        "default",
                        lStart,
                        lPerCount,
                        strLang,
                        null,   // stop,
                        out List <string> aPath,
                        out strError);
                    if (nRet == -1)
                    {
                        strError = "检索库时出错: " + strError;
                        return(-1);
                    }

                    delta       = DateTime.Now - time;
                    strMessage += "get search result end. time=" + delta.ToString() + "\r\n";

                    if (aPath.Count == 0)
                    {
                        strError = "检索库时获取的检索结果为空";
                        return(-1);
                    }

                    //if (page.Response.IsClientConnected == false)	// 灵敏中断
                    //	return -1;

                    strMessage += "--- begin build storage ...\r\n";

                    time = DateTime.Now;

                    int i;
                    // 加入新行对象。新行对象中,只初始化了m_strRecID参数
                    for (i = 0; i < aPath.Count; i++)
                    {
                        ClientRecordItem item = new ClientRecordItem();
                        item.Path = (string)aPath[i];
                        this.File.Add(item);

                        if ((i % 100) == 0)
                        {
                            strMessage += "process " + Convert.ToString(i) + "\r\n";
                        }
                    }

                    delta       = DateTime.Now - time;
                    strMessage += "build storage end. time=" + delta.ToString() + "\r\n";

                    lStart += aPath.Count;
                    if (lStart >= lTotalCount)
                    {
                        break;
                    }
                }


                return(1);
            }
            finally
            {
                this.m_lock.ReleaseWriterLock();
            }
        }