fixed broken HTMLs in ps_product_lang
This commit is contained in:
@@ -51,15 +51,39 @@ func (s *MeiliService) CreateIndex(id_lang uint) error {
|
||||
|
||||
nextMeiliProduct.ProductID = products[i].ProductID
|
||||
nextMeiliProduct.Name = products[i].Name
|
||||
nextMeiliProduct.Description = cleanHTML(products[i].Description)
|
||||
nextMeiliProduct.DescriptionShort = cleanHTML(products[i].DescriptionShort)
|
||||
nextMeiliProduct.Usage = cleanHTML(products[i].Usage)
|
||||
|
||||
nextMeiliProduct.Description, err = cleanHTML(products[i].Description)
|
||||
if err != nil {
|
||||
fmt.Printf("nextMeiliProduct.Description: %v\n", nextMeiliProduct.Description)
|
||||
fmt.Printf("products[i].ProductID: %v\n", products[i].ProductID)
|
||||
fmt.Println("failed at description")
|
||||
fmt.Printf("err: %v\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
nextMeiliProduct.DescriptionShort, err = cleanHTML(products[i].DescriptionShort)
|
||||
if err != nil {
|
||||
fmt.Printf("nextMeiliProduct.DescriptionShort: %v\n", nextMeiliProduct.DescriptionShort)
|
||||
fmt.Printf("products[i].ProductID: %v\n", products[i].ProductID)
|
||||
fmt.Println("failed at description short")
|
||||
fmt.Printf("err: %v\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
nextMeiliProduct.Usage, err = cleanHTML(products[i].Usage)
|
||||
if err != nil {
|
||||
fmt.Printf("nextMeiliProduct.Usage: %v\n", nextMeiliProduct.Usage)
|
||||
fmt.Printf("products[i].ProductID: %v\n", products[i].ProductID)
|
||||
fmt.Println("failed at usage")
|
||||
fmt.Printf("err: %v\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
meiliProducts = append(meiliProducts, nextMeiliProduct)
|
||||
}
|
||||
|
||||
indexName := "meili_products_shop" + strconv.FormatInt(constdata.SHOP_ID, 10) + "_lang" + strconv.FormatInt(int64(id_lang), 10)
|
||||
primaryKey := "product_id"
|
||||
primaryKey := "ProductID"
|
||||
docOptions := &meilisearch.DocumentOptions{
|
||||
PrimaryKey: &primaryKey,
|
||||
SkipCreation: false,
|
||||
@@ -123,7 +147,7 @@ func (s *MeiliService) HealthCheck() (*meilisearch.Health, error) {
|
||||
}
|
||||
|
||||
// remove all tags from HTML text
|
||||
func cleanHTML(s string) string {
|
||||
func cleanHTML(s string) (string, error) {
|
||||
r := strings.NewReader(s)
|
||||
d := xml.NewDecoder(r)
|
||||
|
||||
@@ -137,19 +161,25 @@ func cleanHTML(s string) string {
|
||||
token, err := d.Token()
|
||||
if err == io.EOF {
|
||||
break
|
||||
} else if err != nil {
|
||||
return text, err
|
||||
}
|
||||
|
||||
switch v := token.(type) {
|
||||
case xml.StartElement:
|
||||
text += "\n"
|
||||
if len(text) > 0 && text[len(text)-1] != '\n' {
|
||||
text += " \n "
|
||||
}
|
||||
case xml.EndElement:
|
||||
case xml.CharData:
|
||||
text += string(v)
|
||||
if strings.TrimSpace(string(v)) != "" {
|
||||
text += string(v)
|
||||
}
|
||||
case xml.Comment:
|
||||
case xml.ProcInst:
|
||||
case xml.Directive:
|
||||
}
|
||||
}
|
||||
|
||||
return text
|
||||
return text, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user