From a77db23927c937bbf9d54e6c96cd18d2a4034c27 Mon Sep 17 00:00:00 2001 From: Frank Sauerburger <frank@sauerburger.com> Date: Sun, 28 Aug 2022 17:49:30 +0200 Subject: [PATCH] Add movie ids --- Makefile | 2 +- app.py | 21 +++++++++++++++++++-- deployment.yaml | 2 +- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index fd5f1da..55c692e 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -TAG=0.2.0 +TAG=0.3.0 build: DOCKER_DEFAULT_PLATFORM=linux/amd64 docker build -t gitlab.sauerburger.com:5049/frank/wakefield-movie-recommender:$(TAG) . diff --git a/app.py b/app.py index 7b61032..22d9b34 100644 --- a/app.py +++ b/app.py @@ -12,21 +12,38 @@ app = Flask(__name__) with open("examples/titles.json", encoding="utf-8") as fileobj: titles = json.load(fileobj) +movie_ids = {} index = qgram.QGramIndex() -for title, _ in titles.values(): +for tid, (title, _) in titles.items(): + movie_ids[title] = int(tid) index.add_term(title) + @app.route("/titles") def suggest(): """Serve movie title suggestions""" query = request.args.get("q") + + try: + length = int(request.args.get("l", 12)) + length = min(length, 100) + except ValueError: + length = 12 + results = [] if query: results = index.search(query) + results = results[:length] + + results = [ + (score, title, movie_ids[title]) + for score, title in results + ] + return { - "suggestions": results[:100] + "suggestions": results } @app.route("/titles/healthz") diff --git a/deployment.yaml b/deployment.yaml index adf83be..2c0d865 100644 --- a/deployment.yaml +++ b/deployment.yaml @@ -16,7 +16,7 @@ spec: spec: containers: - name: titles - image: gitlab.sauerburger.com:5049/frank/wakefield-movie-recommender:0.2.0 + image: gitlab.sauerburger.com:5049/frank/wakefield-movie-recommender:0.3.0 livenessProbe: httpGet: path: /titles/healthz -- GitLab