From a1dd77d1156f1b57d027ab0d0afa8e17a90f7299 Mon Sep 17 00:00:00 2001 From: Shiny Nematoda Date: Thu, 7 Aug 2025 14:28:52 +0200 Subject: [PATCH] chore(dep): Update module meilisearch to v0.33 (#8788) Fixes the breakages with the version update... Co-authored-by: Renovate Bot Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8788 Reviewed-by: Gusted Co-authored-by: Shiny Nematoda Co-committed-by: Shiny Nematoda --- go.mod | 2 +- go.sum | 5 +-- .../indexer/issues/meilisearch/meilisearch.go | 14 +++--- .../issues/meilisearch/meilisearch_test.go | 44 ++++++++++--------- 4 files changed, 32 insertions(+), 33 deletions(-) diff --git a/go.mod b/go.mod index 1aeeb7ee63..5c6bd8e22d 100644 --- a/go.mod +++ b/go.mod @@ -73,7 +73,7 @@ require ( github.com/markbates/goth v1.80.0 github.com/mattn/go-isatty v0.0.20 github.com/mattn/go-sqlite3 v1.14.30 - github.com/meilisearch/meilisearch-go v0.31.0 + github.com/meilisearch/meilisearch-go v0.33.0 github.com/mholt/archiver/v3 v3.5.1 github.com/microcosm-cc/bluemonday v1.0.27 github.com/minio/minio-go/v7 v7.0.94 diff --git a/go.sum b/go.sum index 12642b5df1..192384aee5 100644 --- a/go.sum +++ b/go.sum @@ -267,7 +267,6 @@ github.com/gogs/chardet v0.0.0-20211120154057-b7413eaefb8f h1:3BSP1Tbs2djlpprl7w github.com/gogs/chardet v0.0.0-20211120154057-b7413eaefb8f/go.mod h1:Pcatq5tYkCW2Q6yrR2VRHlbHpZ/R4/7qyL1TCF7vl14= github.com/gogs/go-gogs-client v0.0.0-20210131175652-1d7215cd8d85 h1:UjoPNDAQ5JPCjlxoJd6K8ALZqSDDhk2ymieAZOVaDg0= github.com/gogs/go-gogs-client v0.0.0-20210131175652-1d7215cd8d85/go.mod h1:fR6z1Ie6rtF7kl/vBYMfgD5/G5B1blui7z426/sj2DU= -github.com/golang-jwt/jwt/v4 v4.5.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang-jwt/jwt/v4 v4.5.2 h1:YtQM7lnr8iZ+j5q71MGKkNw9Mn7AjHM68uc9g5fXeUI= github.com/golang-jwt/jwt/v4 v4.5.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang-jwt/jwt/v5 v5.3.0 h1:pv4AsKCKKZuqlgs5sUmn4x8UlGa0kEVt/puTpKx9vvo= @@ -401,8 +400,8 @@ github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebG github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y= github.com/mattn/go-sqlite3 v1.14.30 h1:bVreufq3EAIG1Quvws73du3/QgdeZ3myglJlrzSYYCY= github.com/mattn/go-sqlite3 v1.14.30/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= -github.com/meilisearch/meilisearch-go v0.31.0 h1:yZRhY1qJqdH8h6GFZALGtkDLyj8f9v5aJpsNMyrUmnY= -github.com/meilisearch/meilisearch-go v0.31.0/go.mod h1:aNtyuwurDg/ggxQIcKqWH6G9g2ptc8GyY7PLY4zMn/g= +github.com/meilisearch/meilisearch-go v0.33.0 h1:vDJtB5Ba5X0XaDmrazDiX89QEpi3zuee5Lvt7FJu7Q0= +github.com/meilisearch/meilisearch-go v0.33.0/go.mod h1:dY4nxhVc0Ext8Kn7u2YohJCsEjirg80DdcOmfNezUYg= github.com/mholt/acmez/v3 v3.1.2 h1:auob8J/0FhmdClQicvJvuDavgd5ezwLBfKuYmynhYzc= github.com/mholt/acmez/v3 v3.1.2/go.mod h1:L1wOU06KKvq7tswuMDwKdcHeKpFFgkppZy/y0DFxagQ= github.com/microcosm-cc/bluemonday v1.0.27 h1:MpEUotklkwCSLeH+Qdx1VJgNqLlpY2KXwXFM08ygZfk= diff --git a/modules/indexer/issues/meilisearch/meilisearch.go b/modules/indexer/issues/meilisearch/meilisearch.go index 17a8ba2452..8c83a7f417 100644 --- a/modules/indexer/issues/meilisearch/meilisearch.go +++ b/modules/indexer/issues/meilisearch/meilisearch.go @@ -13,6 +13,7 @@ import ( indexer_internal "forgejo.org/modules/indexer/internal" inner_meilisearch "forgejo.org/modules/indexer/internal/meilisearch" "forgejo.org/modules/indexer/issues/internal" + "forgejo.org/modules/json" "github.com/meilisearch/meilisearch-go" ) @@ -100,7 +101,7 @@ func (b *Indexer) Index(_ context.Context, issues ...*internal.IndexerData) erro return nil } for _, issue := range issues { - _, err := b.inner.Client.Index(b.inner.VersionedIndexName()).AddDocuments(issue) + _, err := b.inner.Client.Index(b.inner.VersionedIndexName()).AddDocuments(issue, nil) if err != nil { return err } @@ -305,18 +306,13 @@ func doubleQuoteKeyword(k string) string { func convertHits(searchRes *meilisearch.SearchResponse) ([]internal.Match, error) { hits := make([]internal.Match, 0, len(searchRes.Hits)) for _, hit := range searchRes.Hits { - hit, ok := hit.(map[string]any) - if !ok { - return nil, ErrMalformedResponse - } - - issueID, ok := hit["id"].(float64) - if !ok { + var issueID int64 + if err := json.Unmarshal(hit["id"], &issueID); err != nil { return nil, ErrMalformedResponse } hits = append(hits, internal.Match{ - ID: int64(issueID), + ID: issueID, }) } return hits, nil diff --git a/modules/indexer/issues/meilisearch/meilisearch_test.go b/modules/indexer/issues/meilisearch/meilisearch_test.go index 7637e8d6b4..810de77046 100644 --- a/modules/indexer/issues/meilisearch/meilisearch_test.go +++ b/modules/indexer/issues/meilisearch/meilisearch_test.go @@ -46,30 +46,34 @@ func TestMeilisearchIndexer(t *testing.T) { } func TestConvertHits(t *testing.T) { - _, err := convertHits(&meilisearch.SearchResponse{ - Hits: []any{"aa", "bb", "cc", "dd"}, - }) - require.ErrorIs(t, err, ErrMalformedResponse) + for _, invalidID := range []string{"\"aa\"", "{\"aa\":\"123\"}", "[\"aa\"]"} { + _, err := convertHits(&meilisearch.SearchResponse{ + Hits: meilisearch.Hits{ + meilisearch.Hit{"id": []byte(invalidID)}, + }, + }) + require.ErrorIs(t, err, ErrMalformedResponse) + } validResponse := &meilisearch.SearchResponse{ - Hits: []any{ - map[string]any{ - "id": float64(11), - "title": "a title", - "content": "issue body with no match", - "comments": []any{"hey what's up?", "I'm currently bowling", "nice"}, + Hits: meilisearch.Hits{ + meilisearch.Hit{ + "id": []byte("11"), + "title": []byte("\"a title\""), + "content": []byte("\"issue body with no match\""), + "comments": []byte("[\"hey what's up?\", \"I'm currently bowling\", \"nice\"]"), }, - map[string]any{ - "id": float64(22), - "title": "Bowling as title", - "content": "", - "comments": []any{}, + meilisearch.Hit{ + "id": []byte("22"), + "title": []byte("\"Bowling as title\""), + "content": []byte("\"\""), + "comments": []byte("[]"), }, - map[string]any{ - "id": float64(33), - "title": "Bowl-ing as fuzzy match", - "content": "", - "comments": []any{}, + meilisearch.Hit{ + "id": []byte("33"), + "title": []byte("\"Bowl-ing as fuzzy match\""), + "content": []byte("\"\""), + "comments": []byte("[]"), }, }, }