WikiCrawler/MediaWiki/Api.cs
/// <summary>
/// Searches for pages by a search query.
/// </summary>
Searches for pages by a search query.
Searches for pages by a search query .
public IEnumerable<Article> Search(string srsearch, string srnamespace = "", int srlimit = Limit.Max)
		{
			string baseQuery = "format=json"
				+ "&action=query"
				+ "&list=search"
				+ "&srsearch=" + UrlEncode(srsearch);
			if (!string.IsNullOrEmpty(srnamespace))
			{
				baseQuery += "&srnamespace=" + UrlEncode(srnamespace);
			}
			if (srlimit != Limit.Unspecified)
			{
				baseQuery += "&srlimit=" + GetLimitParameter(srlimit);
			}
			string query = baseQuery + "&continue=";
			bool doContinue = false;
			do
			{
				HttpWebRequest request = CreateApiRequest();
				string json;
				using (StreamReader read = new StreamReader(EasyWeb.Post(request, query)))
				{
					json = read.ReadToEnd();
				}
				Dictionary<string, object> deser = (Dictionary<string, object>)new JavaScriptSerializer().DeserializeObject(json);
				foreach (Dictionary<string, object> page in (object[])((Dictionary<string, object>)deser["query"])["search"])
				{
					yield return new Article(page);
				}
				doContinue = deser.ContainsKey("continue");
				if (doContinue)
				{
					Dictionary<string, object> continueData = (Dictionary<string, object>)deser["continue"];
					query = baseQuery;
					foreach (KeyValuePair<string, object> kv in continueData)
					{
						query += "&" + kv.Key + "=" + (string)kv.Value;
					}
				}
			}
			while (doContinue);
		}
public IEnumerable < Article > Search ( string srsearch , string srnamespace = " " , int srlimit = Limit . Max ) { string baseQuery = " " + " " + " " + " " + UrlEncode ( srsearch ) ; if ( ! string . IsNullOrEmpty ( srnamespace ) ) { baseQuery += " " + UrlEncode ( srnamespace ) ; } if ( srlimit != Limit . Unspecified ) { baseQuery += " " + GetLimitParameter ( srlimit ) ; } string query = baseQuery + " " ; bool doContinue = false ; do { HttpWebRequest request = CreateApiRequest ( ) ; string json ; using ( StreamReader read = new StreamReader ( EasyWeb . Post ( request , query ) ) ) { json = read . ReadToEnd ( ) ; } Dictionary < string , object > deser = ( Dictionary < string , object > ) new JavaScriptSerializer ( ) . DeserializeObject ( json ) ; foreach ( Dictionary < string , object > page in ( object [ ] ) ( ( Dictionary < string , object > ) deser [ " " ] ) [ " " ] ) { yield return new Article ( page ) ; } doContinue = deser . ContainsKey ( " " ) ; if ( doContinue ) { Dictionary < string , object > continueData = ( Dictionary < string , object > ) deser [ " " ] ; query = baseQuery ; foreach ( KeyValuePair < string , object > kv in continueData ) { query += " " + kv . Key + " " + ( string ) kv . Value ; } } } while ( doContinue ) ; }
Searches for pages by a search query.
Searches for pages by a search query .
//TODO: test me //Download stream //Read response
srsearch
string
srnamespace
string
srlimit
int