fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

Remove unused repoPathRanks struct (#921)

This was left over from our PageRank prototype.

-76
-19
internal/gitindex/index.go
··· 598 598 return repo, s, err 599 599 } 600 600 601 - type repoPathRanks struct { 602 - MeanRank float64 `json:"mean_reference_count"` 603 - Paths map[string]float64 `json:"paths"` 604 - } 605 - 606 - // rank returns the rank for a given path. It uses these rules: 607 - // - If we have a concrete rank for this file, always use it 608 - // - If there's no rank, and it's a low priority file like a test, then use rank 0 609 - // - Otherwise use the mean rank of this repository, to avoid giving it a big disadvantage 610 - func (r repoPathRanks) rank(path string, content []byte) float64 { 611 - if rank, ok := r.Paths[path]; ok { 612 - return rank 613 - } else if index.IsLowPriority(path, content) { 614 - return 0.0 615 - } else { 616 - return r.MeanRank 617 - } 618 - } 619 - 620 601 func newIgnoreMatcher(tree *object.Tree) (*ignore.Matcher, error) { 621 602 ignoreFile, err := tree.File(ignore.IgnoreFile) 622 603 if err == object.ErrFileNotFound {
-57
internal/gitindex/index_test.go
··· 776 776 } 777 777 } 778 778 779 - func TestRepoPathRanks(t *testing.T) { 780 - pathRanks := repoPathRanks{ 781 - Paths: map[string]float64{ 782 - "search.go": 10.23, 783 - "internal/index.go": 5.5, 784 - "internal/scratch.go": 0.0, 785 - "backend/search_test.go": 2.1, 786 - }, 787 - MeanRank: 3.3, 788 - } 789 - cases := []struct { 790 - name string 791 - path string 792 - rank float64 793 - }{ 794 - { 795 - name: "rank for standard file", 796 - path: "search.go", 797 - rank: 10.23, 798 - }, 799 - { 800 - name: "file with rank 0", 801 - path: "internal/scratch.go", 802 - rank: 0.0, 803 - }, 804 - { 805 - name: "rank for test file", 806 - path: "backend/search_test.go", 807 - rank: 2.1, 808 - }, 809 - { 810 - name: "file with missing rank", 811 - path: "internal/docs.md", 812 - rank: 3.3, 813 - }, 814 - { 815 - name: "test file with missing rank", 816 - path: "backend/index_test.go", 817 - rank: 0.0, 818 - }, 819 - { 820 - name: "third-party file with missing rank", 821 - path: "node_modules/search/index.js", 822 - rank: 0.0, 823 - }, 824 - } 825 - 826 - for _, tt := range cases { 827 - t.Run(tt.name, func(t *testing.T) { 828 - got := pathRanks.rank(tt.path, nil) 829 - if got != tt.rank { 830 - t.Errorf("expected file '%s' to have rank %f, but got %f", tt.path, tt.rank, got) 831 - } 832 - }) 833 - } 834 - } 835 - 836 779 func runScript(t *testing.T, cwd string, script string) { 837 780 t.Helper() 838 781