From c98667831998d0467830537bb8c83d9e0df534a3 Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Mon, 16 Jan 2012 14:33:18 +0100 Subject: [PATCH 1/1] Fixed collecting content for snippet generation --- apps/search/index.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/apps/search/index.py b/apps/search/index.py index e59c38b17..7ab3de9dd 100644 --- a/apps/search/index.py +++ b/apps/search/index.py @@ -139,6 +139,7 @@ class Snippets(object): self.file.write(txt) pos = (self.position, l) self.position += l + print "SSSS %s - %s" % (pos, txt) return pos def get(self, pos): @@ -402,27 +403,25 @@ class Index(BaseIndex): if header.tag in self.skip_header_tags: continue - content = u' '.join([t for t in header.itertext()]) - content = fix_format(content) + # section content + content = [] - doc = add_part(snippets, header_index=position, header_type=header.tag, content=content) - - self.index.addDocument(doc) - for start, end in walker(header): + # handle fragments and themes. if start is not None and start.tag == 'begin': fid = start.attrib['id'][1:] fragments[fid] = {'content': [], 'themes': [], 'start_section': position, 'start_header': header.tag} - fragments[fid]['content'].append(start.tail) + elif start is not None and start.tag == 'motyw': fid = start.attrib['id'][1:] if start.text is not None: fragments[fid]['themes'] += map(str.strip, map(give_me_utf8, start.text.split(','))) - fragments[fid]['content'].append(start.tail) + elif start is not None and start.tag == 'end': fid = start.attrib['id'][1:] if fid not in fragments: continue # a broken node, skip it + # import pdb; pdb.set_trace() frag = fragments[fid] if frag['themes'] == []: continue # empty themes list. @@ -442,12 +441,23 @@ class Index(BaseIndex): themes=frag['themes']) self.index.addDocument(doc) + + # Collect content. elif start is not None: for frag in fragments.values(): frag['content'].append(start.text) + content.append(start.text) elif end is not None: for frag in fragments.values(): frag['content'].append(end.tail) + content.append(end.tail) + + # in the end, add a section text. + doc = add_part(snippets, header_index=position, header_type=header.tag, + content=fix_format(u' '.join(filter(lambda s: s is not None, frag['content'])))) + + self.index.addDocument(doc) + finally: snippets.close() -- 2.20.1