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

Configure Feed

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

score: remove unused contentProvider.matchScore (#725)

My last PR missed this. Now that we only score by candidateMatch we can
remove the matchScore implementation which was used to score LineMatch.

Test Plan: go test

-84
-84
contentprovider.go
··· 673 673 return maxScore.score, maxScore.what, symbolInfo 674 674 } 675 675 676 - func (p *contentProvider) matchScore(secs []DocumentSection, m *LineMatch, language string, debug bool) (float64, string) { 677 - type debugScore struct { 678 - what string 679 - score float64 680 - } 681 - 682 - score := &debugScore{} 683 - maxScore := &debugScore{} 684 - 685 - addScore := func(what string, s float64) { 686 - if s != 0 && debug { 687 - score.what += fmt.Sprintf("%s:%.2f, ", what, s) 688 - } 689 - score.score += s 690 - } 691 - 692 - data := p.data(m.FileName) 693 - filename := p.data(true) 694 - 695 - for _, f := range m.LineFragments { 696 - startBoundary := f.LineOffset < len(m.Line) && (f.LineOffset == 0 || byteClass(m.Line[f.LineOffset-1]) != byteClass(m.Line[f.LineOffset])) 697 - 698 - end := int(f.LineOffset) + f.MatchLength 699 - endBoundary := end > 0 && (end == len(m.Line) || byteClass(m.Line[end-1]) != byteClass(m.Line[end])) 700 - 701 - score.score = 0 702 - score.what = "" 703 - 704 - if startBoundary && endBoundary { 705 - addScore("WordMatch", scoreWordMatch) 706 - } else if startBoundary || endBoundary { 707 - addScore("PartialWordMatch", scorePartialWordMatch) 708 - } 709 - 710 - if m.FileName { 711 - sep := bytes.LastIndexByte(m.Line, '/') 712 - startMatch := sep+1 == f.LineOffset 713 - endMatch := len(m.Line) == f.LineOffset+f.MatchLength 714 - if startMatch && endMatch { 715 - addScore("Base", scoreBase) 716 - } else if startMatch || endMatch { 717 - addScore("EdgeBase", (scoreBase+scorePartialBase)/2) 718 - } else if sep < f.LineOffset { 719 - addScore("InnerBase", scorePartialBase) 720 - } 721 - } else if secIdx, ok := findSection(secs, f.Offset, uint32(f.MatchLength)); ok { 722 - sec := secs[secIdx] 723 - startMatch := sec.Start == f.Offset 724 - endMatch := sec.End == f.Offset+uint32(f.MatchLength) 725 - if startMatch && endMatch { 726 - addScore("Symbol", scoreSymbol) 727 - } else if startMatch || endMatch { 728 - addScore("EdgeSymbol", (scoreSymbol+scorePartialSymbol)/2) 729 - } else { 730 - addScore("InnerSymbol", scorePartialSymbol) 731 - } 732 - 733 - si := f.SymbolInfo 734 - if si == nil { 735 - // for non-symbol queries, we need to hydrate in SymbolInfo. 736 - start := p.id.fileEndSymbol[p.idx] 737 - si = p.id.symbols.data(start + uint32(secIdx)) 738 - } 739 - if si != nil { 740 - // the LineFragment may not be on a symbol, then si will be nil. 741 - symbolKind := ctags.ParseSymbolKind(si.Kind) 742 - sym := sectionSlice(data, sec) 743 - addScore(fmt.Sprintf("kind:%s:%s", language, si.Kind), scoreSymbolKind(language, filename, sym, symbolKind)) 744 - } 745 - } 746 - 747 - if score.score > maxScore.score { 748 - maxScore.score = score.score 749 - maxScore.what = score.what 750 - } 751 - } 752 - 753 - if debug { 754 - maxScore.what = fmt.Sprintf("score:%.2f <- %s", maxScore.score, strings.TrimSuffix(maxScore.what, ", ")) 755 - } 756 - 757 - return maxScore.score, maxScore.what 758 - } 759 - 760 676 // sectionSlice will return data[sec.Start:sec.End] but will clip Start and 761 677 // End such that it won't be out of range. 762 678 func sectionSlice(data []byte, sec DocumentSection) []byte {