예제 #1
0
        public void FromXMLObject(XMLObject xmlObject)
        {
            SearchEngineResult result = GetSearchEngineResultFromXMLObject(xmlObject);

            this._searchEngine = result._searchEngine;
            this._searchUrl    = result._searchUrl;
            this._results      = result._results;
        }
예제 #2
0
        public static SearchEngineResult GetSearchEngineResultFromXMLObject(XMLObject xmlObject)
        {
            XmlSerializer      xmlSerializer   = new XmlSerializer(typeof(SearchEngineResult));
            StringReader       xmlStringReader = new StringReader(xmlObject.ToString());
            SearchEngineResult result          = xmlSerializer.Deserialize(xmlStringReader) as SearchEngineResult;

            xmlStringReader.Close();
            if (result == null)
            {
                result = new SearchEngineResult();
            }
            return(result);
        }
예제 #3
0
        public SearchEngineResult Parse(string html, Encoding encoding)
        {
            HTMLparser oP = HtmlParserFactory.GetInstance();
            searchResult = new SearchEngineResult();
            searchResult.SearchEngineType = SearchEngineType.Google;
            item = new SearchEngineResult.ResultItem();
            //item.Source = "Google";
            oP.Init(encoding.GetBytes(html));
            oP.SetEncoding(encoding);
            HTMLchunk oChunk = null;

            int state = 0;
            bool bEncodingSet = false;
            while ((oChunk = oP.ParseNext()) != null)
            {

                switch (oChunk.oType)
                {
                    case  HTMLchunkType.OpenTag:
                        HandleOpenTag(oChunk, ref state);

                printParams:
                        if (oChunk.sTag == "meta")
                        {
                            HandleMetaEncoding(oP, oChunk, ref bEncodingSet);
                        };
                    HandleParam(oChunk, ref state);

                    break;

                    case HTMLchunkType.CloseTag:
                    HandleCloseTag(oChunk, ref state);
                        break;

                    case HTMLchunkType.Text:
                        HandleText(oChunk, ref state);
                        break;

                    default:
                        break;
                }
            }
            return searchResult;
        }
예제 #4
0
 private static SearchEngineResult GetSearchResult()
 {
     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 = "LinTian" + " " + 1 + " Done.";
     item1.SimilarUrl = "http://similar.www.com/";
     item1.Url = "http://info.tsinghua.edu.cn";
     result.Results.Add(item1);
     SearchEngineResult.ResultItem item2 = new SearchEngineResult.ResultItem();
     item2.Title = "INFO2";
     item2.CacheUrl = "http://aaa.www.com22222/";
     item2.Description = "LunaR" + " " + 2 + " Done2.";
     item2.SimilarUrl = "http://similar.www.com2222/";
     item2.Url = "http://info.tsinghua.edu.cn2";
     result.Results.Add(item2);
     return result;
 }
예제 #5
0
 public SearchEngineResult Parse(string html, Encoding encoding)
 {
     string content = ScriptManager.LoadScript(ScriptPath);
     SearchEngineResult result;
     if (content != "")
     {
         try
         {
             object o = WebBrowser.InvokeScript("eval", new String[] { content });
             result = SearchEngineResult.GetSearchEngineResultFromXMLObject(new XMLObject(o.ToString()));
             return result;
         }
         catch (Exception)
         {
             // currently do nothing
             result = new SearchEngineResult();
         }
     }
     else
     {
         result = new SearchEngineResult();
     }
     return result;
 }
예제 #6
0
 private bool FindUIElements(SearchEngineResult searchEngineResult, out ListBox listBox, out TabItem tabItem, out string engineName)
 {
     bool hasFound = false;
     switch (searchEngineResult.SearchEngineType)
     {
         case SearchEngineType.Google:
             {
                 hasFound = true;
                 listBox = _parent.GoogleOutputListBox;
                 tabItem = _parent.GoogleTabItem;
                 engineName = "谷歌";
                 break;
             }
         case SearchEngineType.Baidu:
             {
                 hasFound = true;
                 listBox = _parent.BaiduOutputListBox;
                 tabItem = _parent.BaiduTabItem;
                 engineName = "百度";
                 break;
             }
         case SearchEngineType.Sougou:
             {
                 hasFound = true;
                 listBox = _parent.SougouOutputListBox;
                 tabItem = _parent.SougouTabItem;
                 engineName = "搜狗";
                 break;
             }
         case SearchEngineType.Wikipedia:
             {
                 hasFound = true;
                 listBox = _parent.WikipediaOutputListBox;
                 tabItem = _parent.WikipediaTabItem;
                 engineName = "维基";
                 break;
             }
         default:
             {
                 hasFound = false;
                 listBox = null;
                 tabItem = null;
                 engineName = "Unknown";
                 break;
             }
     }
     return hasFound;
 }
예제 #7
0
            private bool FindSearchEngineResult(QueryResult queryResult, SearchEngineType targetType, out SearchEngineResult searchEngineResult)
            {
                bool hasFound = false;
                searchEngineResult = null;
                if (queryResult != null)
                {

                    if ( queryResult.SearchEngineResultItems != null )
                    {

                        foreach ( SearchEngineResult resultItem in queryResult.SearchEngineResultItems )
                        {
                            if (resultItem != null && resultItem.SearchEngineType == targetType)
                            {
                                searchEngineResult = resultItem;
                                hasFound = true;
                                break;
                            }
                        }
                    }
                }
                return hasFound;
            }
예제 #8
0
 private bool FindSearchEngineResult(object sender, out SearchEngineResult searchEngineResult)
 {
     bool hasFound = false;
     SearchEngineResult result = null;
     if (sender is ListBox)
     {
         ListBox sourceListBox = sender as ListBox;
         if (sourceListBox == _parent.GoogleOutputListBox)
         {
             hasFound = FindSearchEngineResult(_currentQueryResult, SearchEngineType.Google, out result);
         }
         else if (sourceListBox == _parent.BaiduOutputListBox)
         {
             hasFound = FindSearchEngineResult(_currentQueryResult, SearchEngineType.Baidu, out result);
         }
         else if (sourceListBox == _parent.SougouOutputListBox)
         {
             hasFound = FindSearchEngineResult(_currentQueryResult, SearchEngineType.Sougou, out result);
         }
         else if (sourceListBox == _parent.WikipediaOutputListBox)
         {
             hasFound = FindSearchEngineResult(_currentQueryResult, SearchEngineType.Wikipedia, out result);
         }
     }
     searchEngineResult = result;
     return hasFound;
 }
        public static void Test()
        {
            QueryResultRecordManager manager = new QueryResultRecordManager("data", new TimeSpan(0, 1, 0));

            Pipeline.Pipeline pipeline = new Pipeline.Pipeline();
            pipeline.QueryResultSubscriberManager.AddSubscriber(manager);

            QueryResult result = new QueryResult(new InputQuery("Bill Gates"));
            SearchEngineResult resultItem = new SearchEngineResult();
            resultItem.SearchEngineType = SearchEngineType.Google;
            resultItem.SearchUrl = "http://www.google.com/query.jsp";
            SearchEngineResult.ResultItem item = new SearchEngineResult.ResultItem();
            item.Title = "ddd";
            item.Url = "http://www.gfw.com/";
            item.SimilarUrl = "http://www.g.com/ddd";
            item.CacheUrl = "http://www.g.com/cache";
            item.Description = "Who cares?";
            resultItem.Results.Add(item);

            SuggestionResult resultItem1 = new SuggestionResult();
            resultItem1.SuggestionType = SuggestionType.Google;
            resultItem1.SearchUrl = "json";
            SuggestionResult.ResultItem item1 = new SuggestionResult.ResultItem();
            item1.Index = "1";
            item1.Number = "2";
            item1.Suggestion = "haha";
            resultItem1.Results.Add( item1 );

            result.SearchEngineResultItems.Add(resultItem);
            result.SuggestionResultItems.Add(resultItem1);

            pipeline.OnQueryResultReady(result);

            Thread.Sleep(1000);

            List<QueryResult> resultList = manager.GetResultList(DateTime.Today, DateTime.Today);
            foreach (QueryResult queryResult in resultList)
            {
                Console.WriteLine(queryResult);
            }
            Console.WriteLine("----------------------------------------------");

            manager.RemoveAllResultList();

            resultList = manager.GetResultList(DateTime.Today, DateTime.Today);
            foreach (QueryResult queryResult in resultList)
            {
                Console.WriteLine(queryResult);
            }

            Console.WriteLine("----------------------------------------------");

            result = new QueryResult(new InputQuery("Bill Gates"));
            resultItem = new SearchEngineResult();
            resultItem.SearchEngineType = SearchEngineType.Google;
            resultItem.SearchUrl = "http://www.google.com/query.jsp";
            item = new SearchEngineResult.ResultItem();
            item.Title = "ddd";
            item.Url = "http://www.gfw.com/";
            item.SimilarUrl = "http://www.g.com/ddd";
            item.CacheUrl = "http://www.g.com/cache";
            item.Description = "Who cares?";
            resultItem.Results.Add(item);

            result.Items.Add(resultItem);

            pipeline.OnQueryResultReady(result);

            Thread.Sleep(1000);

            manager.RemoveResultListFromDate(DateTime.Today);
            resultList = manager.GetResultList(DateTime.Today - new TimeSpan(1, 0, 0, 0), DateTime.Today);
            foreach (QueryResult queryResult in resultList)
            {
                Console.WriteLine(queryResult);
            }

            Console.WriteLine("----------------------------------------------");

            manager.RemoveResultListFromDate(DateTime.Today + new TimeSpan(1, 0, 0, 0));
            resultList = manager.GetResultList(DateTime.Today - new TimeSpan(1, 0, 0, 0), DateTime.Today);
            foreach (QueryResult queryResult in resultList)
            {
                Console.WriteLine(queryResult);
            }

            Console.WriteLine("----------------------------------------------");
        }
 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;
 }
예제 #11
0
 /// <summary>
 /// 读完一个网页后进行解析的回调函数
 /// </summary>
 /// <param name="sender">产生发送消息者</param>
 /// <param name="e">消息事件</param>
 private void WebBrowserLoadCompleted(object sender, NavigationEventArgs e)
 {
     foreach (string str in _libraryPath)
     {
         LoadLibrary(str);
     }
     _result = Parser.Parse(null, _encoding);
     isBrowserNavigating = false;
 }
예제 #12
0
 public static SearchEngineResult GetSearchEngineResultFromXMLObject(XMLObject xmlObject)
 {
     XmlSerializer xmlSerializer = new XmlSerializer(typeof(SearchEngineResult));
     StringReader xmlStringReader = new StringReader(xmlObject.ToString());
     SearchEngineResult result = xmlSerializer.Deserialize(xmlStringReader) as SearchEngineResult;
     xmlStringReader.Close();
     if (result == null)
     {
         result = new SearchEngineResult();
     }
     return result;
 }