summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryvesf <yvesf-git@xapek.org>2010-11-24 23:04:19 +0100
committeryvesf <yvesf-git@xapek.org>2010-11-24 23:04:19 +0100
commit0b2d108aa2dba77f9221245a3f763d0244c79702 (patch)
tree2f02dad41f186aad430672fb5dd0dcd24084baee
parent9f105d305dda4a0b53f42c215e866d482b048007 (diff)
downloadbooksearch-0b2d108aa2dba77f9221245a3f763d0244c79702.tar.gz
booksearch-0b2d108aa2dba77f9221245a3f763d0244c79702.zip
simplyfy query in excerpt
-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'],