Esempio n. 1
0
        private SearchFileContentsResult DoSearchFileContents(SearchContentsData searchContentsData, int maxResults, CancellationToken cancellationToken)
        {
            var taskResults       = new TaskResultCounter(maxResults);
            var searchedFileCount = 0;
            var matches           = _currentFileDatabase.FilesWithContents
                                    .AsParallel()
                                    .WithExecutionMode(ParallelExecutionMode.ForceParallelism)
                                    .WithCancellation(cancellationToken)
                                    .Where(x => !taskResults.Done)
                                    .Select(item => {
                Interlocked.Increment(ref searchedFileCount);
                return(MatchFileContents(item, searchContentsData, taskResults));
            })
                                    .Where(r => r != null)
                                    .ToList();

            return(new SearchFileContentsResult {
                Entries = matches,
                SearchedFileCount = searchedFileCount,
                TotalFileCount = _currentFileDatabase.FilesWithContents.Count,
                HitCount = taskResults.Count,
            });
        }
Esempio n. 2
0
        private static FileSearchResult MatchFileContents(FileData fileData, SearchContentsData searchContentsData, TaskResultCounter taskResultCounter)
        {
            var spans = fileData.Contents.Search(searchContentsData);

            if (spans.Count == 0)
            {
                return(null);
            }

            taskResultCounter.Add(spans.Count);

            return(new FileSearchResult {
                FileName = fileData.FileName,
                Spans = spans
            });
        }