fixed broken HTMLs in ps_product_lang
This commit is contained in:
2995
ADD_THIS_TO_SQL.sql
Normal file
2995
ADD_THIS_TO_SQL.sql
Normal file
File diff suppressed because it is too large
Load Diff
@@ -51,15 +51,39 @@ func (s *MeiliService) CreateIndex(id_lang uint) error {
|
|||||||
|
|
||||||
nextMeiliProduct.ProductID = products[i].ProductID
|
nextMeiliProduct.ProductID = products[i].ProductID
|
||||||
nextMeiliProduct.Name = products[i].Name
|
nextMeiliProduct.Name = products[i].Name
|
||||||
nextMeiliProduct.Description = cleanHTML(products[i].Description)
|
|
||||||
nextMeiliProduct.DescriptionShort = cleanHTML(products[i].DescriptionShort)
|
nextMeiliProduct.Description, err = cleanHTML(products[i].Description)
|
||||||
nextMeiliProduct.Usage = cleanHTML(products[i].Usage)
|
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)
|
meiliProducts = append(meiliProducts, nextMeiliProduct)
|
||||||
}
|
}
|
||||||
|
|
||||||
indexName := "meili_products_shop" + strconv.FormatInt(constdata.SHOP_ID, 10) + "_lang" + strconv.FormatInt(int64(id_lang), 10)
|
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{
|
docOptions := &meilisearch.DocumentOptions{
|
||||||
PrimaryKey: &primaryKey,
|
PrimaryKey: &primaryKey,
|
||||||
SkipCreation: false,
|
SkipCreation: false,
|
||||||
@@ -123,7 +147,7 @@ func (s *MeiliService) HealthCheck() (*meilisearch.Health, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// remove all tags from HTML text
|
// remove all tags from HTML text
|
||||||
func cleanHTML(s string) string {
|
func cleanHTML(s string) (string, error) {
|
||||||
r := strings.NewReader(s)
|
r := strings.NewReader(s)
|
||||||
d := xml.NewDecoder(r)
|
d := xml.NewDecoder(r)
|
||||||
|
|
||||||
@@ -137,19 +161,25 @@ func cleanHTML(s string) string {
|
|||||||
token, err := d.Token()
|
token, err := d.Token()
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
break
|
break
|
||||||
|
} else if err != nil {
|
||||||
|
return text, err
|
||||||
}
|
}
|
||||||
|
|
||||||
switch v := token.(type) {
|
switch v := token.(type) {
|
||||||
case xml.StartElement:
|
case xml.StartElement:
|
||||||
|
if len(text) > 0 && text[len(text)-1] != '\n' {
|
||||||
text += " \n "
|
text += " \n "
|
||||||
|
}
|
||||||
case xml.EndElement:
|
case xml.EndElement:
|
||||||
case xml.CharData:
|
case xml.CharData:
|
||||||
|
if strings.TrimSpace(string(v)) != "" {
|
||||||
text += string(v)
|
text += string(v)
|
||||||
|
}
|
||||||
case xml.Comment:
|
case xml.Comment:
|
||||||
case xml.ProcInst:
|
case xml.ProcInst:
|
||||||
case xml.Directive:
|
case xml.Directive:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return text
|
return text, nil
|
||||||
}
|
}
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -11,6 +11,7 @@ require (
|
|||||||
github.com/gofiber/fiber/v3 v3.1.0
|
github.com/gofiber/fiber/v3 v3.1.0
|
||||||
github.com/golang-jwt/jwt/v5 v5.3.1
|
github.com/golang-jwt/jwt/v5 v5.3.1
|
||||||
github.com/joho/godotenv v1.5.1
|
github.com/joho/godotenv v1.5.1
|
||||||
|
github.com/meilisearch/meilisearch-go v0.36.1
|
||||||
github.com/openai/openai-go/v3 v3.28.0
|
github.com/openai/openai-go/v3 v3.28.0
|
||||||
github.com/samber/lo v1.53.0
|
github.com/samber/lo v1.53.0
|
||||||
golang.org/x/crypto v0.48.0
|
golang.org/x/crypto v0.48.0
|
||||||
@@ -29,7 +30,6 @@ require (
|
|||||||
github.com/google/s2a-go v0.1.9 // indirect
|
github.com/google/s2a-go v0.1.9 // indirect
|
||||||
github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect
|
github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect
|
||||||
github.com/googleapis/gax-go/v2 v2.15.0 // indirect
|
github.com/googleapis/gax-go/v2 v2.15.0 // indirect
|
||||||
github.com/meilisearch/meilisearch-go v0.36.1 // indirect
|
|
||||||
github.com/tidwall/gjson v1.18.0 // indirect
|
github.com/tidwall/gjson v1.18.0 // indirect
|
||||||
github.com/tidwall/match v1.1.1 // indirect
|
github.com/tidwall/match v1.1.1 // indirect
|
||||||
github.com/tidwall/pretty v1.2.1 // indirect
|
github.com/tidwall/pretty v1.2.1 // indirect
|
||||||
|
|||||||
Reference in New Issue
Block a user