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

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

import datetime

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)
"""Django haystack `SearchIndex` module."""
from pages.models import Page, Content

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

import datetime

class PageIndex(SearchIndex):
    """Search index for pages content."""
    text = CharField(document=True, use_template=True)
    title = CharField(model_attr='title')
    url = CharField(model_attr='get_absolute_url')
    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 url attribute to the SearchIndex for pages.
Add a url attribute to the SearchIndex for pages.

This is useful when displaying a list of search results because we
can create a link to the result without having to hit the database
for every object in the result list.
