备份
This commit is contained in:
30
export/meilisearch.go
Normal file
30
export/meilisearch.go
Normal file
@ -0,0 +1,30 @@
|
||||
package export
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/meilisearch/meilisearch-go"
|
||||
"github.com/rs/xid"
|
||||
)
|
||||
|
||||
type MeiliSearch struct{}
|
||||
|
||||
func (*MeiliSearch) Export(exports chan interface{}) error {
|
||||
client := meilisearch.New("http://localhost:7700", meilisearch.WithAPIKey("123456789"))
|
||||
|
||||
// An index is where the documents are stored.
|
||||
index := client.Index("movies")
|
||||
|
||||
for res := range exports {
|
||||
data := res.(map[string]interface{})
|
||||
guid := xid.New().String()
|
||||
task, err := index.AddDocuments([]map[string]interface{}{
|
||||
{"id": guid, "title": data["title"].(string), "url": data["url"].(string), "html": data["html"].(string)},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(task.TaskUID)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user