Blog Archive for May 20, 2010

Haystack Result Highlights

May 20, 2010

It's possible to get Haystack to show the part of the document that matches the search, and to highlight the matched terms in yellow.

forms.py

Modify the search form MySearchForm so that the superclass is HighlightedModelSearchForm:

from haystack.forms import HighlightedModelSearchForm
from django import forms
from myproject.project.models import Project

class MySearchForm …

Haystack Accessing Stored Fields

May 20, 2010

When you define a search_indexes.py file in Haystack, you can specify additional fields taken from the model. These fields are stored in the index:

import datetime
from haystack.indexes import *
from haystack import site
from myproject.xmlclass.models import XmlClass

class XmlClassIndex(SearchIndex):
    text = CharField(document=True …