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

Configure Feed

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

ranking: add test for scoring based on ctags (#313)

Now that we have ctags available on CI we can add tests that check
regressions of our scoring.

+34 -20
+14 -15
build/builder.go
··· 230 230 temp, final string 231 231 } 232 232 233 - // SetDefaults sets reasonable default options. 234 - func (o *Options) SetDefaults() { 235 - if o.CTags == "" { 236 - if ctags := os.Getenv("CTAGS_COMMAND"); ctags != "" { 237 - o.CTags = ctags 238 - } 233 + func checkCTags() string { 234 + if ctags := os.Getenv("CTAGS_COMMAND"); ctags != "" { 235 + return ctags 236 + } 237 + 238 + if ctags, err := exec.LookPath("universal-ctags"); err == nil { 239 + return ctags 239 240 } 240 241 241 - if o.CTags == "" { 242 - ctags, err := exec.LookPath("universal-ctags") 243 - if err == nil { 244 - o.CTags = ctags 245 - } 242 + if ctags, err := exec.LookPath("ctags-exuberant"); err == nil { 243 + return ctags 246 244 } 245 + return "" 246 + } 247 247 248 + // SetDefaults sets reasonable default options. 249 + func (o *Options) SetDefaults() { 248 250 if o.CTags == "" { 249 - ctags, err := exec.LookPath("ctags-exuberant") 250 - if err == nil { 251 - o.CTags = ctags 252 - } 251 + o.CTags = checkCTags() 253 252 } 254 253 255 254 if o.Parallelism == 0 {
+16 -4
build/e2e_test.go
··· 805 805 } 806 806 807 807 // With this test we want to capture regressions in the names returned by our 808 - // language detection. We rely on the detected language and its spelling, for 809 - // example, in scoring (see scoreKind). 810 - func TestDetectLanguage(t *testing.T) { 808 + // language detection and the scores assigned to file matches. We rely on the 809 + // detected language and its spelling, for example, in scoring (see scoreKind). 810 + func TestScoring(t *testing.T) { 811 + if os.Getenv("CI") == "" && checkCTags() == "" { 812 + t.Skip("ctags not available") 813 + } 811 814 dir := t.TempDir() 812 815 813 816 opts := Options{ ··· 820 823 cases := []struct { 821 824 fileName string 822 825 content []byte 826 + query query.Q 823 827 wantLanguage string 828 + wantScore float64 824 829 }{ 825 830 { 826 831 fileName: "hw.java", ··· 833 838 } 834 839 } 835 840 `), 841 + query: &query.Substring{Content: true, Pattern: "lloWorld"}, 836 842 wantLanguage: "Java", 843 + // 5500 (partial symbol at boundary) + 1000 (Java class) + 50 (partial word) + 400 (atom) + 10 (file order) 844 + wantScore: 6960, 837 845 }, 838 846 } 839 847 ··· 856 864 } 857 865 defer ss.Close() 858 866 859 - srs, err := ss.Search(context.Background(), &query.Const{true}, new(zoekt.SearchOptions)) 867 + srs, err := ss.Search(context.Background(), c.query, new(zoekt.SearchOptions)) 860 868 if err != nil { 861 869 t.Fatal(err) 862 870 } 863 871 864 872 if got, want := len(srs.Files), 1; got != want { 865 873 t.Fatalf("file matches: want %d, got %d", want, got) 874 + } 875 + 876 + if got := srs.Files[0].Score; got != c.wantScore { 877 + t.Fatalf("score: want %f, got %f", c.wantScore, got) 866 878 } 867 879 868 880 if got := srs.Files[0].Language; got != c.wantLanguage {
+4 -1
contentprovider.go
··· 348 348 switch language { 349 349 case "Java": 350 350 switch kind { 351 - case "c": // classes 351 + // 2022-03-30: go-ctags contains a regex rule for Java classes that sets "kind" 352 + // to "classes" instead of "c". We have to cover both cases to support existing 353 + // indexes. 354 + case "c", "classes": 352 355 return scoreKindMatch 353 356 } 354 357 }