Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

search: factor out function for structural search path #22943

Merged
merged 1 commit into from
Jul 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions internal/search/run/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,8 @@ func (a *Aggregator) DoSymbolSearch(ctx context.Context, args *search.TextParame
return errors.Wrap(err, "symbol search failed")
}

func (a *Aggregator) DoFilePathSearch(ctx context.Context, args *search.TextParameters) (err error) {
tr, ctx := trace.New(ctx, "doFilePathSearch", "")
tr.LogFields(trace.Stringer("global_search_mode", args.Mode))
defer func() {
a.Error(err)
tr.SetErrorIfNotContext(err)
tr.Finish()
}()

isDefaultStructuralSearch := args.PatternInfo.IsStructuralPat && args.PatternInfo.FileMatchLimit == search.DefaultMaxSearchResults

if !isDefaultStructuralSearch {
return unindexed.SearchFilesInRepos(ctx, args, a)
}

func (a *Aggregator) DoStructuralSearch(ctx context.Context, args *search.TextParameters) (err error) {
// For structural search with default limits we retry if we get no results.

fileMatches, stats, err := unindexed.SearchFilesInReposBatch(ctx, args)

if len(fileMatches) == 0 && err == nil {
Expand Down Expand Up @@ -140,6 +125,23 @@ func (a *Aggregator) DoFilePathSearch(ctx context.Context, args *search.TextPara
return err
}

func (a *Aggregator) DoFilePathSearch(ctx context.Context, args *search.TextParameters) (err error) {
tr, ctx := trace.New(ctx, "doFilePathSearch", "")
tr.LogFields(trace.Stringer("global_search_mode", args.Mode))
defer func() {
a.Error(err)
tr.SetErrorIfNotContext(err)
tr.Finish()
}()

isDefaultStructuralSearch := args.PatternInfo.IsStructuralPat && args.PatternInfo.FileMatchLimit == search.DefaultMaxSearchResults
if isDefaultStructuralSearch {
return a.DoStructuralSearch(ctx, args)
}

return unindexed.SearchFilesInRepos(ctx, args, a)
}

func (a *Aggregator) DoDiffSearch(ctx context.Context, tp *search.TextParameters) (err error) {
tr, ctx := trace.New(ctx, "doDiffSearch", "")
defer func() {
Expand Down