PageRenderTime 83ms CodeModel.GetById 41ms app.highlight 7ms RepoModel.GetById 33ms app.codeStats 0ms

/branches/SmartMe/Backup/SmartMe.Core/Data/QueryResult.cs

http://lunar-thu.googlecode.com/
C# | 203 lines | 162 code | 37 blank | 4 comment | 6 complexity | 8f8f70d0562ec1771de4f444fbb27867 MD5 | raw file
  1using System;
  2using System.Collections.Generic;
  3using System.Linq;
  4using System.Text;
  5using System.Collections;
  6using System.Collections.ObjectModel;
  7using SmartMe.Core.Pipeline;
  8using System.Xml.Serialization;
  9
 10namespace SmartMe.Core.Data
 11{
 12    /// <summary>
 13    /// 搜索返回的结果
 14    /// </summary>
 15    public class QueryResult : Message
 16    {
 17		#region fields
 18        private InputQuery _query;
 19        private List<SearchEngineResult> _searchEngineResultItems = new List<SearchEngineResult>();
 20        private List<SuggestionResult> _suggestionResultItems = new List<SuggestionResult>();
 21        private List<DictResult> _dictResultItems = new List<DictResult>();
 22        private List<IQueryResultItem> _items = new List<IQueryResultItem>();
 23        #endregion
 24        
 25        #region constructor
 26
 27        public QueryResult()
 28        {
 29            // do nothing
 30        }
 31
 32        public QueryResult(InputQuery query)
 33        {
 34            _query = query;
 35        }
 36
 37        #endregion
 38
 39        #region properties
 40
 41        public InputQuery Query
 42        {
 43            get
 44            {
 45                return _query;
 46            }
 47            set 
 48            {
 49                _query = value;
 50            }
 51        }
 52
 53        [XmlIgnore]
 54        public List<IQueryResultItem> Items
 55        {
 56            get {
 57                _items.Clear();
 58                foreach ( IQueryResultItem item in _searchEngineResultItems )
 59                {
 60                    _items.Add( item );
 61                }
 62
 63                
 64                foreach ( IQueryResultItem item in _suggestionResultItems )
 65                {
 66                    _items.Add( item );
 67                }
 68
 69                
 70                foreach ( IQueryResultItem item in _dictResultItems )
 71                {
 72                    _items.Add( item );
 73                }
 74
 75                return _items;
 76
 77                
 78            }
 79        }
 80
 81        public List<SearchEngineResult> SearchEngineResultItems
 82        {
 83            get
 84            {
 85                return _searchEngineResultItems;
 86            }
 87        }
 88
 89        [XmlIgnore]
 90        public List<SuggestionResult> SuggestionResultItems
 91        {
 92            get
 93            {
 94                return _suggestionResultItems;
 95            }
 96        }
 97
 98
 99        public List<DictResult> DictResultItems
100        {
101            get
102            {
103                return _dictResultItems;
104            }
105        }
106
107        public DateTime LastUpdateTime
108        {
109            get;
110            set;
111        }
112
113
114        #region IMessage Members
115
116        public override MessageType MessageType
117        {
118            get
119            {
120                return MessageType.QueryResult;
121            }
122        }
123
124        #endregion
125
126        #endregion
127
128        #region methods
129
130        public bool IsEmpty()
131        {
132            
133            foreach (SearchEngineResult r in _searchEngineResultItems)
134            {
135                if(r.Results.Count!=0)
136                {
137                    return false;
138                }
139            }
140            foreach (DictResult  r in _dictResultItems)
141            {
142                if (r.Word!=string.Empty)
143                {
144                    return false;
145                }
146            }
147            foreach (SuggestionResult r in _suggestionResultItems)
148            {
149                if (r.Results.Count!=0)
150                {
151                    return false;
152                }
153            }
154            return true;
155           
156        }
157
158        public override string ToString()
159        {
160            StringBuilder stringBuilder = new StringBuilder(_query.ToString());
161            stringBuilder.Append( "\n" + _searchEngineResultItems.Count );
162            foreach ( IQueryResultItem item in _searchEngineResultItems )
163            {
164                stringBuilder.Append("\n").Append(item);
165            }
166
167            stringBuilder.Append( "\n" + _suggestionResultItems.Count );
168            foreach ( IQueryResultItem item in _suggestionResultItems )
169            {
170                stringBuilder.Append( "\n" ).Append( item );
171            }
172
173            stringBuilder.Append( "\n" + _dictResultItems.Count );
174            foreach ( IQueryResultItem item in _dictResultItems )
175            {
176                stringBuilder.Append( "\n" ).Append( item );
177            }
178
179
180            return stringBuilder.ToString();
181        }
182
183        public override bool Equals(object obj)
184        {
185            QueryResult result = obj as QueryResult;
186            if (result != null)
187            {
188                return (result.ToString() == this.ToString());
189            }
190            else
191            {
192                return false;
193            }
194        }
195
196        public override int GetHashCode()
197        {
198            return ToString().GetHashCode();
199        }
200
201        #endregion
202    }
203}