public static void Test( ) { BaiduSuggestion engine = new BaiduSuggestion(); InputQuery query = new InputQuery( "baih" ); query.QueryType = InputQueryType.Text; SuggestionResult item = engine.Search( query ) as SuggestionResult; Console.WriteLine( item ); }
public static void Test() { ISearch engine = new GoogleSearchEngine(); InputQuery query = new InputQuery("时间"); query.QueryType = InputQueryType.Text; IQueryResultItem item = engine.Search(query); Console.WriteLine(item); }
public static void Test() { DictCn engine = new DictCn(); InputQuery query = new InputQuery( "time" ); query.QueryType = InputQueryType.Text; IQueryResultItem item = engine.Search( query ); Console.WriteLine( item ); }
public IQueryResultItem Search( InputQuery query ) { SuggestionResult finalResult = new SuggestionResult(); finalResult.SuggestionType = SuggestionType.Baidu; Encoding gb2312 = Encoding.GetEncoding( "gb2312" ); Encoding utf8 = Encoding.UTF8; string url = "http://suggestion.baidu.com/su?wd=" + HttpUtility.UrlEncode( query.Text, gb2312 ) + "&action=opensearch&ie=gb2312&from=ie8"; finalResult.SearchUrl = url; if ( query == null || query.QueryType != SmartMe.Core.Data.InputQueryType.Text || query.Text == null || query.Text == "" ) { return finalResult; } string html = SmartMe.Web.Crawl.Crawler.Crawl( url, gb2312 ); if ( html == null || html == "" ) { return finalResult; } Regex p = new Regex( "\\[.+\\]" ); string jsonResult = p.Match( html ).Value; if ( jsonResult == null || jsonResult == string.Empty ) { return finalResult; } DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer( typeof( object ) ); object rawResults = jsonSerializer.ReadObject( new MemoryStream( Encoding.Convert(gb2312,utf8,gb2312.GetBytes(jsonResult)) ) ); if(rawResults!=null) { object[] preResults = rawResults as object[]; if ( preResults!=null && preResults.Length==2) { object[] results = preResults[1] as object[]; if ( results != null && results.Length > 0 ) { for ( int i = 0; i < results.Length; ++i ) { SuggestionResult.ResultItem item = new SuggestionResult.ResultItem(); string temp = results[i] as string; if ( temp != null ) { item.Suggestion = temp; //Console.WriteLine( temp ); finalResult.Results.Add( item ); } } } } } return finalResult; }
public void OnInputTextCanceled(InputQuery text) { lock (_inputTextPipes) { foreach (Pipe pipe in _inputTextPipes) { if (pipe.Message == text) { pipe.CancelMessage(); } } } }
public static void Test() { _libPath = new string[] { "jquery-1.3.2.min.js", "SmartMe-Buildin-Script.js" }; ExternelSearchEngine engine = new ExternelSearchEngine(_webBrowser, _googleUrlPattern, _scriptPath); engine.Encoding = Encoding.UTF8; engine.LibraryPath.AddRange(_libPath); InputQuery query = new InputQuery(_queryString, InputQueryType.Text); SearchEngineResult result = engine.Search(query) as SearchEngineResult; Console.WriteLine(result); }
public static void Test() { Pipeline pipeline = new Pipeline(); pipeline.QueryResultItemSubscriberManager.AddSubscriber(new ResultItemSubscriber(500)); WebResourceManager manager = new WebResourceManager(pipeline, new QueryResultHandler()); InputQuery query = new InputQuery("Ba"); Console.WriteLine(query.Text); //manager.SearchEngineList.Add(new SearchEngine(2000)); // manager.SearchEngineList.Add(new SearchEngine(1000)); manager.SearchEngineList.Add(new GoogleSearchEngine()); manager.SearchEngineList.Add(new BaiduSearchEngine()); manager.SearchEngineList.Add( new GoogleSuggestion() ); manager.SearchEngineList.Add(new DictCn()); manager.Handle(query); Thread.Sleep(8000); }
public override bool Equals(object obj) { InputQuery anotherQuery = obj as InputQuery; if (anotherQuery == null) { return(false); } if (this.QueryType == anotherQuery.QueryType && this.Text == anotherQuery.Text) { return(true); } else { return(false); } }
public IQueryResultItem Search( InputQuery query ) { SmartMe.Core.Data.DictResult emptyResult = new SmartMe.Core.Data.DictResult(); emptyResult.DictionaryType = SmartMe.Core.Data.DictionaryType.Dict_cn; string url = "http://dict.cn/search?q=" + HttpUtility.UrlEncode( query.Text, Encoding.GetEncoding( "gb2312" ) ); emptyResult.SearchUrl = url; if ( query == null || query.QueryType != SmartMe.Core.Data.InputQueryType.Text || query.Text == null || query.Text == "" ) { return emptyResult; } string html = SmartMe.Web.Crawl.Crawler.Crawl( url, Encoding.GetEncoding( "gb2312" ) ); if ( html == null || html == "" ) { return emptyResult; } SmartMe.Web.Parse.DictCnParser parser = new SmartMe.Web.Parse.DictCnParser(); SmartMe.Core.Data.DictResult result = parser.Parse( html, Encoding.GetEncoding( "gb2312" ) ); result.SearchUrl = url; return result; }
private void _DoQuery(string text, InputQueryType queryType) { if (text == string.Empty) { return; } switch (queryType) { case InputQueryType.Text: case InputQueryType.FileName: { InputQuery query = new InputQuery(text); query.QueryType = InputQueryType.Text; _lastQueryText = text; AddQueryHistory(text); this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background, new Action( delegate() { _pipeline.OnInputTextReady(query); }) ); break; } case InputQueryType.FtpUri: case InputQueryType.HttpUri: { Shell shell = new Shell(); shell.DoOpenWebBrowser(text); break; } default: break; } }
public SearchAndReturnPipe(WebResourceManager parent, ISearch engine, InputQuery query, Pipeline pipeline) { // Assert(engine!= null && query != null) _parent = parent; _searchEngine = engine; _inputQuery = query; _thread = new Thread(new ThreadStart(SearchAndReturn)); _thread.IsBackground = true; _thread.Start(); }
public InputQuery GetQuery(string rawText) { InputQuery query = new InputQuery(rawText); return query; }
public void OnInputTextReady(InputQuery text) { List<Pipe> newPipes = _inputTextSubscriberManager.NotifyAll(text); // Assert(newPipes != null) lock (_inputTextPipes) { _inputTextPipes.AddRange(newPipes); } }
public IQueryResultItem Search( InputQuery query ) { string queryString = HttpUtility.UrlEncode(query.Text, _encoding); string urlString = string.Format(UrlPattern, queryString); string urlAddress = urlString.Trim(new char[] { ' ', '\t', '\n', '\r' }); this.WebBrowser.Navigate(new Uri(urlAddress)); isBrowserNavigating = true; while (isBrowserNavigating) { Thread.Sleep(500); } return _result; }
/// <summary> /// 新增一个查询项 /// </summary> /// <param name="query">查询项</param> private void AddInputQuery(InputQuery query) { if (query == null) { //TO-DO: throw exception? return; } lock (QueryList) { QueryList.Add(query); } // TO-DO: Do not save anyway, add some saving policies SaveQuery(); }
private void HandleDeprecateMessage(InputQuery message) { if (_deprecateQueryOption == HandleDeprecateQueryOption.Drop) { _pipeline.OnInputTextCanceled(message); lock (_searchPipeList) { foreach (SearchAndReturnPipe pipe in _searchPipeList) { pipe.CancelQuery(); } } } }
private void OnSearchResultDone( IQueryResultItem result, InputQuery query ) { if (query == _result.Query) { lock (_result) { switch (result.ResultType) { case QueryResultItemType.SearchEngineResult: _result.SearchEngineResultItems.Add( result as SearchEngineResult ); break; case QueryResultItemType.DictionaryResult: _result.DictResultItems.Add(result as DictResult); break; case QueryResultItemType.SuggestionResult: _result.SuggestionResultItems.Add(result as SuggestionResult); break; default: break; } _result.LastUpdateTime = DateTime.Now; _handler.OnResultUpdate(_result); _pipeline.OnQueryResultReady(_result); if ( (_result.SearchEngineResultItems.Count + _result.SuggestionResultItems.Count + _result.DictResultItems.Count) == _searchEngineList.Count) { _handler.OnResultCompleted(_result); //_pipeline.OnQueryResultReady(_result); } } } }
public QueryResult(InputQuery query) { _query = query; }
public IQueryResultItem Search( InputQuery query ) { SearchEngineResult result = new SearchEngineResult(); result.SearchEngineType = SearchEngineType.Other; SearchEngineResult.ResultItem item1 = new SearchEngineResult.ResultItem(); item1.Title = "INFO"; item1.CacheUrl = "http://aaa.www.com/"; item1.Description = query + " " + _count + " Done."; item1.SimilarUrl = "http://similar.www.com/"; item1.Url = "http://info.tsinghua.edu.cn"; result.Results.Add(item1); _count++; Thread.Sleep(_waitTime); return result; }