aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Magorsch <arzano@gentoo.org>2020-08-27 22:50:50 +0200
committerMax Magorsch <arzano@gentoo.org>2020-08-27 22:50:50 +0200
commit5b8da9ca28da04272eadf08dadfd5217a9a55fe9 (patch)
tree7409afbf953feffacd83b1ed2b7c9197523e44a3
parentImprove the searchPackages api query (diff)
downloadsoko-5b8da9ca28da04272eadf08dadfd5217a9a55fe9.tar.gz
soko-5b8da9ca28da04272eadf08dadfd5217a9a55fe9.tar.bz2
soko-5b8da9ca28da04272eadf08dadfd5217a9a55fe9.zip
Improve the searchPackages api query further
Signed-off-by: Max Magorsch <arzano@gentoo.org>
-rw-r--r--pkg/api/graphql/generated/generated.go18
-rw-r--r--pkg/api/graphql/resolvers/resolver.go13
-rw-r--r--pkg/api/graphql/schema/query.graphql2
3 files changed, 18 insertions, 15 deletions
diff --git a/pkg/api/graphql/generated/generated.go b/pkg/api/graphql/generated/generated.go
index bcb7b23..36b27a9 100644
--- a/pkg/api/graphql/generated/generated.go
+++ b/pkg/api/graphql/generated/generated.go
@@ -190,7 +190,7 @@ type ComplexityRoot struct {
OutdatedPackage func(childComplexity int, atom *string, gentooVersion *string, newestVersion *string) int
OutdatedPackages func(childComplexity int, atom *string, gentooVersion *string, newestVersion *string) int
Package func(childComplexity int, atom *string, category *string, name *string, longdescription *string, precedingCommits *int) int
- PackageSearch func(childComplexity int, searchTerm *string, firstOnly *bool) int
+ PackageSearch func(childComplexity int, searchTerm *string, resultSize *int) int
Packages func(childComplexity int, atom *string, category *string, name *string, longdescription *string, precedingCommits *int) int
PkgCheckResult func(childComplexity int, atom *string, category *string, packageArg *string, version *string, cpv *string, class *string, message *string) int
PkgCheckResults func(childComplexity int, atom *string, category *string, packageArg *string, version *string, cpv *string, class *string, message *string) int
@@ -256,7 +256,7 @@ type QueryResolver interface {
PkgCheckResults(ctx context.Context, atom *string, category *string, packageArg *string, version *string, cpv *string, class *string, message *string) ([]*models.PkgCheckResult, error)
Package(ctx context.Context, atom *string, category *string, name *string, longdescription *string, precedingCommits *int) (*models.Package, error)
Packages(ctx context.Context, atom *string, category *string, name *string, longdescription *string, precedingCommits *int) ([]*models.Package, error)
- PackageSearch(ctx context.Context, searchTerm *string, firstOnly *bool) ([]*models.Package, error)
+ PackageSearch(ctx context.Context, searchTerm *string, resultSize *int) ([]*models.Package, error)
Useflag(ctx context.Context, id *string, name *string, scope *string, description *string, useExpand *string, packageArg *string) (*models.Useflag, error)
Useflags(ctx context.Context, id *string, name *string, scope *string, description *string, useExpand *string, packageArg *string) ([]*models.Useflag, error)
Version(ctx context.Context, id *string, category *string, packageArg *string, atom *string, version *string, slot *string, subslot *string, eapi *string, keywords *string, useflags *string, restricts *string, properties *string, homepage *string, license *string, description *string) (*models.Version, error)
@@ -1063,7 +1063,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return 0, false
}
- return e.complexity.Query.PackageSearch(childComplexity, args["searchTerm"].(*string), args["firstOnly"].(*bool)), true
+ return e.complexity.Query.PackageSearch(childComplexity, args["searchTerm"].(*string), args["resultSize"].(*int)), true
case "Query.packages":
if e.complexity.Query.Packages == nil {
@@ -1637,7 +1637,7 @@ type Query {
"Search by the given query"
searchTerm: String
"Return the first result only"
- firstOnly: Boolean
+ resultSize: Int
): [Package]
"A query to get a single useflag by any of the given parameters. Multiple parameters can be used. In case the useflag can not identified uniquely by the given parameters, an error is returned."
@@ -2698,14 +2698,14 @@ func (ec *executionContext) field_Query_packageSearch_args(ctx context.Context,
}
}
args["searchTerm"] = arg0
- var arg1 *bool
- if tmp, ok := rawArgs["firstOnly"]; ok {
- arg1, err = ec.unmarshalOBoolean2ᚖbool(ctx, tmp)
+ var arg1 *int
+ if tmp, ok := rawArgs["resultSize"]; ok {
+ arg1, err = ec.unmarshalOInt2ᚖint(ctx, tmp)
if err != nil {
return nil, err
}
}
- args["firstOnly"] = arg1
+ args["resultSize"] = arg1
return args, nil
}
@@ -6863,7 +6863,7 @@ func (ec *executionContext) _Query_packageSearch(ctx context.Context, field grap
fc.Args = args
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children
- return ec.resolvers.Query().PackageSearch(rctx, args["searchTerm"].(*string), args["firstOnly"].(*bool))
+ return ec.resolvers.Query().PackageSearch(rctx, args["searchTerm"].(*string), args["resultSize"].(*int))
})
if err != nil {
ec.Error(ctx, err)
diff --git a/pkg/api/graphql/resolvers/resolver.go b/pkg/api/graphql/resolvers/resolver.go
index d1a12eb..bb66854 100644
--- a/pkg/api/graphql/resolvers/resolver.go
+++ b/pkg/api/graphql/resolvers/resolver.go
@@ -202,9 +202,14 @@ func (r *queryResolver) Packages(ctx context.Context, atom *string, category *st
return gpackages, nil
}
-func (r *queryResolver) PackageSearch(ctx context.Context, searchTerm *string, firstOnly *bool) ([]*models.Package, error) {
+func (r *queryResolver) PackageSearch(ctx context.Context, searchTerm *string, resultSize *int) ([]*models.Package, error) {
var gpackages []*models.Package
+ limit := 100
+ if resultSize != nil {
+ limit = *resultSize
+ }
+
var err error
if strings.Contains(*searchTerm, "*") {
// if the query contains wildcards
@@ -214,6 +219,7 @@ func (r *queryResolver) PackageSearch(ctx context.Context, searchTerm *string, f
WhereOr("name LIKE ? ", wildcardSearchTerm).
Relation("PkgCheckResults").Relation("Bugs").Relation("PullRequests").Relation("ReverseDependencies").Relation("Commits").Relation("Versions").Relation("Versions.Masks").Relation("Versions.PkgCheckResults").Relation("Versions.Dependencies").Relation("PkgCheckResults").Relation("Outdated").
OrderExpr("name <-> '" + *searchTerm + "'").
+ Limit(limit).
Select()
} else {
// if the query contains no wildcards do a fuzzy search
@@ -223,6 +229,7 @@ func (r *queryResolver) PackageSearch(ctx context.Context, searchTerm *string, f
WhereOr("atom LIKE ? ", ("%" + *searchTerm + "%")).
Relation("PkgCheckResults").Relation("Bugs").Relation("PullRequests").Relation("ReverseDependencies").Relation("Commits").Relation("Versions").Relation("Versions.Masks").Relation("Versions.PkgCheckResults").Relation("Versions.Dependencies").Relation("PkgCheckResults").Relation("Outdated").
OrderExpr("name <-> '" + *searchTerm + "'").
+ Limit(limit).
Select()
}
@@ -230,10 +237,6 @@ func (r *queryResolver) PackageSearch(ctx context.Context, searchTerm *string, f
return nil, errors.New("an error occurred while searching for the packages")
}
- if firstOnly != nil && *firstOnly {
- return gpackages[:1], nil
- }
-
return gpackages, nil
}
diff --git a/pkg/api/graphql/schema/query.graphql b/pkg/api/graphql/schema/query.graphql
index a93dbf4..a7de981 100644
--- a/pkg/api/graphql/schema/query.graphql
+++ b/pkg/api/graphql/schema/query.graphql
@@ -183,7 +183,7 @@ type Query {
"Search by the given query"
searchTerm: String
"Return the first result only"
- firstOnly: Boolean
+ resultSize: Int
): [Package]
"A query to get a single useflag by any of the given parameters. Multiple parameters can be used. In case the useflag can not identified uniquely by the given parameters, an error is returned."