From 0b2d108aa2dba77f9221245a3f763d0244c79702 Mon Sep 17 00:00:00 2001 From: yvesf Date: Wed, 24 Nov 2010 23:04:19 +0100 Subject: simplyfy query in excerpt --- web.py | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) (limited to 'web.py') diff --git a/web.py b/web.py index 505dfed..ed46d06 100644 --- a/web.py +++ b/web.py @@ -103,23 +103,10 @@ class MyHtmlFormatter(highlight.HtmlFormatter): @app.route("/excerpt//", methods=["GET"]) def do_excerpt(docnum, term): - def generator(q): - for result in searcher.search(q, limit=1, sortedby="pagenumber"): - terms = [ text for fieldname, text in q.all_terms() - if fieldname == "content" ] - excerpt = highlight.highlight(result.get("content"), - terms, - analysis.StandardAnalyzer(), - highlight.ContextFragmenter(terms, maxchars=400, charsbefore=40, charsafter=40), #highlight.SentenceFragmenter(maxchars=500), - MyHtmlFormatter()) - - yield json.dumps( { 'pagenumber':result.get("pagenumber"), - 'excerpt':excerpt, - 'docnum':result.docnum} ) - with index_book.reader() as reader: document = reader.stored_fields(docnum) - q = QueryParser("content").parse(term) + q = QueryParser("content").parse(term) + q = q.simplify(reader) terms = [ text for fieldname, text in q.all_terms() if fieldname == "content" ] excerpt = highlight.highlight(document['content'], -- cgit v1.2.1