diff options
author | Arthur Zamarin <arthurzam@gentoo.org> | 2024-09-25 21:46:55 +0300 |
---|---|---|
committer | Arthur Zamarin <arthurzam@gentoo.org> | 2024-09-25 21:46:55 +0300 |
commit | 4efad00ca23bfa72b27a61ca954d11a18b0650d1 (patch) | |
tree | d3078587eee26ee6694deb729e4befc7c298be85 | |
parent | update golang version to 1.23.1 (diff) | |
download | soko-4efad00ca23bfa72b27a61ca954d11a18b0650d1.tar.gz soko-4efad00ca23bfa72b27a61ca954d11a18b0650d1.tar.bz2 soko-4efad00ca23bfa72b27a61ca954d11a18b0650d1.zip |
resolve.json: improve search quality
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
-rw-r--r-- | pkg/app/handler/packages/json.go | 4 | ||||
-rw-r--r-- | pkg/app/handler/packages/resolve.go | 16 |
2 files changed, 10 insertions, 10 deletions
diff --git a/pkg/app/handler/packages/json.go b/pkg/app/handler/packages/json.go index 057d410..f2d3085 100644 --- a/pkg/app/handler/packages/json.go +++ b/pkg/app/handler/packages/json.go @@ -134,10 +134,10 @@ func getJSONUseflag(gpackage *models.Package) Use { Description: useflag.Description, }) } - for _, flags := range useExpands { + for expandGroup, flags := range useExpands { for _, flag := range flags { useflags.UseExpand = append(useflags.UseExpand, Useflag{ - Name: flag.Name, + Name: expandGroup + "_" + flag.Name, Description: flag.Description, }) } diff --git a/pkg/app/handler/packages/resolve.go b/pkg/app/handler/packages/resolve.go index aeb0973..3f7a509 100644 --- a/pkg/app/handler/packages/resolve.go +++ b/pkg/app/handler/packages/resolve.go @@ -12,11 +12,12 @@ import ( // Show renders a template to show a given package func Resolve(w http.ResponseWriter, r *http.Request) { - atom := getParam(r, "atom") - gpackage := new(models.Package) - err := database.DBCon.Model(gpackage). - Where("atom LIKE ?", "%"+atom). + + var gpackage models.Package + err := database.DBCon.Model(&gpackage). + Where("atom LIKE ? ", "%"+atom+"%"). + OrderExpr("name <-> ?", atom). Relation("Versions"). Relation("Versions.Masks"). Relation("Commits", func(q *pg.Query) (*pg.Query, error) { @@ -33,9 +34,9 @@ func Resolve(w http.ResponseWriter, r *http.Request) { sortVersionsDesc(gpackage.Versions) - versions := getJSONVersions(gpackage) - maintainers := getJSONMaintainers(gpackage) - useflags := getJSONUseflag(gpackage) + versions := getJSONVersions(&gpackage) + maintainers := getJSONMaintainers(&gpackage) + useflags := getJSONUseflag(&gpackage) jsonPackage := Package{ Atom: gpackage.Atom, @@ -55,7 +56,6 @@ func Resolve(w http.ResponseWriter, r *http.Request) { } b, err := json.Marshal(result) - if err != nil { http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) |