summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--web.py17
1 files changed, 2 insertions, 15 deletions
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/<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'],