fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

1// Copyright 2016 Google Inc. All rights reserved. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package zoekt // import "github.com/sourcegraph/zoekt" 16 17import ( 18 "math/rand" 19 "reflect" 20 21 "google.golang.org/protobuf/types/known/durationpb" 22 "google.golang.org/protobuf/types/known/timestamppb" 23 24 proto "github.com/sourcegraph/zoekt/grpc/protos/zoekt/webserver/v1" 25) 26 27func FileMatchFromProto(p *proto.FileMatch) FileMatch { 28 lineMatches := make([]LineMatch, len(p.GetLineMatches())) 29 for i, lineMatch := range p.GetLineMatches() { 30 lineMatches[i] = LineMatchFromProto(lineMatch) 31 } 32 33 chunkMatches := make([]ChunkMatch, len(p.GetChunkMatches())) 34 for i, chunkMatch := range p.GetChunkMatches() { 35 chunkMatches[i] = ChunkMatchFromProto(chunkMatch) 36 } 37 38 return FileMatch{ 39 Score: p.GetScore(), 40 Debug: p.GetDebug(), 41 FileName: string(p.GetFileName()), // Note: 🚨Warning, this filename may be a non-UTF8 string. 42 Repository: p.GetRepository(), 43 Branches: p.GetBranches(), 44 LineMatches: lineMatches, 45 ChunkMatches: chunkMatches, 46 RepositoryID: p.GetRepositoryId(), 47 RepositoryPriority: p.GetRepositoryPriority(), 48 Content: p.GetContent(), 49 Checksum: p.GetChecksum(), 50 Language: p.GetLanguage(), 51 SubRepositoryName: p.GetSubRepositoryName(), 52 SubRepositoryPath: p.GetSubRepositoryPath(), 53 Version: p.GetVersion(), 54 } 55} 56 57func (m *FileMatch) ToProto() *proto.FileMatch { 58 lineMatches := make([]*proto.LineMatch, len(m.LineMatches)) 59 for i, lm := range m.LineMatches { 60 lineMatches[i] = lm.ToProto() 61 } 62 63 chunkMatches := make([]*proto.ChunkMatch, len(m.ChunkMatches)) 64 for i, cm := range m.ChunkMatches { 65 chunkMatches[i] = cm.ToProto() 66 } 67 68 return &proto.FileMatch{ 69 Score: m.Score, 70 Debug: m.Debug, 71 FileName: []byte(m.FileName), 72 Repository: m.Repository, 73 Branches: m.Branches, 74 LineMatches: lineMatches, 75 ChunkMatches: chunkMatches, 76 RepositoryId: m.RepositoryID, 77 RepositoryPriority: m.RepositoryPriority, 78 Content: m.Content, 79 Checksum: m.Checksum, 80 Language: m.Language, 81 SubRepositoryName: m.SubRepositoryName, 82 SubRepositoryPath: m.SubRepositoryPath, 83 Version: m.Version, 84 } 85} 86 87func ChunkMatchFromProto(p *proto.ChunkMatch) ChunkMatch { 88 ranges := make([]Range, len(p.GetRanges())) 89 for i, r := range p.GetRanges() { 90 ranges[i] = RangeFromProto(r) 91 } 92 93 symbols := make([]*Symbol, len(p.GetSymbolInfo())) 94 for i, r := range p.GetSymbolInfo() { 95 symbols[i] = SymbolFromProto(r) 96 } 97 98 return ChunkMatch{ 99 Content: p.GetContent(), 100 ContentStart: LocationFromProto(p.GetContentStart()), 101 FileName: p.GetFileName(), 102 Ranges: ranges, 103 SymbolInfo: symbols, 104 Score: p.GetScore(), 105 BestLineMatch: p.GetBestLineMatch(), 106 DebugScore: p.GetDebugScore(), 107 } 108} 109 110func (cm *ChunkMatch) ToProto() *proto.ChunkMatch { 111 ranges := make([]*proto.Range, len(cm.Ranges)) 112 for i, r := range cm.Ranges { 113 ranges[i] = r.ToProto() 114 } 115 116 symbolInfo := make([]*proto.SymbolInfo, len(cm.SymbolInfo)) 117 for i, si := range cm.SymbolInfo { 118 symbolInfo[i] = si.ToProto() 119 } 120 121 return &proto.ChunkMatch{ 122 Content: cm.Content, 123 ContentStart: cm.ContentStart.ToProto(), 124 FileName: cm.FileName, 125 Ranges: ranges, 126 SymbolInfo: symbolInfo, 127 Score: cm.Score, 128 BestLineMatch: cm.BestLineMatch, 129 DebugScore: cm.DebugScore, 130 } 131} 132 133func RangeFromProto(p *proto.Range) Range { 134 return Range{ 135 Start: LocationFromProto(p.GetStart()), 136 End: LocationFromProto(p.GetEnd()), 137 } 138} 139 140func (r *Range) ToProto() *proto.Range { 141 return &proto.Range{ 142 Start: r.Start.ToProto(), 143 End: r.End.ToProto(), 144 } 145} 146 147func LocationFromProto(p *proto.Location) Location { 148 return Location{ 149 ByteOffset: p.GetByteOffset(), 150 LineNumber: p.GetLineNumber(), 151 Column: p.GetColumn(), 152 } 153} 154 155func (l *Location) ToProto() *proto.Location { 156 return &proto.Location{ 157 ByteOffset: l.ByteOffset, 158 LineNumber: l.LineNumber, 159 Column: l.Column, 160 } 161} 162 163func LineMatchFromProto(p *proto.LineMatch) LineMatch { 164 lineFragments := make([]LineFragmentMatch, len(p.GetLineFragments())) 165 for i, lineFragment := range p.GetLineFragments() { 166 lineFragments[i] = LineFragmentMatchFromProto(lineFragment) 167 } 168 169 return LineMatch{ 170 Line: p.GetLine(), 171 LineStart: int(p.GetLineStart()), 172 LineEnd: int(p.GetLineEnd()), 173 LineNumber: int(p.GetLineNumber()), 174 Before: p.GetBefore(), 175 After: p.GetAfter(), 176 FileName: p.GetFileName(), 177 Score: p.GetScore(), 178 DebugScore: p.GetDebugScore(), 179 LineFragments: lineFragments, 180 } 181} 182 183func (lm *LineMatch) ToProto() *proto.LineMatch { 184 fragments := make([]*proto.LineFragmentMatch, len(lm.LineFragments)) 185 for i, fragment := range lm.LineFragments { 186 fragments[i] = fragment.ToProto() 187 } 188 189 return &proto.LineMatch{ 190 Line: lm.Line, 191 LineStart: int64(lm.LineStart), 192 LineEnd: int64(lm.LineEnd), 193 LineNumber: int64(lm.LineNumber), 194 Before: lm.Before, 195 After: lm.After, 196 FileName: lm.FileName, 197 Score: lm.Score, 198 DebugScore: lm.DebugScore, 199 LineFragments: fragments, 200 } 201} 202 203func SymbolFromProto(p *proto.SymbolInfo) *Symbol { 204 if p == nil { 205 return nil 206 } 207 208 return &Symbol{ 209 Sym: p.GetSym(), 210 Kind: p.GetKind(), 211 Parent: p.GetParent(), 212 ParentKind: p.GetParentKind(), 213 } 214} 215 216func (s *Symbol) ToProto() *proto.SymbolInfo { 217 if s == nil { 218 return nil 219 } 220 221 return &proto.SymbolInfo{ 222 Sym: s.Sym, 223 Kind: s.Kind, 224 Parent: s.Parent, 225 ParentKind: s.ParentKind, 226 } 227} 228 229func LineFragmentMatchFromProto(p *proto.LineFragmentMatch) LineFragmentMatch { 230 return LineFragmentMatch{ 231 LineOffset: int(p.GetLineOffset()), 232 Offset: p.GetOffset(), 233 MatchLength: int(p.GetMatchLength()), 234 SymbolInfo: SymbolFromProto(p.GetSymbolInfo()), 235 } 236} 237 238func (lfm *LineFragmentMatch) ToProto() *proto.LineFragmentMatch { 239 return &proto.LineFragmentMatch{ 240 LineOffset: int64(lfm.LineOffset), 241 Offset: lfm.Offset, 242 MatchLength: int64(lfm.MatchLength), 243 SymbolInfo: lfm.SymbolInfo.ToProto(), 244 } 245} 246 247func FlushReasonFromProto(p proto.FlushReason) FlushReason { 248 switch p { 249 case proto.FlushReason_FLUSH_REASON_TIMER_EXPIRED: 250 return FlushReasonTimerExpired 251 case proto.FlushReason_FLUSH_REASON_FINAL_FLUSH: 252 return FlushReasonFinalFlush 253 case proto.FlushReason_FLUSH_REASON_MAX_SIZE: 254 return FlushReasonMaxSize 255 default: 256 return FlushReason(0) 257 } 258} 259 260func (fr FlushReason) ToProto() proto.FlushReason { 261 switch fr { 262 case FlushReasonTimerExpired: 263 return proto.FlushReason_FLUSH_REASON_TIMER_EXPIRED 264 case FlushReasonFinalFlush: 265 return proto.FlushReason_FLUSH_REASON_FINAL_FLUSH 266 case FlushReasonMaxSize: 267 return proto.FlushReason_FLUSH_REASON_MAX_SIZE 268 default: 269 return proto.FlushReason_FLUSH_REASON_UNKNOWN_UNSPECIFIED 270 } 271} 272 273// Generate valid reasons for quickchecks 274func (fr FlushReason) Generate(rand *rand.Rand, size int) reflect.Value { 275 switch rand.Int() % 4 { 276 case 1: 277 return reflect.ValueOf(FlushReasonMaxSize) 278 case 2: 279 return reflect.ValueOf(FlushReasonFinalFlush) 280 case 3: 281 return reflect.ValueOf(FlushReasonTimerExpired) 282 default: 283 return reflect.ValueOf(FlushReason(0)) 284 } 285} 286 287func StatsFromProto(p *proto.Stats) Stats { 288 return Stats{ 289 ContentBytesLoaded: p.GetContentBytesLoaded(), 290 IndexBytesLoaded: p.GetIndexBytesLoaded(), 291 Crashes: int(p.GetCrashes()), 292 Duration: p.GetDuration().AsDuration(), 293 FileCount: int(p.GetFileCount()), 294 ShardFilesConsidered: int(p.GetShardFilesConsidered()), 295 FilesConsidered: int(p.GetFilesConsidered()), 296 FilesLoaded: int(p.GetFilesLoaded()), 297 FilesSkipped: int(p.GetFilesSkipped()), 298 ShardsScanned: int(p.GetShardsScanned()), 299 ShardsSkipped: int(p.GetShardsSkipped()), 300 ShardsSkippedFilter: int(p.GetShardsSkippedFilter()), 301 MatchCount: int(p.GetMatchCount()), 302 NgramMatches: int(p.GetNgramMatches()), 303 NgramLookups: int(p.GetNgramLookups()), 304 Wait: p.GetWait().AsDuration(), 305 MatchTreeConstruction: p.GetMatchTreeConstruction().AsDuration(), 306 MatchTreeSearch: p.GetMatchTreeSearch().AsDuration(), 307 RegexpsConsidered: int(p.GetRegexpsConsidered()), 308 FlushReason: FlushReasonFromProto(p.GetFlushReason()), 309 } 310} 311 312func (s *Stats) ToProto() *proto.Stats { 313 return &proto.Stats{ 314 ContentBytesLoaded: s.ContentBytesLoaded, 315 IndexBytesLoaded: s.IndexBytesLoaded, 316 Crashes: int64(s.Crashes), 317 Duration: durationpb.New(s.Duration), 318 FileCount: int64(s.FileCount), 319 ShardFilesConsidered: int64(s.ShardFilesConsidered), 320 FilesConsidered: int64(s.FilesConsidered), 321 FilesLoaded: int64(s.FilesLoaded), 322 FilesSkipped: int64(s.FilesSkipped), 323 ShardsScanned: int64(s.ShardsScanned), 324 ShardsSkipped: int64(s.ShardsSkipped), 325 ShardsSkippedFilter: int64(s.ShardsSkippedFilter), 326 MatchCount: int64(s.MatchCount), 327 NgramMatches: int64(s.NgramMatches), 328 NgramLookups: int64(s.NgramLookups), 329 Wait: durationpb.New(s.Wait), 330 MatchTreeConstruction: durationpb.New(s.MatchTreeConstruction), 331 MatchTreeSearch: durationpb.New(s.MatchTreeSearch), 332 RegexpsConsidered: int64(s.RegexpsConsidered), 333 FlushReason: s.FlushReason.ToProto(), 334 } 335} 336 337func ProgressFromProto(p *proto.Progress) Progress { 338 return Progress{ 339 Priority: p.GetPriority(), 340 MaxPendingPriority: p.GetMaxPendingPriority(), 341 } 342} 343 344func (p *Progress) ToProto() *proto.Progress { 345 return &proto.Progress{ 346 Priority: p.Priority, 347 MaxPendingPriority: p.MaxPendingPriority, 348 } 349} 350 351func SearchResultFromStreamProto(p *proto.StreamSearchResponse, repoURLs, lineFragments map[string]string) *SearchResult { 352 if p == nil { 353 return nil 354 } 355 356 return SearchResultFromProto(p.GetResponseChunk(), repoURLs, lineFragments) 357} 358 359func SearchResultFromProto(p *proto.SearchResponse, repoURLs, lineFragments map[string]string) *SearchResult { 360 if p == nil { 361 return nil 362 } 363 364 files := make([]FileMatch, len(p.GetFiles())) 365 for i, file := range p.GetFiles() { 366 files[i] = FileMatchFromProto(file) 367 } 368 369 return &SearchResult{ 370 Stats: StatsFromProto(p.GetStats()), 371 Progress: ProgressFromProto(p.GetProgress()), 372 373 Files: files, 374 375 RepoURLs: repoURLs, 376 LineFragments: lineFragments, 377 } 378} 379 380func (sr *SearchResult) ToProto() *proto.SearchResponse { 381 if sr == nil { 382 return nil 383 } 384 385 files := make([]*proto.FileMatch, len(sr.Files)) 386 for i, file := range sr.Files { 387 files[i] = file.ToProto() 388 } 389 390 return &proto.SearchResponse{ 391 Stats: sr.Stats.ToProto(), 392 Progress: sr.Progress.ToProto(), 393 394 Files: files, 395 } 396} 397 398func (sr *SearchResult) ToStreamProto() *proto.StreamSearchResponse { 399 if sr == nil { 400 return nil 401 } 402 403 return &proto.StreamSearchResponse{ResponseChunk: sr.ToProto()} 404} 405 406func RepositoryBranchFromProto(p *proto.RepositoryBranch) RepositoryBranch { 407 return RepositoryBranch{ 408 Name: p.GetName(), 409 Version: p.GetVersion(), 410 } 411} 412 413func (r *RepositoryBranch) ToProto() *proto.RepositoryBranch { 414 return &proto.RepositoryBranch{ 415 Name: r.Name, 416 Version: r.Version, 417 } 418} 419 420func RepositoryFromProto(p *proto.Repository) Repository { 421 branches := make([]RepositoryBranch, len(p.GetBranches())) 422 for i, branch := range p.GetBranches() { 423 branches[i] = RepositoryBranchFromProto(branch) 424 } 425 426 subRepoMap := make(map[string]*Repository, len(p.GetSubRepoMap())) 427 for name, repo := range p.GetSubRepoMap() { 428 r := RepositoryFromProto(repo) 429 subRepoMap[name] = &r 430 } 431 432 fileTombstones := make(map[string]struct{}, len(p.GetFileTombstones())) 433 for _, file := range p.GetFileTombstones() { 434 fileTombstones[file] = struct{}{} 435 } 436 437 return Repository{ 438 TenantID: int(p.GetTenantId()), 439 ID: p.GetId(), 440 Name: p.GetName(), 441 URL: p.GetUrl(), 442 Source: p.GetSource(), 443 Branches: branches, 444 SubRepoMap: subRepoMap, 445 CommitURLTemplate: p.GetCommitUrlTemplate(), 446 FileURLTemplate: p.GetFileUrlTemplate(), 447 LineFragmentTemplate: p.GetLineFragmentTemplate(), 448 priority: p.GetPriority(), 449 RawConfig: p.GetRawConfig(), 450 Rank: uint16(p.GetRank()), 451 IndexOptions: p.GetIndexOptions(), 452 HasSymbols: p.GetHasSymbols(), 453 Tombstone: p.GetTombstone(), 454 LatestCommitDate: p.GetLatestCommitDate().AsTime(), 455 FileTombstones: fileTombstones, 456 } 457} 458 459func (r *Repository) ToProto() *proto.Repository { 460 if r == nil { 461 return nil 462 } 463 464 branches := make([]*proto.RepositoryBranch, len(r.Branches)) 465 for i, branch := range r.Branches { 466 branches[i] = branch.ToProto() 467 } 468 469 subRepoMap := make(map[string]*proto.Repository, len(r.SubRepoMap)) 470 for name, repo := range r.SubRepoMap { 471 subRepoMap[name] = repo.ToProto() 472 } 473 474 fileTombstones := make([]string, 0, len(r.FileTombstones)) 475 for file := range r.FileTombstones { 476 fileTombstones = append(fileTombstones, file) 477 } 478 479 return &proto.Repository{ 480 TenantId: int64(r.TenantID), 481 Id: r.ID, 482 Name: r.Name, 483 Url: r.URL, 484 Source: r.Source, 485 Branches: branches, 486 SubRepoMap: subRepoMap, 487 CommitUrlTemplate: r.CommitURLTemplate, 488 FileUrlTemplate: r.FileURLTemplate, 489 LineFragmentTemplate: r.LineFragmentTemplate, 490 Priority: r.priority, 491 RawConfig: r.RawConfig, 492 Rank: uint32(r.Rank), 493 IndexOptions: r.IndexOptions, 494 HasSymbols: r.HasSymbols, 495 Tombstone: r.Tombstone, 496 LatestCommitDate: timestamppb.New(r.LatestCommitDate), 497 FileTombstones: fileTombstones, 498 } 499} 500 501func IndexMetadataFromProto(p *proto.IndexMetadata) IndexMetadata { 502 languageMap := make(map[string]uint16, len(p.GetLanguageMap())) 503 for language, id := range p.GetLanguageMap() { 504 languageMap[language] = uint16(id) 505 } 506 507 return IndexMetadata{ 508 IndexFormatVersion: int(p.GetIndexFormatVersion()), 509 IndexFeatureVersion: int(p.GetIndexFeatureVersion()), 510 IndexMinReaderVersion: int(p.GetIndexMinReaderVersion()), 511 IndexTime: p.GetIndexTime().AsTime(), 512 PlainASCII: p.GetPlainAscii(), 513 LanguageMap: languageMap, 514 ZoektVersion: p.GetZoektVersion(), 515 ID: p.GetId(), 516 } 517} 518 519func (m *IndexMetadata) ToProto() *proto.IndexMetadata { 520 if m == nil { 521 return nil 522 } 523 524 languageMap := make(map[string]uint32, len(m.LanguageMap)) 525 for language, id := range m.LanguageMap { 526 languageMap[language] = uint32(id) 527 } 528 529 return &proto.IndexMetadata{ 530 IndexFormatVersion: int64(m.IndexFormatVersion), 531 IndexFeatureVersion: int64(m.IndexFeatureVersion), 532 IndexMinReaderVersion: int64(m.IndexMinReaderVersion), 533 IndexTime: timestamppb.New(m.IndexTime), 534 PlainAscii: m.PlainASCII, 535 LanguageMap: languageMap, 536 ZoektVersion: m.ZoektVersion, 537 Id: m.ID, 538 } 539} 540 541func RepoStatsFromProto(p *proto.RepoStats) RepoStats { 542 return RepoStats{ 543 Repos: int(p.GetRepos()), 544 Shards: int(p.GetShards()), 545 Documents: int(p.GetDocuments()), 546 IndexBytes: p.GetIndexBytes(), 547 ContentBytes: p.GetContentBytes(), 548 NewLinesCount: p.GetNewLinesCount(), 549 DefaultBranchNewLinesCount: p.GetDefaultBranchNewLinesCount(), 550 OtherBranchesNewLinesCount: p.GetOtherBranchesNewLinesCount(), 551 } 552} 553 554func (s *RepoStats) ToProto() *proto.RepoStats { 555 return &proto.RepoStats{ 556 Repos: int64(s.Repos), 557 Shards: int64(s.Shards), 558 Documents: int64(s.Documents), 559 IndexBytes: s.IndexBytes, 560 ContentBytes: s.ContentBytes, 561 NewLinesCount: s.NewLinesCount, 562 DefaultBranchNewLinesCount: s.DefaultBranchNewLinesCount, 563 OtherBranchesNewLinesCount: s.OtherBranchesNewLinesCount, 564 } 565} 566 567func RepoListEntryFromProto(p *proto.RepoListEntry) *RepoListEntry { 568 if p == nil { 569 return nil 570 } 571 572 return &RepoListEntry{ 573 Repository: RepositoryFromProto(p.GetRepository()), 574 IndexMetadata: IndexMetadataFromProto(p.GetIndexMetadata()), 575 Stats: RepoStatsFromProto(p.GetStats()), 576 } 577} 578 579func (r *RepoListEntry) ToProto() *proto.RepoListEntry { 580 if r == nil { 581 return nil 582 } 583 584 return &proto.RepoListEntry{ 585 Repository: r.Repository.ToProto(), 586 IndexMetadata: r.IndexMetadata.ToProto(), 587 Stats: r.Stats.ToProto(), 588 } 589} 590 591func MinimalRepoListEntryFromProto(p *proto.MinimalRepoListEntry) MinimalRepoListEntry { 592 branches := make([]RepositoryBranch, len(p.GetBranches())) 593 for i, branch := range p.GetBranches() { 594 branches[i] = RepositoryBranchFromProto(branch) 595 } 596 597 return MinimalRepoListEntry{ 598 HasSymbols: p.GetHasSymbols(), 599 Branches: branches, 600 IndexTimeUnix: p.GetIndexTimeUnix(), 601 } 602} 603 604func (m *MinimalRepoListEntry) ToProto() *proto.MinimalRepoListEntry { 605 branches := make([]*proto.RepositoryBranch, len(m.Branches)) 606 for i, branch := range m.Branches { 607 branches[i] = branch.ToProto() 608 } 609 return &proto.MinimalRepoListEntry{ 610 HasSymbols: m.HasSymbols, 611 Branches: branches, 612 IndexTimeUnix: m.IndexTimeUnix, 613 } 614} 615 616func RepoListFromProto(p *proto.ListResponse) *RepoList { 617 repos := make([]*RepoListEntry, len(p.GetRepos())) 618 for i, repo := range p.GetRepos() { 619 repos[i] = RepoListEntryFromProto(repo) 620 } 621 622 reposMap := make(map[uint32]MinimalRepoListEntry, len(p.GetReposMap())) 623 for id, mle := range p.GetReposMap() { 624 reposMap[id] = MinimalRepoListEntryFromProto(mle) 625 } 626 627 return &RepoList{ 628 Repos: repos, 629 ReposMap: reposMap, 630 Crashes: int(p.GetCrashes()), 631 Stats: RepoStatsFromProto(p.GetStats()), 632 } 633} 634 635func (r *RepoList) ToProto() *proto.ListResponse { 636 repos := make([]*proto.RepoListEntry, len(r.Repos)) 637 for i, repo := range r.Repos { 638 repos[i] = repo.ToProto() 639 } 640 641 reposMap := make(map[uint32]*proto.MinimalRepoListEntry, len(r.ReposMap)) 642 for id, repo := range r.ReposMap { 643 reposMap[id] = repo.ToProto() 644 } 645 646 return &proto.ListResponse{ 647 Repos: repos, 648 ReposMap: reposMap, 649 Crashes: int64(r.Crashes), 650 Stats: r.Stats.ToProto(), 651 } 652} 653 654func (l *ListOptions) ToProto() *proto.ListOptions { 655 if l == nil { 656 return nil 657 } 658 var field proto.ListOptions_RepoListField 659 switch l.Field { 660 case RepoListFieldRepos: 661 field = proto.ListOptions_REPO_LIST_FIELD_REPOS 662 case RepoListFieldReposMap: 663 field = proto.ListOptions_REPO_LIST_FIELD_REPOS_MAP 664 } 665 666 return &proto.ListOptions{ 667 Field: field, 668 } 669} 670 671func ListOptionsFromProto(p *proto.ListOptions) *ListOptions { 672 if p == nil { 673 return nil 674 } 675 var field RepoListField 676 switch p.GetField() { 677 case proto.ListOptions_REPO_LIST_FIELD_REPOS: 678 field = RepoListFieldRepos 679 case proto.ListOptions_REPO_LIST_FIELD_REPOS_MAP: 680 field = RepoListFieldReposMap 681 } 682 return &ListOptions{ 683 Field: field, 684 } 685} 686 687func SearchOptionsFromProto(p *proto.SearchOptions) *SearchOptions { 688 if p == nil { 689 return nil 690 } 691 692 return &SearchOptions{ 693 EstimateDocCount: p.GetEstimateDocCount(), 694 Whole: p.GetWhole(), 695 ShardMaxMatchCount: int(p.GetShardMaxMatchCount()), 696 TotalMaxMatchCount: int(p.GetTotalMaxMatchCount()), 697 ShardRepoMaxMatchCount: int(p.GetShardRepoMaxMatchCount()), 698 MaxWallTime: p.GetMaxWallTime().AsDuration(), 699 FlushWallTime: p.GetFlushWallTime().AsDuration(), 700 MaxDocDisplayCount: int(p.GetMaxDocDisplayCount()), 701 MaxMatchDisplayCount: int(p.GetMaxMatchDisplayCount()), 702 NumContextLines: int(p.GetNumContextLines()), 703 ChunkMatches: p.GetChunkMatches(), 704 Trace: p.GetTrace(), 705 DebugScore: p.GetDebugScore(), 706 UseBM25Scoring: p.GetUseBm25Scoring(), 707 } 708} 709 710func (s *SearchOptions) ToProto() *proto.SearchOptions { 711 if s == nil { 712 return nil 713 } 714 715 return &proto.SearchOptions{ 716 EstimateDocCount: s.EstimateDocCount, 717 Whole: s.Whole, 718 ShardMaxMatchCount: int64(s.ShardMaxMatchCount), 719 TotalMaxMatchCount: int64(s.TotalMaxMatchCount), 720 ShardRepoMaxMatchCount: int64(s.ShardRepoMaxMatchCount), 721 MaxWallTime: durationpb.New(s.MaxWallTime), 722 FlushWallTime: durationpb.New(s.FlushWallTime), 723 MaxDocDisplayCount: int64(s.MaxDocDisplayCount), 724 MaxMatchDisplayCount: int64(s.MaxMatchDisplayCount), 725 NumContextLines: int64(s.NumContextLines), 726 ChunkMatches: s.ChunkMatches, 727 Trace: s.Trace, 728 DebugScore: s.DebugScore, 729 UseBm25Scoring: s.UseBM25Scoring, 730 } 731}