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