SearchBackend API

class SearchBackend(site=None)

The SearchBackend class handles interaction directly with the backend. The search query it performs is usually fed to it from a SearchQuery class that has been built for that backend.

This class must be at least partially implemented on a per-backend basis and is usually accompanied by a SearchQuery class within the same module.

Unless you are writing a new backend, it is unlikely you need to directly access this class.

Method Reference

update

SearchBackend.update(self, index, iterable)

Updates the backend when given a SearchIndex and a collection of documents.

This method MUST be implemented by each backend, as it will be highly specific to each one.

remove

SearchBackend.remove(self, obj_or_string)

Removes a document/object from the backend. Can be either a model instance or the identifier (i.e. app_name.model_name.id) in the event the object no longer exists.

This method MUST be implemented by each backend, as it will be highly specific to each one.

clear

SearchBackend.clear(self, models=[])

Clears the backend of all documents/objects for a collection of models.

This method MUST be implemented by each backend, as it will be highly specific to each one.

prep_value

SearchBackend.prep_value(self, value)

Hook to give the backend a chance to prep an attribute value before sending it to the search engine.

By default, just force it to unicode.

more_like_this

SearchBackend.more_like_this(self, model_instance, additional_query_string=None, result_class=None)

Takes a model object and returns results the backend thinks are similar.

This method MUST be implemented by each backend, as it will be highly specific to each one.

build_schema

SearchBackend.build_schema(self, fields)

Takes a dictionary of fields and returns schema information.

This method MUST be implemented by each backend, as it will be highly specific to each one.

build_registered_models_list

SearchBackend.build_registered_models_list(self)

Builds a list of registered models for searching.

The search method should use this and the django_ct field to narrow the results (unless the user indicates not to). This helps ignore any results that are not currently registered models and ensures consistent caching.

Project Versions

Table Of Contents

Previous topic

SearchQuery API

Next topic

Running Tests

This Page