Created
February 9, 2012 17:48
-
-
Save toastdriven/1781529 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from haystack import indexes | |
# The easiest, per-object approach. | |
class CustomSearchIndex(indexes.SearchIndex, indexes.Indexable): | |
# The usual fields. | |
def prepare(self, obj): | |
prepared = super(CustomSearchIndex, self).prepare(obj) | |
# Assuming there's a relation... | |
for tag_set in obj.tag_sets.filter(is_official=True): | |
tags = [tag.name for tag in tag_set.tags.all()] | |
prepared["%s_tagset" % tag_set.name] = tags | |
prepared["%s__exact_tagset" % tag_set.name] = tags | |
return prepared | |
# In the solr.xml, add: | |
<dynamicField name="*_tagset" type="string" indexed="true" stored="true" multiValued="true" /> |
ghing
commented
Feb 9, 2012
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment