- doc.add(Field("fragment_anchor", fid,
- Field.Store.YES, Field.Index.NOT_ANALYZED))
- doc.add(Field("content",
- u' '.join(filter(lambda s: s is not None, frag['content'])),
- Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS))
- doc.add(Field("themes",
- u' '.join(filter(lambda s: s is not None, frag['themes'])),
- Field.Store.NO, Field.Index.ANALYZED))
-
- fragment_docs.append(doc)
- elif start is not None:
- for frag in fragments.values():
- frag['content'].append(start.text)
- elif end is not None:
- for frag in fragments.values():
- frag['content'].append(end.tail)
+
+ doc.add(NumericField("header_index", Field.Store.YES, True).setIntValue(position))
+ doc.add(Field("header_type", header.tag, Field.Store.YES, Field.Index.NOT_ANALYZED))
+
+ content = u' '.join([t for t in header.itertext()])
+ content = fix_format(content)
+
+ doc.add(Field("content", content, Field.Store.NO, Field.Index.ANALYZED))
+ snip_pos = snippets.add(content)
+ doc.add(NumericField("snippets_position", Field.Store.YES, True).setIntValue(snip_pos[0]))
+ doc.add(NumericField("snippets_length", Field.Store.YES, True).setIntValue(snip_pos[0]))
+
+ header_docs.append(doc)
+
+ for start, end in walker(master):
+ 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:]
+ fragments[fid]['themes'].append(start.text)
+ 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 <end> node, skip it
+ frag = fragments[fid]
+ del fragments[fid]
+
+ def jstr(l):
+ return u' '.join(map(
+ lambda x: x == None and u'(none)' or unicode(x),
+ l))
+
+ doc = self.create_book_doc(book)
+
+ doc.add(NumericField("header_index", Field.Store.YES, True).setIntValue(position))
+ doc.add(NumericField("header_span", Field.Store.YES, True).setIntValue(position - frag['start_section'] + 1))
+ doc.add(Field("header_type", frag['start_header'], Field.Store.YES, Field.Index.NOT_ANALYZED))
+
+ doc.add(Field("fragment_anchor", fid,
+ Field.Store.YES, Field.Index.NOT_ANALYZED))
+ doc.add(Field("content",
+ u' '.join(filter(lambda s: s is not None, frag['content'])),
+ Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS))
+
+ snip_pos = snippets.add(content)
+ doc.add(NumericField("snippets_position", Field.Store.YES, True).setIntValue(snip_pos[0]))
+ doc.add(NumericField("snippets_length", Field.Store.YES, True).setIntValue(snip_pos[0]))
+
+ doc.add(Field("themes",
+ u' '.join(filter(lambda s: s is not None, frag['themes'])),
+ Field.Store.NO, Field.Index.ANALYZED))
+
+ fragment_docs.append(doc)
+ elif start is not None:
+ for frag in fragments.values():
+ frag['content'].append(start.text)
+ elif end is not None:
+ for frag in fragments.values():
+ frag['content'].append(end.tail)
+ finally:
+ snippets.close()