custom image for meilisearch bootstrap
Former-commit-id: d77f16337c9f25cdf13cf00d7383718b82951c84
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,6 +3,5 @@
|
|||||||
|
|
||||||
search/meilisearch
|
search/meilisearch
|
||||||
search/data.ms
|
search/data.ms
|
||||||
search/dumps
|
|
||||||
|
|
||||||
run.sh
|
run.sh
|
||||||
@@ -6,7 +6,6 @@ WORKDIR /
|
|||||||
COPY go.mod ./
|
COPY go.mod ./
|
||||||
COPY go.sum ./
|
COPY go.sum ./
|
||||||
COPY migrations ./migrations
|
COPY migrations ./migrations
|
||||||
RUN tar -xvf migrations/initial_data/cities500.tar.gz -C migrations/initial_data
|
|
||||||
|
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
|
|
||||||
|
|||||||
@@ -115,11 +115,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// bootstrap meilisearch
|
|
||||||
if err := bootstrapMeilisearch(client); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,102 +1,13 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/meilisearch/meilisearch-go"
|
"github.com/meilisearch/meilisearch-go"
|
||||||
"github.com/pocketbase/pocketbase/models"
|
"github.com/pocketbase/pocketbase/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
func hasIndex(index string, client *meilisearch.Client) (resp bool, err error) {
|
|
||||||
|
|
||||||
if _, err := client.GetIndex(index); err != nil {
|
|
||||||
if err.(*meilisearch.Error).StatusCode == 404 {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func bootstrapMeilisearch(client *meilisearch.Client) error {
|
|
||||||
indexExists, err := hasIndex("cities500", client)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if !indexExists {
|
|
||||||
|
|
||||||
jsonFile, err := os.Open("migrations/initial_data/cities500.json")
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer jsonFile.Close()
|
|
||||||
|
|
||||||
byteValue, err := io.ReadAll(jsonFile)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
var cities []map[string]interface{}
|
|
||||||
json.Unmarshal(byteValue, &cities)
|
|
||||||
|
|
||||||
_, err = client.CreateIndex(&meilisearch.IndexConfig{
|
|
||||||
Uid: "cities500",
|
|
||||||
PrimaryKey: "id",
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
settings := meilisearch.Settings{
|
|
||||||
SortableAttributes: []string{
|
|
||||||
"_geo",
|
|
||||||
},
|
|
||||||
FilterableAttributes: []string{
|
|
||||||
"_geo",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
_, err = client.Index("cities500").UpdateSettings(&settings)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
_, err = client.Index("cities500").AddDocuments(cities)
|
|
||||||
if err != nil {
|
|
||||||
return (err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
indexExists, err = hasIndex("trails", client)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if !indexExists {
|
|
||||||
_, err = client.CreateIndex(&meilisearch.IndexConfig{
|
|
||||||
Uid: "trails",
|
|
||||||
PrimaryKey: "id",
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
settings := meilisearch.Settings{
|
|
||||||
SortableAttributes: []string{
|
|
||||||
"name", "distance", "elevation_gain", "difficulty", "created",
|
|
||||||
},
|
|
||||||
FilterableAttributes: []string{
|
|
||||||
"category", "difficulty", "distance", "elevation_gain", "completed", "_geo", "public", "author",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
_, err = client.Index("trails").UpdateSettings(&settings)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func indexRecord(r *models.Record, client *meilisearch.Client) error {
|
func indexRecord(r *models.Record, client *meilisearch.Client) error {
|
||||||
documents := []map[string]interface{}{
|
documents := []map[string]interface{}{
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ x-common-env: &cenv
|
|||||||
services:
|
services:
|
||||||
search:
|
search:
|
||||||
container_name: wanderer-search
|
container_name: wanderer-search
|
||||||
image: getmeili/meilisearch:v1.6.2
|
build: ./search
|
||||||
environment:
|
environment:
|
||||||
<<: *cenv
|
<<: *cenv
|
||||||
MEILI_NO_ANALYTICS: true
|
MEILI_NO_ANALYTICS: true
|
||||||
|
|||||||
10
search/Dockerfile
Normal file
10
search/Dockerfile
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
FROM getmeili/meilisearch:v1.6.2
|
||||||
|
|
||||||
|
COPY ./migrations/migration.dump /meili_data/dumps/migration.dump
|
||||||
|
COPY ./run.sh /run.sh
|
||||||
|
|
||||||
|
RUN chmod +x /run.sh
|
||||||
|
|
||||||
|
CMD [ "/run.sh" ]
|
||||||
|
|
||||||
|
|
||||||
BIN
search/migrations/migration.dump
Normal file
BIN
search/migrations/migration.dump
Normal file
Binary file not shown.
Reference in New Issue
Block a user