MCPcopy Index your code
hub / github.com/apache/answer / FetchMatchedExcerpt

Function FetchMatchedExcerpt

pkg/htmltext/htmltext.go:174–190  ·  view source on GitHub ↗

FetchMatchedExcerpt returns the matched excerpt according to the words

(html string, words []string, trimMarker string, trimLength int)

Source from the content-addressed store, hash-verified

172
173// FetchMatchedExcerpt returns the matched excerpt according to the words
174func FetchMatchedExcerpt(html string, words []string, trimMarker string, trimLength int) string {
175 text := ClearText(html)
176 matchedWord, matchedIndex := findFirstMatchedWord(text, words)
177 runeIndex := utf8.RuneCountInString(text[0:matchedIndex])
178
179 trimLength = max(0, trimLength)
180 runeOffset := runeIndex - trimLength
181 runeLimit := trimLength + trimLength + utf8.RuneCountInString(matchedWord)
182
183 textRuneCount := utf8.RuneCountInString(text)
184 if runeOffset+runeLimit > textRuneCount {
185 // Reserved extra chars before the matched word
186 runeOffset = textRuneCount - runeLimit
187 }
188
189 return FetchRangedExcerpt(html, trimMarker, runeOffset, runeLimit)
190}
191
192func GetPicByUrl(url string) string {
193 res, err := http.Get(url)

Callers 2

parseResultMethod · 0.92
TestFetchMatchedExcerptFunction · 0.85

Calls 3

ClearTextFunction · 0.85
findFirstMatchedWordFunction · 0.85
FetchRangedExcerptFunction · 0.85

Tested by 1

TestFetchMatchedExcerptFunction · 0.68