From 5e76a54b2b4046b4a6a177c04c3ad8fc3bc345fe Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Fri, 20 Jun 2014 15:36:10 +0100 Subject: [PATCH] Remove any duplicate search fields of the same type --- wagtail/wagtailsearch/indexed.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/wagtail/wagtailsearch/indexed.py b/wagtail/wagtailsearch/indexed.py index 347e41c0c..aba3003f7 100644 --- a/wagtail/wagtailsearch/indexed.py +++ b/wagtail/wagtailsearch/indexed.py @@ -101,6 +101,13 @@ class Indexed(object): # Add the field search_fields.append(SearchField(field_name, boost=boost, partial_match=partial_match, es_extra=config)) + # Remove any duplicate entries into search fields + # We need to take into account that fields can be indexed as both a SearchField and as a FilterField + search_fields_dict = {} + for field in search_fields: + search_fields_dict[(field.field_name, type(field))] = field + search_fields = search_fields_dict.values() + return search_fields @classmethod