"""Django haystack `SearchIndex` module."""
from pages.models import Page

from haystack.indexes import SearchIndex, CharField, DateTimeField
from haystack import site


class PageIndex(SearchIndex):
    """Search index for pages content."""
    text = CharField(document=True, use_template=True)
    publication_date = DateTimeField(model_attr='publication_date')

    def get_queryset(self):
        """Used when the entire index for model is updated."""
        return Page.objects.published()


site.register(Page, PageIndex)
"""Django haystack `SearchIndex` module."""
from pages.models import Page

from haystack.indexes import SearchIndex, CharField, DateTimeField
from haystack import site


class PageIndex(SearchIndex):
    """Search index for pages content."""
    text = CharField(document=True, use_template=True)
    title = CharField(model_attr='title')
    publication_date = DateTimeField(model_attr='publication_date')

    def get_queryset(self):
        """Used when the entire index for model is updated."""
        return Page.objects.published()


site.register(Page, PageIndex)
Add a title attribute to the SearchIndex for pages.
Add a title attribute to the SearchIndex for pages.

This is useful when displaying a list of search results because we
can display the title of the result without hitting the database to
actually pull the page.

  """Django haystack `SearchIndex` module."""
  from pages.models import Page
  
  from haystack.indexes import SearchIndex, CharField, DateTimeField
  from haystack import site
  
  
  class PageIndex(SearchIndex):
      """Search index for pages content."""
      text = CharField(document=True, use_template=True)
+     title = CharField(model_attr='title')
      publication_date = DateTimeField(model_attr='publication_date')
  
      def get_queryset(self):
          """Used when the entire index for model is updated."""
          return Page.objects.published()
  
  
  site.register(Page, PageIndex)
Add a title attribute to the SearchIndex for pages.
## Code Before:
"""Django haystack `SearchIndex` module."""
from pages.models import Page

from haystack.indexes import SearchIndex, CharField, DateTimeField
from haystack import site


class PageIndex(SearchIndex):
    """Search index for pages content."""
    text = CharField(document=True, use_template=True)
    publication_date = DateTimeField(model_attr='publication_date')

    def get_queryset(self):
        """Used when the entire index for model is updated."""
        return Page.objects.published()


site.register(Page, PageIndex)
## Instruction:
Add a title attribute to the SearchIndex for pages.
## Code After:
"""Django haystack `SearchIndex` module."""
from pages.models import Page

from haystack.indexes import SearchIndex, CharField, DateTimeField
from haystack import site


class PageIndex(SearchIndex):
    """Search index for pages content."""
    text = CharField(document=True, use_template=True)
    title = CharField(model_attr='title')
    publication_date = DateTimeField(model_attr='publication_date')

    def get_queryset(self):
        """Used when the entire index for model is updated."""
        return Page.objects.published()


site.register(Page, PageIndex)