public void Dispose() { if (SearchData != null) { SearchData.Dispose(); SearchData = null; } }
public IList<TextRange> FindAll( CompiledTextSearchData compiledTextSearchData, IOperationProgressTracker progressTracker) { return _fileContents.FindAll( compiledTextSearchData, _textRange, progressTracker); }
private SearchCodeResult SearchCodeWorker( CompiledTextSearchData compiledTextSearchData, int maxResults, bool includeSymLinks, CancellationToken cancellationToken) { var progressTracker = new OperationProgressTracker(maxResults, cancellationToken); var searchedFileIds = new PartitionedBitArray( _currentFileDatabase.SearchableFileCount, Environment.ProcessorCount * 2); var matches = _currentFileDatabase.FileContentsPieces .AsParallel() .WithExecutionMode(ParallelExecutionMode.ForceParallelism) .WithCancellation(cancellationToken) .Where(x => !progressTracker.ShouldEndProcessing) .Select(item => { // Filter out files inside symlinks if needed if (!includeSymLinks) { if (_currentFileDatabase.IsContainedInSymLink(item.FileName)) { return(default(SearchableContentsResult)); } } // Filter out files that don't match the file name match pattern if (!compiledTextSearchData.FileNameFilter(item.FileName)) { return(default(SearchableContentsResult)); } searchedFileIds.Set(item.FileId, true); return(new SearchableContentsResult { FileContentsPiece = item, Spans = item .FindAll(compiledTextSearchData, progressTracker) .Select(x => new FilePositionSpan { Position = x.Position, Length = x.Length, }) .ToList(), }); }) .Where(r => r.Spans != null && r.Spans.Count > 0) .GroupBy(r => r.FileContentsPiece.FileId) .Select(g => new FileSearchResult { FileName = g.First().FileContentsPiece.FileName, Spans = g.OrderBy(x => x.Spans.First().Position).SelectMany(x => x.Spans).ToList() }) .ToList(); return(new SearchCodeResult { Entries = matches, SearchedFileCount = searchedFileIds.Count, TotalFileCount = _currentFileDatabase.SearchableFileCount, HitCount = progressTracker.ResultCount, }); }
/// <summary> /// Find all instances of the search pattern stored in <paramref /// name="compiledTextSearchData"/> within the passed in <paramref /// name="textRange"/> /// </summary> public IList<TextRange> FindAll( CompiledTextSearchData compiledTextSearchData, TextRange textRange, IOperationProgressTracker progressTracker) { var textFragment = CreateFragmentFromRange(textRange); var providerForMainEntry = compiledTextSearchData .GetSearchContainer(compiledTextSearchData.ParsedSearchString.MainEntry); var textSearch = GetCompiledTextSearch(providerForMainEntry); var postProcessSearchHit = CreateFilterForOtherEntries(compiledTextSearchData); var result = textSearch.FindAll(textFragment, postProcessSearchHit, progressTracker); return result; }
private Func<TextRange, TextRange?> CreateFilterForOtherEntries( CompiledTextSearchData compiledTextSearchData) { if (compiledTextSearchData.ParsedSearchString.EntriesBeforeMainEntry.Count == 0 && compiledTextSearchData.ParsedSearchString.EntriesAfterMainEntry.Count == 0) { return x => x; } // Search for a match for "entry" withing "textRange" FindEntryFunction findEntry = (textRange, entry) => { var algo = this.GetCompiledTextSearch(compiledTextSearchData.GetSearchContainer(entry)); return algo.FindFirst(CreateFragmentFromRange(textRange), OperationProgressTracker.None); }; // Return the extent of the line to look into for non-main entries. GetLineRangeFunction getLineRange = position => this.GetLineTextRangeFromPosition(position, MaxLineExtentOffset); var sourceTextSearch = new TextSourceTextSearch( getLineRange, findEntry, compiledTextSearchData.ParsedSearchString); return sourceTextSearch.FilterSearchHit; }