public ISearchTaskResult GetErrorResult(Exception ex) { if ((this.type & SearchType.Statistics) == SearchType.Statistics) { List <IKeywordHit> list = new List <IKeywordHit>(1); List <string> list2 = new List <string>(1); list2.Add(this.criteria.QueryString); if (this.criteria.SubFilters != null) { list2.AddRange(this.criteria.SubFilters.Keys); } foreach (string phrase in list2) { IKeywordHit keywordHit = null; foreach (MailboxInfo mailbox in this.MailboxInfoList) { if (keywordHit == null) { keywordHit = new KeywordHit(phrase, mailbox, ex); } else { keywordHit.Merge(new KeywordHit(phrase, mailbox, ex)); } } list.Add(keywordHit); } return(new AggregatedSearchTaskResult(this.MailboxInfoList, list)); } return(new AggregatedSearchTaskResult(this.MailboxInfoList, ex)); }
public SearchMailboxResult(MailboxInfo mailbox, IKeywordHit keyword) { Util.ThrowOnNull(mailbox, "mailbox"); Util.ThrowOnNull(keyword, "keyword"); this.mailbox = mailbox; this.resultType = SearchType.Statistics; this.keywordHit = keyword; this.success = true; if (keyword.Errors.Count != 0) { this.success = false; } }
private void MergeStatistics(IKeywordHit hit) { if (hit == null) { return; } IKeywordHit keywordHit = null; if (!this.keywordStatistics.TryGetValue(hit.Phrase, out keywordHit)) { this.keywordStatistics.Add(hit.Phrase, hit); return; } keywordHit.Merge(hit); }
public void Execute(SearchCompletedCallback searchCallback) { if (searchCallback == null) { throw new ArgumentNullException("searchCallback"); } this.InvokeMethodAndHandleExceptions(delegate { this.attempts++; this.callback = searchCallback; AggregatedSearchTaskResult result = null; this.InitRpcSearchClient(); Factory.Current.LocalTaskTracer.TraceInformation(this.GetHashCode(), 0L, "Correlation Id:{0}. Executing {1} search for the queryFilter:{2} on {3} mailboxes in database:{4}", new object[] { this.ExecutingUserIdentity.QueryCorrelationId, (this.RpcClient.Criteria.SearchType == SearchType.Preview) ? "preview" : "keyword stats", this.RpcClient.Criteria.QueryString, this.MailboxInfoList.Count, this.RpcClient.MailboxDatabaseGuid }); if ((this.type & SearchType.Preview) == SearchType.Preview) { result = this.RpcClient.Search(Factory.Current.GetMaxRefinerResults(this.SearchCriteria.RecipientSession)); } else if ((this.type & SearchType.Statistics) == SearchType.Statistics) { List <IKeywordHit> keywordHits = this.RpcClient.GetKeywordHits(this.keywordList); IKeywordHit keywordHit; if (keywordHits == null) { keywordHit = null; } else { keywordHit = keywordHits.Find((IKeywordHit x) => x.Phrase.Equals(this.SearchCriteria.QueryString, StringComparison.OrdinalIgnoreCase)); } IKeywordHit keywordHit2 = keywordHit; result = new AggregatedSearchTaskResult(this.MailboxInfoList, keywordHits, (keywordHit2 != null) ? keywordHit2.Count : 0UL, (keywordHit2 != null) ? keywordHit2.Size : ByteQuantifiedSize.Zero); } this.UpdateSearchStatistics(); this.callback(this, result); }); }
public void Merge(IKeywordHit hits) { if (hits == null) { return; } if (string.Compare(this.phrase, hits.Phrase, StringComparison.OrdinalIgnoreCase) != 0) { throw new ArgumentException("Keyword hits: Invalid merge"); } checked { if (hits.Count != 0UL) { this.count += hits.Count; this.size += hits.Size; } this.errors.AddRange(((KeywordHit)hits).Errors); } }
private AggregatedSearchTaskResult(SearchType searchType, bool isSuccess, MailboxInfoList mailboxInfoList, SortedResultPage previewResultPage, Dictionary <string, List <IRefinerResult> > refinerResult, List <MailboxStatistics> mailboxStatistics, IProtocolLog protocolLog, ulong totalResultCount, ByteQuantifiedSize totalResultSize, List <Pair <MailboxInfo, Exception> > previewFailures, List <IKeywordHit> keywordStatsResults, Exception error) { Util.ThrowOnNull(mailboxInfoList, "mailboxInfoList"); if (mailboxInfoList.Count == 0) { throw new ArgumentException("Invalid or empty mailboxInfoList"); } this.resultType = searchType; this.mailboxInfoList = mailboxInfoList; this.success = isSuccess; this.exception = error; this.totalResultCount = totalResultCount; this.totalResultSize = totalResultSize; this.protocolLog = protocolLog; if (searchType == SearchType.Preview) { if (this.success) { if (totalResultCount > 0UL) { Util.ThrowOnNull(previewResultPage, "resultPage"); } if (previewResultPage != null && previewResultPage.ResultCount > 0) { if (totalResultCount < (ulong)((long)previewResultPage.ResultCount)) { Factory.Current.LocalTaskTracer.TraceError <string, Guid>((long)this.GetHashCode(), "The total result count was less than the current page result count for the mailbox:{0} on database:{1}", this.mailboxInfoList[0].MailboxGuid.ToString(), this.mailboxInfoList[0].MdbGuid); throw new ArgumentException("The totalResultCount must be greater than or equal to the current page result count"); } if (totalResultSize == ByteQuantifiedSize.Zero) { Factory.Current.LocalTaskTracer.TraceError <string, string>((long)this.GetHashCode(), "There are results from FAST but the size information was not returned from FAST for the mailbox:{0} on database:{1}", this.mailboxInfoList[0].MailboxGuid.ToString(), this.mailboxInfoList[0].MdbGuid.ToString()); Factory.Current.EventLog.LogEvent(InfoWorkerEventLogConstants.Tuple_DiscoveryFailedToFetchSizeInformation, null, new object[] { this.mailboxInfoList[0].MailboxGuid.ToString(), this.mailboxInfoList[0].MdbGuid.ToString() }); } } this.previewSearchResultPage = previewResultPage; this.refinersResults = refinerResult; Util.ThrowOnNull(mailboxStatistics, "mailboxStatistics"); if (this.previewSearchResultPage != null && this.previewSearchResultPage.ResultCount > 0 && mailboxStatistics.Count == 0) { throw new ArgumentException("The MailboxStats cannot be an empty list when the results are present."); } this.mailboxStatistics = mailboxStatistics; } this.previewErrors = new List <Pair <MailboxInfo, Exception> >(this.mailboxInfoList.Count); if (this.exception != null) { foreach (MailboxInfo first in this.mailboxInfoList) { this.previewErrors.Add(new Pair <MailboxInfo, Exception>(first, this.exception)); } } if (previewFailures != null) { this.previewErrors.AddRange(previewFailures); return; } } else if (searchType == SearchType.Statistics && isSuccess) { Util.ThrowOnNull(keywordStatsResults, null); this.keywordStatisticsResult = new Dictionary <string, IKeywordHit>(keywordStatsResults.Count, StringComparer.InvariantCultureIgnoreCase); foreach (IKeywordHit keywordHit in keywordStatsResults) { IKeywordHit keywordHit2 = null; if (!this.keywordStatisticsResult.TryGetValue(keywordHit.Phrase, out keywordHit2)) { this.keywordStatisticsResult.Add(keywordHit.Phrase, keywordHit); } } } }