From 6f2ba32537c60c2e3be8b03acb6c333737da1de9 Mon Sep 17 00:00:00 2001 From: Israel Yago Pereira Date: Tue, 24 Aug 2021 13:42:06 -0300 Subject: [PATCH] Index and return meta tag description --- src/indexer.py | 1 + src/post.py | 4 ++++ src/searcher.py | 4 ++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/indexer.py b/src/indexer.py index 6e3faab..e2ad0bc 100644 --- a/src/indexer.py +++ b/src/indexer.py @@ -29,6 +29,7 @@ def index_posts(es, posts): doc = { "title": post.title, "url": post.url, + "description": post.description, "body": post.body, "lang": post.lang, } diff --git a/src/post.py b/src/post.py index 3ad4c11..db4a944 100644 --- a/src/post.py +++ b/src/post.py @@ -4,5 +4,9 @@ class Post: self.title = title self.url = url self.body = body + + if len(description) > 200: + description = description[0:200] + "..." self.description = description + self.lang = lang \ No newline at end of file diff --git a/src/searcher.py b/src/searcher.py index 4af6be0..5b066e2 100644 --- a/src/searcher.py +++ b/src/searcher.py @@ -13,7 +13,7 @@ def search_query(es: Elasticsearch, user_query: str, language: str): "type": "best_fields", "fuzziness": "AUTO", "tie_breaker": 0.3, - "fields": ["title^3", "body"], + "fields": ["title^3", "description^2", "body"], } }, "highlight": { @@ -21,7 +21,7 @@ def search_query(es: Elasticsearch, user_query: str, language: str): "body" : {} } }, - "_source": ["title", "url", "body", "lang"] + "_source": ["title", "url", "description", "lang", "body"] } res = es.search(index=language, body=query) -- GitLab