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