Skip to content

Commit

Permalink
slight improvement of the documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre-24 committed Jan 22, 2017
1 parent 55c66d7 commit 7db240f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
29 changes: 19 additions & 10 deletions doc/source/back-end/searchv2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -313,27 +313,36 @@ Les avantages de cette situation sont multiples:


Pour ce faire, l'indexation des chapitres (stocké à l'aide de la classe ``FakeChapter``, `voir ici <../back-end-code/tutorialv2.html#zds.tutorialv2.models.models_database.FakeChapter>`_) est effectuée en même temps que l'indexation des contenus publiés (``PublishedContent``).
En particulier, c'est la méthode ``get_es_indexable()`` qui est modifiée, profitant du fait que cette fonction peut retourner n'importe quel type de document à indexer.
En particulier, c'est la méthode ``get_es_indexable()`` qui est modifiée, profitant du fait que cette fonction peut envoyer n'importe quel type de document à indexer.

.. sourcecode:: python

@classmethod
def get_es_indexable(cls, force_reindexing=False):
@classmethod
def get_es_indexable(cls, force_reindexing=False, objects_per_batch=100):
"""Overridden to include chapters as well
"""

published_contents = super(PublishedContent, cls).get_es_indexable(force_reindexing)
indexable = []
index_manager = ESIndexManager(**settings.ES_SEARCH_INDEX)
for contents in super(PublishedContent, cls).get_es_indexable(force_reindexing, objects_per_batch=100):
chapters = []

for content in published_contents:
for content in contents:
versioned = content.load_public_version()

if versioned.has_sub_containers():
if versioned.has_sub_containers(): # chapters are only indexed for middle and big tuto

# delete possible previous chapters
if content.es_already_indexed:
index_manager.delete_by_query(
FakeChapter.get_es_document_type(), ES_Q('match', _routing=content.es_id))

# (re)index the new one(s)
for chapter in versioned.get_list_of_chapters():
chapters.append(FakeChapter(chapter, versioned, content.es_id))

indexable.extend(chapters)
indexable.extend(published_contents)
return indexable
yield chapters
yield contents



Expand Down
5 changes: 3 additions & 2 deletions zds/searchv2/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def get_es_mapping(self):

@classmethod
def get_es_indexable(cls, force_reindexing=False, objects_per_batch=100):
"""Get a list of object to be indexed. Through this method, you may limit the reindexing.
"""Yield objects to index by batch of ``objects_per_batch``.
.. attention::
You need to override this method (otherwise nothing will be indexed).
Expand Down Expand Up @@ -203,7 +203,7 @@ def get_es_django_indexable(cls, force_reindexing=False):

@classmethod
def get_es_indexable(cls, force_reindexing=False, objects_per_batch=100):
"""Override ``get_es_indexable()`` in order to use the Django querysets and batch
"""Override ``get_es_indexable()`` in order to use the Django querysets and batch objects.
"""

query = cls.get_es_django_indexable(force_reindexing).order_by('pk')
Expand All @@ -217,6 +217,7 @@ def get_es_indexable(cls, force_reindexing=False, objects_per_batch=100):

for obj in objects:
current_pk = obj.pk

yield objects

def save(self, *args, **kwargs):
Expand Down

0 comments on commit 7db240f

Please sign in to comment.