MCPcopy Create free account
hub / github.com/django-haystack/django-haystack / prepare

Method prepare

haystack/indexes.py:213–232  ·  view source on GitHub ↗

Fetches and adds/alters data before indexing.

(self, obj)

Source from the content-addressed store, hash-verified

211 return index_qs.filter(**extra_lookup_kwargs).order_by(model._meta.pk.name)
212
213 def prepare(self, obj):
214 """
215 Fetches and adds/alters data before indexing.
216 """
217 self.prepared_data = {
218 ID: get_identifier(obj),
219 DJANGO_CT: get_model_ct(self.get_model()),
220 DJANGO_ID: force_str(obj.pk),
221 }
222
223 for field_name, field in self.fields.items():
224 # Use the possibly overridden name, which will default to the
225 # variable name of the field.
226 self.prepared_data[field.index_fieldname] = field.prepare(obj)
227
228 if hasattr(self, "prepare_%s" % field_name):
229 value = getattr(self, "prepare_%s" % field_name)(obj)
230 self.prepared_data[field.index_fieldname] = value
231
232 return self.prepared_data
233
234 def full_prepare(self, obj, with_string_facet=True):
235 self.prepared_data = self.prepare(obj)

Callers 1

full_prepareMethod · 0.95

Calls 2

get_modelMethod · 0.95
get_model_ctFunction · 0.90

Tested by

no test coverage detected