From e73be6cf40b50173753a65f6596eb582b1e072ea Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Tue, 12 Nov 2013 22:52:04 +0100 Subject: Article searching with Whoosh OK. --- pyaggr3g470r/search.py | 6 +++++- pyaggr3g470r/templates/layout.html | 4 ++-- pyaggr3g470r/templates/search.html | 43 ++++++++++++++++++++++++++++++++++++++ pyaggr3g470r/views.py | 19 +++++++++++++++++ 4 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 pyaggr3g470r/templates/search.html (limited to 'pyaggr3g470r') diff --git a/pyaggr3g470r/search.py b/pyaggr3g470r/search.py index 9fd67124..56aef3f6 100644 --- a/pyaggr3g470r/search.py +++ b/pyaggr3g470r/search.py @@ -34,6 +34,7 @@ from whoosh.fields import * from whoosh.query import * from whoosh.qparser import QueryParser from whoosh.writing import AsyncWriter +from collections import defaultdict import conf import utils @@ -101,6 +102,7 @@ def search(term): Search for `term` in the index. Returns a list of articles. """ + result_dict = defaultdict(list) try: ix = open_dir(indexdir) except (EmptyIndexError, OSError) as e: @@ -108,7 +110,9 @@ def search(term): with ix.searcher() as searcher: query = QueryParser("content", ix.schema).parse(term) results = searcher.search(query, limit=None) - return [(article["feed_id"], article["article_id"]) for article in results] + for article in results: + result_dict[article["feed_id"]].append(article["article_id"]) + return result_dict def nb_documents(): """ diff --git a/pyaggr3g470r/templates/layout.html b/pyaggr3g470r/templates/layout.html index 620f1ca5..0ab81b70 100644 --- a/pyaggr3g470r/templates/layout.html +++ b/pyaggr3g470r/templates/layout.html @@ -57,9 +57,9 @@
  • About
  • Logout
  • -