Пример #1
0
        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);
        }
Пример #2
0
        public SearchResult PerformSearch(ComplianceMessage target, SearchWorkDefinition definition)
        {
            string          query  = definition.Query;
            SearchResult    result = new SearchResult();
            CultureInfo     culture;
            FaultDefinition faultDefinition;

            ExceptionHandler.Parser.TryRun(delegate
            {
                if (string.IsNullOrEmpty(target.Culture))
                {
                    culture = CultureInfo.InvariantCulture;
                }
                else
                {
                    culture = CultureInfo.GetCultureInfo(target.Culture);
                }
                AdditionalParameters additionalParameters = new AdditionalParameters
                {
                    Refiners = new string[]
                    {
                        FastIndexSystemSchema.Size.Name
                    }
                };
                if (query != null)
                {
                    Guid mailboxGuid = target.MessageTarget.Mailbox;
                    Guid database    = target.MessageTarget.Database;
                    IEnumerable <KeyValuePair <PagingImsFlowExecutor.QueryExecutionContext, SearchResultItem[]> > pages = null;
                    string flowName = FlowDescriptor.GetImsFlowDescriptor(FastLocalSearchResultsProvider.SearchConfig, FastIndexVersion.GetIndexSystemName(database)).DisplayName;
                    if (ExceptionHandler.Proxy.TryRun(delegate
                    {
                        pages = FastLocalSearchResultsProvider.FlowExecutor.Execute(flowName, mailboxGuid, Guid.NewGuid(), query, 0L, culture, additionalParameters, Math.Min(FastLocalSearchResultsProvider.SearchConfig.FastQueryResultTrimHits, 1), null);
                    }, TimeSpan.FromMinutes(1.0), out faultDefinition, target, new Action <ExceptionHandler.ExceptionData>(this.ProxyExceptionHandler), default(CancellationToken), null, "PerformSearch", "f:\\15.00.1497\\sources\\dev\\EDiscovery\\src\\TaskDistributionSystem\\ApplicationPlugins\\EDiscovery\\FastLocalSearchResultsProvider.cs", 213))
                    {
                        foreach (KeyValuePair <PagingImsFlowExecutor.QueryExecutionContext, SearchResultItem[]> keyValuePair in pages)
                        {
                            PagingImsFlowExecutor.QueryExecutionContext key = keyValuePair.Key;
                            SearchResultItem[] value = keyValuePair.Value;
                            ByteQuantifiedSize byteQuantifiedSize = default(ByteQuantifiedSize);
                            long count = 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)
                            {
                                byteQuantifiedSize = new ByteQuantifiedSize((ulong)refinerResult.Sum);
                            }
                            result = new SearchResult();
                            result.UpdateTotalSize((long)byteQuantifiedSize.ToMB());
                            result.UpdateTotalCount(count);
                            result.Results.Add(new SearchResult.TargetSearchResult
                            {
                                Target = target.MessageTarget,
                                Size   = result.TotalSize,
                                Count  = result.TotalCount
                            });
                        }
                    }
                }
            }, TimeSpan.FromMinutes(1.0), out faultDefinition, target, null, default(CancellationToken), null, "PerformSearch", "f:\\15.00.1497\\sources\\dev\\EDiscovery\\src\\TaskDistributionSystem\\ApplicationPlugins\\EDiscovery\\FastLocalSearchResultsProvider.cs", 188);
            if (faultDefinition != null)
            {
                ExceptionHandler.FaultMessage(target, faultDefinition, true);
            }
            return(result);
        }