+ def remove_snippets(self, book):
+ book.snippet_set.all().delete()
+
+ def add_snippet(self, book, doc):
+ assert book.id == doc.pop('book_id')
+ # Fragments already exist and can be indexed where they live.
+ if 'fragment_anchor' in doc:
+ return
+
+ text = doc.pop('text')
+ header_index = doc.pop('header_index')
+ book.snippet_set.create(
+ sec=header_index,
+ text=text,
+ )
+