X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/fa9ab52217a8e6912fa4677fc7bb1da21044b470..561a8ca7780e1efa80173e6f0dfd5339aaf0b689:/apps/search/custom.py?ds=sidebyside diff --git a/apps/search/custom.py b/apps/search/custom.py index 6c16f228f..788b6c409 100644 --- a/apps/search/custom.py +++ b/apps/search/custom.py @@ -134,18 +134,22 @@ class CustomSolrInterface(sunburnt.SolrInterface): start = None end = None totlen = len(text) - matches_margins = map(lambda (s, e): (max(0, s - margins), min(totlen, e + margins)), matches) - (start, end) = matches_margins[0] - - for (s, e) in matches_margins[1:]: + matches_margins = map(lambda (s, e): + ((s, e), + (max(0, s - margins), min(totlen, e + margins))), + matches) + (start, end) = matches_margins[0][1] + matches = [] + for (m, (s, e)) in matches_margins[1:]: if end < s or start > e: continue start = min(start, s) end = max(end, e) - + matches.append(m) + snip = text[start:end] - matches = list(matches) matches.sort(lambda a, b: cmp(b[0], a[0])) + for (s, e) in matches: off = - start snip = snip[:e + off] + mark[1] + snip[e + off:]