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 RegexpsConsidered: int(p.GetRegexpsConsidered()), 303 FlushReason: FlushReasonFromProto(p.GetFlushReason()), 304 } 305} 306 307func (s *Stats) ToProto() *proto.Stats { 308 return &proto.Stats{ 309 ContentBytesLoaded: s.ContentBytesLoaded, 310 IndexBytesLoaded: s.IndexBytesLoaded, 311 Crashes: int64(s.Crashes), 312 Duration: durationpb.New(s.Duration), 313 FileCount: int64(s.FileCount), 314 ShardFilesConsidered: int64(s.ShardFilesConsidered), 315 FilesConsidered: int64(s.FilesConsidered), 316 FilesLoaded: int64(s.FilesLoaded), 317 FilesSkipped: int64(s.FilesSkipped), 318 ShardsScanned: int64(s.ShardsScanned), 319 ShardsSkipped: int64(s.ShardsSkipped), 320 ShardsSkippedFilter: int64(s.ShardsSkippedFilter), 321 MatchCount: int64(s.MatchCount), 322 NgramMatches: int64(s.NgramMatches), 323 NgramLookups: int64(s.NgramLookups), 324 Wait: durationpb.New(s.Wait), 325 RegexpsConsidered: int64(s.RegexpsConsidered), 326 FlushReason: s.FlushReason.ToProto(), 327 } 328} 329 330func ProgressFromProto(p *proto.Progress) Progress { 331 return Progress{ 332 Priority: p.GetPriority(), 333 MaxPendingPriority: p.GetMaxPendingPriority(), 334 } 335} 336 337func (p *Progress) ToProto() *proto.Progress { 338 return &proto.Progress{ 339 Priority: p.Priority, 340 MaxPendingPriority: p.MaxPendingPriority, 341 } 342} 343 344func SearchResultFromProto(p *proto.SearchResponse) *SearchResult { 345 if p == nil { 346 return nil 347 } 348 349 files := make([]FileMatch, len(p.GetFiles())) 350 for i, file := range p.GetFiles() { 351 files[i] = FileMatchFromProto(file) 352 } 353 354 return &SearchResult{ 355 Stats: StatsFromProto(p.GetStats()), 356 Progress: ProgressFromProto(p.GetProgress()), 357 Files: files, 358 RepoURLs: p.RepoUrls, 359 LineFragments: p.LineFragments, 360 } 361} 362 363func (sr *SearchResult) ToProto() *proto.SearchResponse { 364 if sr == nil { 365 return nil 366 } 367 368 files := make([]*proto.FileMatch, len(sr.Files)) 369 for i, file := range sr.Files { 370 files[i] = file.ToProto() 371 } 372 373 return &proto.SearchResponse{ 374 Stats: sr.Stats.ToProto(), 375 Progress: sr.Progress.ToProto(), 376 Files: files, 377 RepoUrls: sr.RepoURLs, 378 LineFragments: sr.LineFragments, 379 } 380} 381 382func RepositoryBranchFromProto(p *proto.RepositoryBranch) RepositoryBranch { 383 return RepositoryBranch{ 384 Name: p.GetName(), 385 Version: p.GetVersion(), 386 } 387 388} 389 390func (r *RepositoryBranch) ToProto() *proto.RepositoryBranch { 391 return &proto.RepositoryBranch{ 392 Name: r.Name, 393 Version: r.Version, 394 } 395} 396 397func RepositoryFromProto(p *proto.Repository) Repository { 398 branches := make([]RepositoryBranch, len(p.GetBranches())) 399 for i, branch := range p.GetBranches() { 400 branches[i] = RepositoryBranchFromProto(branch) 401 } 402 403 subRepoMap := make(map[string]*Repository, len(p.GetSubRepoMap())) 404 for name, repo := range p.GetSubRepoMap() { 405 r := RepositoryFromProto(repo) 406 subRepoMap[name] = &r 407 } 408 409 fileTombstones := make(map[string]struct{}, len(p.GetFileTombstones())) 410 for _, file := range p.GetFileTombstones() { 411 fileTombstones[file] = struct{}{} 412 } 413 414 return Repository{ 415 ID: p.GetId(), 416 Name: p.GetName(), 417 URL: p.GetUrl(), 418 Source: p.GetSource(), 419 Branches: branches, 420 SubRepoMap: subRepoMap, 421 CommitURLTemplate: p.GetCommitUrlTemplate(), 422 FileURLTemplate: p.GetFileUrlTemplate(), 423 LineFragmentTemplate: p.GetLineFragmentTemplate(), 424 priority: p.GetPriority(), 425 RawConfig: p.GetRawConfig(), 426 Rank: uint16(p.GetRank()), 427 IndexOptions: p.GetIndexOptions(), 428 HasSymbols: p.GetHasSymbols(), 429 Tombstone: p.GetTombstone(), 430 LatestCommitDate: p.GetLatestCommitDate().AsTime(), 431 FileTombstones: fileTombstones, 432 } 433} 434 435func (r *Repository) ToProto() *proto.Repository { 436 if r == nil { 437 return nil 438 } 439 440 branches := make([]*proto.RepositoryBranch, len(r.Branches)) 441 for i, branch := range r.Branches { 442 branches[i] = branch.ToProto() 443 } 444 445 subRepoMap := make(map[string]*proto.Repository, len(r.SubRepoMap)) 446 for name, repo := range r.SubRepoMap { 447 subRepoMap[name] = repo.ToProto() 448 } 449 450 fileTombstones := make([]string, 0, len(r.FileTombstones)) 451 for file := range r.FileTombstones { 452 fileTombstones = append(fileTombstones, file) 453 } 454 455 return &proto.Repository{ 456 Id: r.ID, 457 Name: r.Name, 458 Url: r.URL, 459 Source: r.Source, 460 Branches: branches, 461 SubRepoMap: subRepoMap, 462 CommitUrlTemplate: r.CommitURLTemplate, 463 FileUrlTemplate: r.FileURLTemplate, 464 LineFragmentTemplate: r.LineFragmentTemplate, 465 Priority: r.priority, 466 RawConfig: r.RawConfig, 467 Rank: uint32(r.Rank), 468 IndexOptions: r.IndexOptions, 469 HasSymbols: r.HasSymbols, 470 Tombstone: r.Tombstone, 471 LatestCommitDate: timestamppb.New(r.LatestCommitDate), 472 FileTombstones: fileTombstones, 473 } 474} 475 476func IndexMetadataFromProto(p *proto.IndexMetadata) IndexMetadata { 477 languageMap := make(map[string]uint16, len(p.GetLanguageMap())) 478 for language, id := range p.GetLanguageMap() { 479 languageMap[language] = uint16(id) 480 } 481 482 return IndexMetadata{ 483 IndexFormatVersion: int(p.GetIndexFormatVersion()), 484 IndexFeatureVersion: int(p.GetIndexFeatureVersion()), 485 IndexMinReaderVersion: int(p.GetIndexMinReaderVersion()), 486 IndexTime: p.GetIndexTime().AsTime(), 487 PlainASCII: p.GetPlainAscii(), 488 LanguageMap: languageMap, 489 ZoektVersion: p.GetZoektVersion(), 490 ID: p.GetId(), 491 } 492} 493 494func (m *IndexMetadata) ToProto() *proto.IndexMetadata { 495 if m == nil { 496 return nil 497 } 498 499 languageMap := make(map[string]uint32, len(m.LanguageMap)) 500 for language, id := range m.LanguageMap { 501 languageMap[language] = uint32(id) 502 } 503 504 return &proto.IndexMetadata{ 505 IndexFormatVersion: int64(m.IndexFormatVersion), 506 IndexFeatureVersion: int64(m.IndexFeatureVersion), 507 IndexMinReaderVersion: int64(m.IndexMinReaderVersion), 508 IndexTime: timestamppb.New(m.IndexTime), 509 PlainAscii: m.PlainASCII, 510 LanguageMap: languageMap, 511 ZoektVersion: m.ZoektVersion, 512 Id: m.ID, 513 } 514} 515 516func RepoStatsFromProto(p *proto.RepoStats) RepoStats { 517 return RepoStats{ 518 Repos: int(p.GetRepos()), 519 Shards: int(p.GetShards()), 520 Documents: int(p.GetDocuments()), 521 IndexBytes: p.GetIndexBytes(), 522 ContentBytes: p.GetContentBytes(), 523 NewLinesCount: p.GetNewLinesCount(), 524 DefaultBranchNewLinesCount: p.GetDefaultBranchNewLinesCount(), 525 OtherBranchesNewLinesCount: p.GetOtherBranchesNewLinesCount(), 526 } 527} 528 529func (s *RepoStats) ToProto() *proto.RepoStats { 530 return &proto.RepoStats{ 531 Repos: int64(s.Repos), 532 Shards: int64(s.Shards), 533 Documents: int64(s.Documents), 534 IndexBytes: s.IndexBytes, 535 ContentBytes: s.ContentBytes, 536 NewLinesCount: s.NewLinesCount, 537 DefaultBranchNewLinesCount: s.DefaultBranchNewLinesCount, 538 OtherBranchesNewLinesCount: s.OtherBranchesNewLinesCount, 539 } 540} 541 542func RepoListEntryFromProto(p *proto.RepoListEntry) *RepoListEntry { 543 if p == nil { 544 return nil 545 } 546 547 return &RepoListEntry{ 548 Repository: RepositoryFromProto(p.GetRepository()), 549 IndexMetadata: IndexMetadataFromProto(p.GetIndexMetadata()), 550 Stats: RepoStatsFromProto(p.GetStats()), 551 } 552} 553 554func (r *RepoListEntry) ToProto() *proto.RepoListEntry { 555 if r == nil { 556 return nil 557 } 558 559 return &proto.RepoListEntry{ 560 Repository: r.Repository.ToProto(), 561 IndexMetadata: r.IndexMetadata.ToProto(), 562 Stats: r.Stats.ToProto(), 563 } 564} 565 566func MinimalRepoListEntryFromProto(p *proto.MinimalRepoListEntry) MinimalRepoListEntry { 567 branches := make([]RepositoryBranch, len(p.GetBranches())) 568 for i, branch := range p.GetBranches() { 569 branches[i] = RepositoryBranchFromProto(branch) 570 } 571 572 return MinimalRepoListEntry{ 573 HasSymbols: p.GetHasSymbols(), 574 Branches: branches, 575 IndexTimeUnix: p.GetIndexTimeUnix(), 576 } 577} 578 579func (m *MinimalRepoListEntry) ToProto() *proto.MinimalRepoListEntry { 580 branches := make([]*proto.RepositoryBranch, len(m.Branches)) 581 for i, branch := range m.Branches { 582 branches[i] = branch.ToProto() 583 } 584 return &proto.MinimalRepoListEntry{ 585 HasSymbols: m.HasSymbols, 586 Branches: branches, 587 IndexTimeUnix: m.IndexTimeUnix, 588 } 589} 590 591func RepoListFromProto(p *proto.ListResponse) *RepoList { 592 repos := make([]*RepoListEntry, len(p.GetRepos())) 593 for i, repo := range p.GetRepos() { 594 repos[i] = RepoListEntryFromProto(repo) 595 } 596 597 reposMap := make(map[uint32]MinimalRepoListEntry, len(p.GetReposMap())) 598 for id, mle := range p.GetReposMap() { 599 reposMap[id] = MinimalRepoListEntryFromProto(mle) 600 } 601 602 minimal := make(map[uint32]*MinimalRepoListEntry, len(p.GetMinimal())) 603 for id, mle := range p.GetMinimal() { 604 m := MinimalRepoListEntryFromProto(mle) 605 minimal[id] = &m 606 } 607 608 return &RepoList{ 609 Repos: repos, 610 ReposMap: reposMap, 611 Crashes: int(p.GetCrashes()), 612 Stats: RepoStatsFromProto(p.GetStats()), 613 Minimal: minimal, 614 } 615} 616 617func (r *RepoList) ToProto() *proto.ListResponse { 618 repos := make([]*proto.RepoListEntry, len(r.Repos)) 619 for i, repo := range r.Repos { 620 repos[i] = repo.ToProto() 621 } 622 623 reposMap := make(map[uint32]*proto.MinimalRepoListEntry, len(r.ReposMap)) 624 for id, repo := range r.ReposMap { 625 reposMap[id] = repo.ToProto() 626 } 627 628 minimal := make(map[uint32]*proto.MinimalRepoListEntry, len(r.Minimal)) 629 for id, repo := range r.Minimal { 630 minimal[id] = repo.ToProto() 631 } 632 633 return &proto.ListResponse{ 634 Repos: []*proto.RepoListEntry{}, 635 ReposMap: reposMap, 636 Crashes: int64(r.Crashes), 637 Stats: r.Stats.ToProto(), 638 Minimal: minimal, 639 } 640} 641 642func (l *ListOptions) ToProto() *proto.ListOptions { 643 if l == nil { 644 return nil 645 } 646 var field proto.ListOptions_RepoListField 647 switch l.Field { 648 case RepoListFieldRepos: 649 field = proto.ListOptions_REPO_LIST_FIELD_REPOS 650 case RepoListFieldMinimal: 651 field = proto.ListOptions_REPO_LIST_FIELD_MINIMAL 652 case RepoListFieldReposMap: 653 field = proto.ListOptions_REPO_LIST_FIELD_REPOS_MAP 654 } 655 656 return &proto.ListOptions{ 657 Field: field, 658 Minimal: l.Minimal, 659 } 660} 661 662func ListOptionsFromProto(p *proto.ListOptions) *ListOptions { 663 if p == nil { 664 return nil 665 } 666 var field RepoListField 667 switch p.GetField() { 668 case proto.ListOptions_REPO_LIST_FIELD_REPOS: 669 field = RepoListFieldRepos 670 case proto.ListOptions_REPO_LIST_FIELD_MINIMAL: 671 field = RepoListFieldMinimal 672 case proto.ListOptions_REPO_LIST_FIELD_REPOS_MAP: 673 field = RepoListFieldReposMap 674 } 675 return &ListOptions{ 676 Field: field, 677 Minimal: p.GetMinimal(), 678 } 679} 680 681func SearchOptionsFromProto(p *proto.SearchOptions) *SearchOptions { 682 if p == nil { 683 return nil 684 } 685 686 return &SearchOptions{ 687 EstimateDocCount: p.GetEstimateDocCount(), 688 Whole: p.GetWhole(), 689 ShardMaxMatchCount: int(p.GetShardMaxMatchCount()), 690 TotalMaxMatchCount: int(p.GetTotalMaxMatchCount()), 691 ShardRepoMaxMatchCount: int(p.GetShardRepoMaxMatchCount()), 692 MaxWallTime: p.GetMaxWallTime().AsDuration(), 693 FlushWallTime: p.GetFlushWallTime().AsDuration(), 694 MaxDocDisplayCount: int(p.GetMaxDocDisplayCount()), 695 NumContextLines: int(p.GetNumContextLines()), 696 ChunkMatches: p.GetChunkMatches(), 697 UseDocumentRanks: p.GetUseDocumentRanks(), 698 DocumentRanksWeight: p.GetDocumentRanksWeight(), 699 Trace: p.GetTrace(), 700 DebugScore: p.GetDebugScore(), 701 UseKeywordScoring: p.GetUseKeywordScoring(), 702 } 703} 704 705func (s *SearchOptions) ToProto() *proto.SearchOptions { 706 if s == nil { 707 return nil 708 } 709 710 return &proto.SearchOptions{ 711 EstimateDocCount: s.EstimateDocCount, 712 Whole: s.Whole, 713 ShardMaxMatchCount: int64(s.ShardMaxMatchCount), 714 TotalMaxMatchCount: int64(s.TotalMaxMatchCount), 715 ShardRepoMaxMatchCount: int64(s.ShardRepoMaxMatchCount), 716 MaxWallTime: durationpb.New(s.MaxWallTime), 717 FlushWallTime: durationpb.New(s.FlushWallTime), 718 MaxDocDisplayCount: int64(s.MaxDocDisplayCount), 719 NumContextLines: int64(s.NumContextLines), 720 ChunkMatches: s.ChunkMatches, 721 UseDocumentRanks: s.UseDocumentRanks, 722 DocumentRanksWeight: s.DocumentRanksWeight, 723 Trace: s.Trace, 724 DebugScore: s.DebugScore, 725 UseKeywordScoring: s.UseKeywordScoring, 726 } 727}