MCPcopy Index your code
hub / github.com/django-haystack/django-haystack / collect_fields

Method collect_fields

haystack/utils/loading.py:260–323  ·  view source on GitHub ↗
(self, index)

Source from the content-addressed store, hash-verified

258 self._built = True
259
260 def collect_fields(self, index):
261 for fieldname, field_object in index.fields.items():
262 if field_object.document is True:
263 if field_object.index_fieldname != self.document_field:
264 raise SearchFieldError(
265 "All 'SearchIndex' classes must use the same '%s' fieldname for the 'document=True' field. Offending index is '%s'."
266 % (self.document_field, index)
267 )
268
269 # Stow the index_fieldname so we don't have to get it the hard way again.
270 if (
271 fieldname in self._fieldnames
272 and field_object.index_fieldname != self._fieldnames[fieldname]
273 ):
274 # We've already seen this field in the list. Raise an exception if index_fieldname differs.
275 raise SearchFieldError(
276 "All uses of the '%s' field need to use the same 'index_fieldname' attribute."
277 % fieldname
278 )
279
280 self._fieldnames[fieldname] = field_object.index_fieldname
281
282 # Stow the facet_fieldname so we don't have to look that up either.
283 if hasattr(field_object, "facet_for"):
284 if field_object.facet_for:
285 self._facet_fieldnames[field_object.facet_for] = fieldname
286 else:
287 self._facet_fieldnames[field_object.instance_name] = fieldname
288
289 # Copy the field in so we've got a unified schema.
290 if field_object.index_fieldname not in self.fields:
291 self.fields[field_object.index_fieldname] = field_object
292 self.fields[field_object.index_fieldname] = copy.copy(field_object)
293 else:
294 # If the field types are different, we can mostly
295 # safely ignore this. The exception is ``MultiValueField``,
296 # in which case we'll use it instead, copying over the
297 # values.
298 if field_object.is_multivalued:
299 old_field = self.fields[field_object.index_fieldname]
300 self.fields[field_object.index_fieldname] = field_object
301 self.fields[field_object.index_fieldname] = copy.copy(field_object)
302
303 # Switch it so we don't have to dupe the remaining
304 # checks.
305 field_object = old_field
306
307 # We've already got this field in the list. Ensure that
308 # what we hand back is a superset of all options that
309 # affect the schema.
310 if field_object.indexed is True:
311 self.fields[field_object.index_fieldname].indexed = True
312
313 if field_object.stored is True:
314 self.fields[field_object.index_fieldname].stored = True
315
316 if field_object.faceted is True:
317 self.fields[field_object.index_fieldname].faceted = True

Callers 1

buildMethod · 0.95

Calls 1

SearchFieldErrorClass · 0.90

Tested by

no test coverage detected