diff options
Diffstat (limited to 'web.py')
-rw-r--r-- | web.py | 17 |
1 files changed, 2 insertions, 15 deletions
@@ -103,23 +103,10 @@ class MyHtmlFormatter(highlight.HtmlFormatter): @app.route("/excerpt/<int:docnum>/<path:term>", 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'], |