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 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("----------------------------------------------");
        }