···805805}
806806807807// With this test we want to capture regressions in the names returned by our
808808-// language detection. We rely on the detected language and its spelling, for
809809-// example, in scoring (see scoreKind).
810810-func TestDetectLanguage(t *testing.T) {
808808+// language detection and the scores assigned to file matches. We rely on the
809809+// detected language and its spelling, for example, in scoring (see scoreKind).
810810+func TestScoring(t *testing.T) {
811811+ if os.Getenv("CI") == "" && checkCTags() == "" {
812812+ t.Skip("ctags not available")
813813+ }
811814 dir := t.TempDir()
812815813816 opts := Options{
···820823 cases := []struct {
821824 fileName string
822825 content []byte
826826+ query query.Q
823827 wantLanguage string
828828+ wantScore float64
824829 }{
825830 {
826831 fileName: "hw.java",
···833838 }
834839}
835840`),
841841+ query: &query.Substring{Content: true, Pattern: "lloWorld"},
836842 wantLanguage: "Java",
843843+ // 5500 (partial symbol at boundary) + 1000 (Java class) + 50 (partial word) + 400 (atom) + 10 (file order)
844844+ wantScore: 6960,
837845 },
838846 }
839847···856864 }
857865 defer ss.Close()
858866859859- srs, err := ss.Search(context.Background(), &query.Const{true}, new(zoekt.SearchOptions))
867867+ srs, err := ss.Search(context.Background(), c.query, new(zoekt.SearchOptions))
860868 if err != nil {
861869 t.Fatal(err)
862870 }
863871864872 if got, want := len(srs.Files), 1; got != want {
865873 t.Fatalf("file matches: want %d, got %d", want, got)
874874+ }
875875+876876+ if got := srs.Files[0].Score; got != c.wantScore {
877877+ t.Fatalf("score: want %f, got %f", c.wantScore, got)
866878 }
867879868880 if got := srs.Files[0].Language; got != c.wantLanguage {
+4-1
contentprovider.go
···348348 switch language {
349349 case "Java":
350350 switch kind {
351351- case "c": // classes
351351+ // 2022-03-30: go-ctags contains a regex rule for Java classes that sets "kind"
352352+ // to "classes" instead of "c". We have to cover both cases to support existing
353353+ // indexes.
354354+ case "c", "classes":
352355 return scoreKindMatch
353356 }
354357 }