public SearchMailboxesResults Search(ISearchPolicy policy, SearchMailboxesInputs input) { ulong num = 0UL; SortedResultPage resultPage = null; new List <SearchSource>(input.Sources); List <MailboxStatistics> list = new List <MailboxStatistics>(); Dictionary <Guid, List <KeyValuePair <int, long> > > dictionary = new Dictionary <Guid, List <KeyValuePair <int, long> > >(); Recorder.Record record = policy.Recorder.Start("NonIndexableItemProvider", TraceType.InfoTrace, true); Recorder.Trace(5L, TraceType.InfoTrace, new object[] { "NonIndexableItemProvider.Search Input:", input, "Type:", input.SearchType }); try { SearchSource searchSource = input.Sources.FirstOrDefault <SearchSource>(); if (searchSource != null) { Guid guid = searchSource.MailboxInfo.IsArchive ? searchSource.MailboxInfo.ArchiveDatabase : searchSource.MailboxInfo.MdbGuid; long num2 = 0L; if (input.PagingInfo.SortValue != null && input.PagingInfo.SortValue.SortColumnValue != null) { num2 = input.PagingInfo.SortValue.SecondarySortValue; num2 += 1L; } string indexSystemName = FastIndexVersion.GetIndexSystemName(guid); using (IFailedItemStorage failedItemStorage = Factory.Current.CreateFailedItemStorage(Factory.Current.CreateSearchServiceConfig(), indexSystemName)) { foreach (SearchSource searchSource2 in input.Sources) { FailedItemParameters failedItemParameters = new FailedItemParameters(FailureMode.All, FieldSet.Default); failedItemParameters.MailboxGuid = new Guid?(searchSource2.MailboxInfo.IsArchive ? searchSource2.MailboxInfo.ArchiveGuid : searchSource2.MailboxInfo.MailboxGuid); long failedItemsCount = failedItemStorage.GetFailedItemsCount(failedItemParameters); num += (ulong)failedItemsCount; list.Add(new MailboxStatistics(searchSource2.MailboxInfo, (ulong)failedItemsCount, ByteQuantifiedSize.Zero)); if (input.SearchType == SearchType.NonIndexedItemPreview) { failedItemParameters.StartingIndexId = num2; failedItemParameters.ResultLimit = input.PagingInfo.PageSize; ICollection <IFailureEntry> failedItems = failedItemStorage.GetFailedItems(failedItemParameters); dictionary[failedItemParameters.MailboxGuid.Value] = (from t in failedItems select new KeyValuePair <int, long>(t.DocumentId, t.IndexId)).ToList <KeyValuePair <int, long> >(); } } } if (input.SearchType == SearchType.NonIndexedItemPreview) { MultiMailboxSearchClient multiMailboxSearchClient = new MultiMailboxSearchClient(guid, (from t in input.Sources select t.MailboxInfo).ToArray <MailboxInfo>(), input.Criteria, input.CallerInfo, input.PagingInfo); resultPage = multiMailboxSearchClient.FetchPreviewProperties(dictionary); } } } finally { policy.Recorder.End(record); } return(new SearchMailboxesResults(input.Sources) { SearchResult = new ResultAggregator(resultPage, null, num, ByteQuantifiedSize.Zero, null, null, list) }); }
public SearchMailboxesResults Search(ISearchPolicy policy, SearchMailboxesInputs input) { long num = 0L; long num2 = 0L; long num3 = 0L; long num4 = 0L; long num5 = 0L; long num6 = 0L; ulong num7 = 0UL; SortedResultPage resultPage = null; MultiMailboxSearchClient multiMailboxSearchClient = null; ResultAggregator resultAggregator = new ResultAggregator(); ByteQuantifiedSize byteQuantifiedSize = new ByteQuantifiedSize(0UL); List <MailboxStatistics> list = new List <MailboxStatistics>(); Dictionary <Guid, List <KeyValuePair <int, long> > > dictionary = new Dictionary <Guid, List <KeyValuePair <int, long> > >(); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); Recorder.Record record = policy.Recorder.Start("SearchResultProvider", TraceType.InfoTrace, true); Recorder.Trace(5L, TraceType.InfoTrace, new object[] { "FastLocalSearchResultsProvider.Search Input:", input, "Type:", input.SearchType }); SearchMailboxesResults result; try { Recorder.Trace(5L, TraceType.InfoTrace, "FastLocalSearchResultsProvider.Search Initializing"); num3 = stopwatch.ElapsedMilliseconds; string str = (input.PagingInfo != null && input.PagingInfo.SortBy != null && input.PagingInfo.SortBy.SortOrder == SortOrder.Ascending) ? "+" : "-"; string str2 = (input.PagingInfo != null && input.PagingInfo.SortValue != null && input.PagingInfo.SortValue.SortColumn == ItemSchema.DocumentId) ? "[docid]" : FastIndexSystemSchema.Received.Name; AdditionalParameters additionalParameters = new AdditionalParameters { Sort = str + str2, Refiners = new string[] { FastIndexSystemSchema.Size.Name } }; long referenceDocId = 0L; PaginationQueryFilter pagingFilter = null; QueryFilter queryFilter = input.Criteria.Query; if (input.PagingInfo != null && input.PagingInfo.SortValue != null) { referenceDocId = input.PagingInfo.SortValue.SecondarySortValue; if (input.PagingInfo.SortValue.SortColumnValue != null && input.PagingInfo.SortValue.SortColumn != ItemSchema.DocumentId) { pagingFilter = new PaginationQueryFilter(input.PagingInfo); } } SearchSource searchSource = input.Sources.FirstOrDefault <SearchSource>(); if (searchSource != null) { Guid guid = searchSource.MailboxInfo.IsArchive ? searchSource.MailboxInfo.ArchiveDatabase : searchSource.MailboxInfo.MdbGuid; string displayName = FlowDescriptor.GetImsFlowDescriptor(FastLocalSearchResultsProvider.SearchConfig, FastIndexVersion.GetIndexSystemName(guid)).DisplayName; num4 += stopwatch.ElapsedMilliseconds - num3; num3 = stopwatch.ElapsedMilliseconds; Recorder.Trace(5L, TraceType.InfoTrace, new object[] { "FastLocalSearchResultsProvider.Search Initialized DB:", guid, "Flow:", displayName }); List <SearchSource> list2 = new List <SearchSource>(input.Sources); while (list2.Count > 0) { HashSet <Guid> hashSet = new HashSet <Guid>(); List <SearchSource> list3 = new List <SearchSource>(); int i = 0; while (i < list2.Count) { SearchSource searchSource2 = list2[i]; Guid item = searchSource2.MailboxInfo.IsArchive ? searchSource2.MailboxInfo.ArchiveGuid : searchSource2.MailboxInfo.MailboxGuid; if (!hashSet.Contains(item)) { list3.Add(searchSource2); list2.RemoveAt(i); hashSet.Add(item); } else { i++; } } multiMailboxSearchClient = new MultiMailboxSearchClient(guid, (from s in list3 select s.MailboxInfo).ToArray <MailboxInfo>(), input.Criteria, input.CallerInfo, input.PagingInfo); foreach (SearchSource searchSource3 in list3) { Recorder.Trace(5L, TraceType.InfoTrace, "FastLocalSearchResultsProvider.Search Searching Source", searchSource3); ulong num8 = 0UL; bool flag = false; MailboxStatistics mailboxStatistics = null; ByteQuantifiedSize byteQuantifiedSize2 = new ByteQuantifiedSize(0UL); List <KeyValuePair <int, long> > list4 = new List <KeyValuePair <int, long> >(); Guid guid2 = searchSource3.MailboxInfo.IsArchive ? searchSource3.MailboxInfo.ArchiveGuid : searchSource3.MailboxInfo.MailboxGuid; queryFilter = this.ApplyFolderFilter(queryFilter, searchSource3.MailboxInfo, multiMailboxSearchClient); string text = FqlQueryBuilder.ToFqlString(queryFilter, input.Criteria.QueryCulture); text = this.ApplyPagingFilter(text, referenceDocId, pagingFilter, input.PagingInfo, input.Criteria.QueryCulture); Recorder.Trace(5L, TraceType.InfoTrace, new object[] { "FastLocalSearchResultsProvider.Search Searching Source Guid:", guid2, "Filter:", queryFilter, "Query:", text }); num6 += stopwatch.ElapsedMilliseconds - num3; num3 = stopwatch.ElapsedMilliseconds; IEnumerable <KeyValuePair <PagingImsFlowExecutor.QueryExecutionContext, SearchResultItem[]> > enumerable = FastLocalSearchResultsProvider.FlowExecutor.Execute(displayName, guid2, policy.CallerInfo.QueryCorrelationId, text, 0L, input.Criteria.QueryCulture, additionalParameters, Math.Min(FastLocalSearchResultsProvider.SearchConfig.FastQueryResultTrimHits, input.PagingInfo.PageSize), null); foreach (KeyValuePair <PagingImsFlowExecutor.QueryExecutionContext, SearchResultItem[]> keyValuePair in enumerable) { Recorder.Trace(5L, TraceType.InfoTrace, "FastLocalSearchResultsProvider.Search found pages"); PagingImsFlowExecutor.QueryExecutionContext key = keyValuePair.Key; ISearchResultItem[] value = keyValuePair.Value; if (!flag) { Recorder.Trace(5L, TraceType.InfoTrace, "FastLocalSearchResultsProvider.Search found statistics"); num8 += (ulong)FastLocalSearchResultsProvider.FlowExecutor.ReadHitCount(key); IEnumerable <RefinerResult> source = FastLocalSearchResultsProvider.FlowExecutor.ReadRefiners(key); RefinerResult refinerResult = source.FirstOrDefault((RefinerResult t) => t.Name == FastIndexSystemSchema.Size.Name); if (refinerResult != null) { byteQuantifiedSize2 += new ByteQuantifiedSize((ulong)refinerResult.Sum); } mailboxStatistics = new MailboxStatistics(searchSource3.MailboxInfo, num8, byteQuantifiedSize2); flag = true; } foreach (ISearchResultItem searchResultItem in value) { Recorder.Trace(5L, TraceType.InfoTrace, "FastLocalSearchResultsProvider.Search found items"); IFieldHolder fieldHolder = searchResultItem.Fields.FirstOrDefault((IFieldHolder f) => string.Equals(f.Name, "DocId", StringComparison.InvariantCultureIgnoreCase)); if (fieldHolder != null) { long num9 = (long)fieldHolder.Value; int documentId = IndexId.GetDocumentId(num9); IndexId.GetMailboxNumber(num9); list4.Add(new KeyValuePair <int, long>(documentId, num9)); } } if (list4.Count >= input.PagingInfo.PageSize) { Recorder.Trace(5L, TraceType.InfoTrace, "FastLocalSearchResultsProvider.Search completed FAST"); break; } } num7 += num8; byteQuantifiedSize += byteQuantifiedSize2; if (list4.Count > 0) { dictionary[guid2] = list4; } if (mailboxStatistics != null) { list.Add(mailboxStatistics); } num += stopwatch.ElapsedMilliseconds - num3; num3 = stopwatch.ElapsedMilliseconds; } if (dictionary.Count > 0) { Recorder.Trace(5L, TraceType.InfoTrace, "FastLocalSearchResultsProvider.Search loading preview items"); resultPage = multiMailboxSearchClient.FetchPreviewProperties(dictionary); num2 += stopwatch.ElapsedMilliseconds - num3; num3 = stopwatch.ElapsedMilliseconds; } Recorder.Trace(5L, TraceType.InfoTrace, "FastLocalSearchResultsProvider.Search aggregating"); ISearchResult aggregator = new AggregatedSearchTaskResult(new MailboxInfoList(multiMailboxSearchClient.Mailboxes), resultPage, null, num7, byteQuantifiedSize, null, list, null); resultAggregator.MergeSearchResult(aggregator); num5 += stopwatch.ElapsedMilliseconds - num3; num3 = stopwatch.ElapsedMilliseconds; } } result = new SearchMailboxesResults(input.Sources) { SearchResult = resultAggregator }; } finally { record.Attributes["FAST"] = num; record.Attributes["STORE"] = num2; record.Attributes["REST"] = num6; record.Attributes["INIT"] = num4; record.Attributes["AGGR"] = num5; record.Attributes["TOTALSIZE"] = byteQuantifiedSize; record.Attributes["TOTALCNT"] = num7; policy.Recorder.End(record); } return(result); }
public override void Process(IList <SearchSource> item) { Recorder.Trace(4L, TraceType.InfoTrace, "CompleteSourceLookup.Process Item:", item); Guid guid = new Guid("aca47e7e-5bb8-43ed-976a-f3158f6d4df7"); List <PreviewItem> list = new List <PreviewItem>(); List <MailboxStatistics> list2 = new List <MailboxStatistics>(); SearchMailboxesInputs searchMailboxesInputs = base.Context.TaskContext as SearchMailboxesInputs; Uri baseUri = new Uri("http://local/"); StoreId value = new VersionedId(new byte[] { 3, 1, 2, 3, 3, 1, 2, 3, byte.MaxValue }); UniqueItemHash itemHash = new UniqueItemHash(string.Empty, string.Empty, null, false); PagingInfo pagingInfo = ((SearchMailboxesInputs)base.Executor.Context.Input).PagingInfo; ReferenceItem sortValue = new ReferenceItem(pagingInfo.SortBy, ExDateTime.Now, 0L); Dictionary <PropertyDefinition, object> properties = new Dictionary <PropertyDefinition, object> { { ItemSchema.Id, value } }; foreach (SearchSource searchSource in item) { if (searchSource.MailboxInfo != null && (searchSource.MailboxInfo.MailboxGuid != Guid.Empty || searchSource.MailboxInfo.IsRemoteMailbox)) { Dictionary <string, string> dictionary = new Dictionary <string, string>(); if (searchSource.MailboxInfo != null && searchSource.MailboxInfo.MailboxGuid != Guid.Empty) { Dictionary <string, string> dictionary2 = dictionary; string key = "Name"; string value2; if ((value2 = searchSource.OriginalReferenceId) == null) { value2 = (searchSource.MailboxInfo.DisplayName ?? string.Empty); } dictionary2[key] = value2; dictionary["Smtp"] = (searchSource.MailboxInfo.PrimarySmtpAddress.ToString() ?? string.Empty); dictionary["DN"] = (searchSource.MailboxInfo.LegacyExchangeDN ?? string.Empty); } if (searchMailboxesInputs != null) { dictionary["Lang"] = (searchMailboxesInputs.Language ?? string.Empty); dictionary["Config"] = (searchMailboxesInputs.SearchConfigurationId ?? string.Empty); } Uri owaLink = LinkUtils.AppendQueryString(baseUri, dictionary); Recorder.Trace(4L, TraceType.InfoTrace, new object[] { "CompleteSourceLookup.Process Found:", searchSource.ReferenceId, "MailboxInfo:", searchSource.MailboxInfo }); list.Add(new PreviewItem(properties, (searchSource.MailboxInfo.MailboxGuid != Guid.Empty) ? searchSource.MailboxInfo.MailboxGuid : guid, owaLink, sortValue, itemHash) { MailboxInfo = searchSource.MailboxInfo }); list2.Add(new MailboxStatistics(searchSource.MailboxInfo, 0UL, new ByteQuantifiedSize(0UL))); } } SortedResultPage resultPage = new SortedResultPage(list.ToArray(), pagingInfo); ISearchResult searchResult = new ResultAggregator(resultPage, null, 0UL, new ByteQuantifiedSize(0UL), null, null, list2); base.Executor.EnqueueNext(new SearchMailboxesResults(item) { SearchResult = searchResult }); }