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