MCPcopy Index your code
hub / github.com/TruthHun/BookStack / html2Text

Method html2Text

models/elasticsearch.go:119–137  ·  view source on GitHub ↗

将HTML转成符合elasticsearch搜索的文本

(htmlStr string)

Source from the content-addressed store, hash-verified

117
118// 将HTML转成符合elasticsearch搜索的文本
119func (this *ElasticSearchClient) html2Text(htmlStr string) string {
120 var tags = []string{
121 "</p>", "</div>", "</code>", "</span>", "</pre>", "</blockquote>",
122 "</h1>", "</h2>", "</h3>", "</h4>", "</h5>", "</h6>", "</td>", "</th>",
123 "</i>", "</b>", "</strong>", "</a>", "</li>",
124 }
125
126 for _, tag := range tags {
127 htmlStr = strings.Replace(htmlStr, tag, tag+" ", -1)
128 }
129
130 htmlStr = strings.Replace(htmlStr, "\n", " ", -1)
131
132 gq, err := goquery.NewDocumentFromReader(strings.NewReader(htmlStr))
133 if err != nil {
134 return htmlStr
135 }
136 return gq.Text()
137}
138
139//初始化全文搜索客户端,包括检查索引是否存在,mapping设置等
140func (this *ElasticSearchClient) Init() (err error) {

Callers 3

GetDocsByIdMethod · 0.95
RebuildAllIndexMethod · 0.95
BuildIndexMethod · 0.95

Calls 1

ReplaceMethod · 0.45

Tested by

no test coverage detected