rankurllister.cs

来自「用C#编写的一个款搜索engine的源代码!摘自<Visual c#200」· CS 代码 · 共 104 行

CS
104
字号
using System;
using System.IO;
using System.Threading;
using SECompare.Kernel;
using SECompare.Structure;

namespace SECompare.Kernel
{
	/// <summary>
	/// Summary description for RankURLLister.
	/// </summary>
	public class RankURLLister:ThreadStatus
	{
		private String m_Engine;
		private int    m_RankStart;  //Start rank of list
		private int    m_RankLength; //rank length of list
		private String m_QueryRoot;
		private String m_QueryURLRoot;

		public RankURLLister(String Engine,int RankStart,int RankLength,String QueryRoot,String QueryURLRoot)
		{
			this.m_Engine = Engine;
			this.m_RankStart  = RankStart;
			this.m_RankLength = RankLength;
			this.m_QueryRoot  = QueryRoot;
			this.m_QueryURLRoot = QueryURLRoot;
			this.threadStart = new ThreadStart(Run);
			
		}

		private void Run()
		{
			try
			{
				//Get all samplinged queries list files
				String[] files = Directory.GetFiles(this.m_QueryRoot);
				for(int i=0;i<files.Length;i++)
				{
					//************Progress Status Report***********
					this.mFilePercentage = (float)i/files.Length; 
					//*********************************************
					this.Run(files[i]);
				}
				
			}
			catch(ThreadInterruptedException)
			{
				
			}
			finally
			{
				this.mIsFinished = true;
			}
		}

		private void Run(String filename)
		{
			//Original File
			FileInfo file = new FileInfo(filename);
			//File to Save URL list
			File.Create(this.m_QueryURLRoot+"\\"+file.Name).Close();
			StreamWriter writer = new StreamWriter(this.m_QueryURLRoot+"\\"+file.Name,true);
				
			//read query samples
			String category = file.Name;
			CrawlSample sample = new CrawlSample();
			sample.Load(category,filename);

			//get query strings
			String[] queries = sample.GetQueries();
	
			//For each query
			for(int i=0;i<queries.Length;i++)
			{
				String query = queries[i];

				//************Progress Status Report***********
				this.mProcessingFile  = category;
				this.mEntryPercentage = (float)i/queries.Length;  
				//*********************************************		
	
				writer.WriteLine("*"+query);
				//For each Rank
				for(int rank=0;rank<this.m_RankLength;rank++)
				{
					//************Progress Status Report***********
					this.mProcessingEntry = query + "(Rank:" + (rank+this.m_RankStart) +")";  
					//*********************************************

					QueryRecord record = QueryRecord.Load(query,this.m_Engine,rank+this.m_RankStart);
					if(record!=null)
						writer.WriteLine((rank+1)+"\t"+record.URL);
					else 
						break;
				}

			}

			writer.Close();

		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?