search.mixins

Classes

Searchable

Defines the interface required for an object to be searchable.

ORMSearchable

Extends the default Searchable class with sensible defaults

SearchableContent

Adds search to all classes using the core's content mixin:

Module Contents

class search.mixins.Searchable[source]

Defines the interface required for an object to be searchable.

Note that es_id ``, ``es_properties and es_type_name must be class properties, not instance properties. So do this:

class X(Searchable):

    es_properties = {}
    es_type_name = 'x'

But do not do this:

class X(Searchable):

    @property
    def es_properties(self):
        return {}

    @property
    def es_type_name(self):
        return 'x'

The rest of the properties may be normal properties.

Polymorphic Identities

If SQLAlchemy’s Polymorphic Identities are used, each identity must have it’s own unqiue es_type_name. Though such models may share the es_properties from the base class, we don’t assume anything and store each polymorphic identity in its own index.

From the point of view of elasticsearch, each different polymorphic identity is a completely different model.

TEXT_SEARCH_COLUMN_NAME = 'fts_idx'[source]
TEXT_SEARCH_DATA_COLUMN_NAME = 'fts_idx_data'[source]
property fts_idx: Column[object][source]

The column for the full text search index.

classmethod es_properties() dict[str, Any][source]
Abstractmethod:

Returns the type mapping of this model. Each property in the mapping will be read from the model instance.

The returned object needs to be a dict or an object that provides a to_dict method.

Internally, onegov.search stores differing languages in different indices. It does this automatically through langauge detection, or by manually specifying a language.

Note that objects with multiple languages are not supported (each object is supposed to have exactly one language).

Onegov.search will automatically insert the right analyzer for types like these.

There’s currently only limited support for properties here, namely objects and nested mappings do not work! This is going to be added in the future though.

classmethod es_type_name() str[source]
Abstractmethod:

Returns the unique type name of the model.

classmethod es_id() str[source]
Abstractmethod:

The name of the id attribute (not the actual value!).

If you use this on an ORM model, be sure to use a primary key, all other properties are not available during deletion.

property es_language: str[source]

Defines the language of the object. By default ‘auto’ is used, which triggers automatic language detection. Automatic language detection is reasonably accurate if provided with enough text. Short texts are not detected easily.

When ‘auto’ is used, expect some content to be misclassified. You should then search over all languages, not just the epxected one.

This property can be used to manually set the language.

property es_public: bool[source]
Abstractmethod:

Returns True if the model is available to be found by the public. If false, only editors/admins will see this object in the search results.

property es_skip: bool[source]

Returns True if the indexing of this specific model instance should be skipped.

property es_suggestion: Sequence[str] | str[source]

Returns suggest-as-you-type value of the document. The field used for this property should also be indexed, or the suggestion will lead to nowhere.

If a single string is returned, the completion input equals the completion output. (My Title -> My Title)

If an array of strings is returned, all values are possible inputs and the first value is the output. (My Title/Title My -> My Title)

property es_last_change: datetime | None[source]

Returns the date the document was created/last modified.

property es_tags: list[str] | None[source]

Returns a list of tags associated with this content.

class search.mixins.ORMSearchable[source]

Bases: Searchable

Extends the default Searchable class with sensible defaults for SQLAlchemy orm models.

classmethod es_id() str[source]

The name of the id attribute (not the actual value!).

If you use this on an ORM model, be sure to use a primary key, all other properties are not available during deletion.

classmethod es_type_name() str[source]

Returns the unique type name of the model.

property es_last_change: datetime | None[source]

Returns the date the document was created/last modified.

class search.mixins.SearchableContent[source]

Bases: ORMSearchable

Adds search to all classes using the core’s content mixin: onegov.core.orm.mixins.content.ContentMixin

es_properties[source]
property es_public: bool[source]

Returns True if the model is available to be found by the public. If false, only editors/admins will see this object in the search results.

property es_suggestions: dict[str, list[str]][source]
property es_tags: list[str] | None[source]

Returns a list of tags associated with this content.