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/protos/zoekt/webserver/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: string(p.GetFileName()), // Note: 🚨Warning, this filename may be a non-UTF8 string. 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: []byte(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_FLUSH_REASON_TIMER_EXPIRED: 247 return FlushReasonTimerExpired 248 case proto.FlushReason_FLUSH_REASON_FINAL_FLUSH: 249 return FlushReasonFinalFlush 250 case proto.FlushReason_FLUSH_REASON_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_FLUSH_REASON_TIMER_EXPIRED 261 case FlushReasonFinalFlush: 262 return proto.FlushReason_FLUSH_REASON_FINAL_FLUSH 263 case FlushReasonMaxSize: 264 return proto.FlushReason_FLUSH_REASON_MAX_SIZE 265 default: 266 return proto.FlushReason_FLUSH_REASON_UNKNOWN_UNSPECIFIED 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 SearchResultFromStreamProto(p *proto.StreamSearchResponse, repoURLs, lineFragments map[string]string) *SearchResult { 349 if p == nil { 350 return nil 351 } 352 353 return SearchResultFromProto(p.GetResponseChunk(), repoURLs, lineFragments) 354} 355 356func SearchResultFromProto(p *proto.SearchResponse, repoURLs, lineFragments map[string]string) *SearchResult { 357 if p == nil { 358 return nil 359 } 360 361 files := make([]FileMatch, len(p.GetFiles())) 362 for i, file := range p.GetFiles() { 363 files[i] = FileMatchFromProto(file) 364 } 365 366 return &SearchResult{ 367 Stats: StatsFromProto(p.GetStats()), 368 Progress: ProgressFromProto(p.GetProgress()), 369 370 Files: files, 371 372 RepoURLs: repoURLs, 373 LineFragments: lineFragments, 374 } 375} 376 377func (sr *SearchResult) ToProto() *proto.SearchResponse { 378 if sr == nil { 379 return nil 380 } 381 382 files := make([]*proto.FileMatch, len(sr.Files)) 383 for i, file := range sr.Files { 384 files[i] = file.ToProto() 385 } 386 387 return &proto.SearchResponse{ 388 Stats: sr.Stats.ToProto(), 389 Progress: sr.Progress.ToProto(), 390 391 Files: files, 392 } 393} 394 395func (sr *SearchResult) ToStreamProto() *proto.StreamSearchResponse { 396 if sr == nil { 397 return nil 398 } 399 400 return &proto.StreamSearchResponse{ResponseChunk: sr.ToProto()} 401} 402 403func RepositoryBranchFromProto(p *proto.RepositoryBranch) RepositoryBranch { 404 return RepositoryBranch{ 405 Name: p.GetName(), 406 Version: p.GetVersion(), 407 } 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 UseDocumentRanks: p.GetUseDocumentRanks(), 701 DocumentRanksWeight: p.GetDocumentRanksWeight(), 702 Trace: p.GetTrace(), 703 DebugScore: p.GetDebugScore(), 704 UseKeywordScoring: p.GetUseKeywordScoring(), 705 } 706} 707 708func (s *SearchOptions) ToProto() *proto.SearchOptions { 709 if s == nil { 710 return nil 711 } 712 713 return &proto.SearchOptions{ 714 EstimateDocCount: s.EstimateDocCount, 715 Whole: s.Whole, 716 ShardMaxMatchCount: int64(s.ShardMaxMatchCount), 717 TotalMaxMatchCount: int64(s.TotalMaxMatchCount), 718 ShardRepoMaxMatchCount: int64(s.ShardRepoMaxMatchCount), 719 MaxWallTime: durationpb.New(s.MaxWallTime), 720 FlushWallTime: durationpb.New(s.FlushWallTime), 721 MaxDocDisplayCount: int64(s.MaxDocDisplayCount), 722 MaxMatchDisplayCount: int64(s.MaxMatchDisplayCount), 723 NumContextLines: int64(s.NumContextLines), 724 ChunkMatches: s.ChunkMatches, 725 UseDocumentRanks: s.UseDocumentRanks, 726 DocumentRanksWeight: s.DocumentRanksWeight, 727 Trace: s.Trace, 728 DebugScore: s.DebugScore, 729 UseKeywordScoring: s.UseKeywordScoring, 730 } 731}