aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Magorsch <arzano@gentoo.org>2020-08-30 14:09:05 +0200
committerMax Magorsch <arzano@gentoo.org>2020-08-30 14:09:05 +0200
commit64d3f8eb97ca7d3ef266453a417ccffbe14a2c39 (patch)
treeaa4c2c2a4d06c6c36573df587ecbce26a362a92a
parentImprove the searchPackages api query further (diff)
downloadsoko-64d3f8eb97ca7d3ef266453a417ccffbe14a2c39.tar.gz
soko-64d3f8eb97ca7d3ef266453a417ccffbe14a2c39.tar.bz2
soko-64d3f8eb97ca7d3ef266453a417ccffbe14a2c39.zip
Correctly return exact matches
Whenever we call the api and the searchTerm exactly matches one package, we expect just one Result. Signed-off-by: Max Magorsch <arzano@gentoo.org>
-rw-r--r--pkg/api/graphql/resolvers/resolver.go4
1 files changed, 4 insertions, 0 deletions
diff --git a/pkg/api/graphql/resolvers/resolver.go b/pkg/api/graphql/resolvers/resolver.go
index bb66854..2712cf1 100644
--- a/pkg/api/graphql/resolvers/resolver.go
+++ b/pkg/api/graphql/resolvers/resolver.go
@@ -233,6 +233,10 @@ func (r *queryResolver) PackageSearch(ctx context.Context, searchTerm *string, r
Select()
}
+ if len(gpackages) > 1 && (gpackages[0].Atom == *searchTerm || (gpackages[0].Name == *searchTerm && gpackages[1].Name != *searchTerm)) {
+ return gpackages[:1], nil
+ }
+
if err != nil {
return nil, errors.New("an error occurred while searching for the packages")
}