31 lines
710 B
Go
31 lines
710 B
Go
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
|
|
}
|