Search code examples
django-haystack

Django Haystack faceting multivalued strings -- unknown field tags_exact


The content on my site is tagged with strings of variable length, and I want to do faceted search on these tags. For example, a story might have tags, "civil war," "general grant," and "battle of gettysburg." I want to be able to do faceted search on the exact, non-tokenized strings.

Within my search_index.py, I defined:

tags = MultiValueField(faceted=True, indexed=True)

and I edited the schema.xml generated by build_solr_schema to make tags a string instead of text:

<field name="tags" type="string" indexed="true" stored="true" multiValued="true" />

Unfortunately when I get an error about tags_exact:

Failed to add documents to Solr: [Reason: None]
ERROR: [doc=application_stories.story.1] unknown field 'tags_exact'

I understand that the tags_exact field has something to do w/ Haystack's internal implementation of faceting, but how can I work around this?

Thanks!


Solution

  • search_index.py:

        tags = MultiValueField(faceted=True)
    

    schema.xml:

    <field name="tags" type="text" indexed="true" stored="true" multiValued="true" />
    <field name="tags_exact" type="string" indexed="true" stored="true" multiValued="true" />