diff --git a/src/indexer.py b/src/indexer.py index 6e3faab9308c4481af96851780406147713797f8..e2ad0bcd1ef3335d29ef05f4602e35d4964f9f1b 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 3ad4c113517d5f3b27fdc6b9ffcb33ef647950e3..db4a9443c40362bd01274540d39af10d8ce70815 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 4af6be0b1b69a0c4d1801eaecdfba800aea3d64a..5b066e28ef157b064b8e7cf23e6c2a4e2588d79d 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)