将HTML转成符合elasticsearch搜索的文本
(htmlStr string)
| 117 | |
| 118 | // 将HTML转成符合elasticsearch搜索的文本 |
| 119 | func (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设置等 |
| 140 | func (this *ElasticSearchClient) Init() (err error) { |
no test coverage detected