search.mixins ============= .. py:module:: search.mixins Classes ------- .. autoapisummary:: search.mixins.Searchable search.mixins.ORMSearchable search.mixins.SearchableContent Module Contents --------------- .. py:class:: Searchable Defines the interface required for an object to be searchable. Note that ``fts_id `` and ``fts_properties`` must be class properties, not instance properties. So do this:: class X(Searchable): fts_properties = {} But do not do this:: class X(Searchable): @property def fts_properties(self): return {} The rest of the properties may be normal properties. .. py:attribute:: fts_title_property :type: ClassVar[str | None] .. py:method:: fts_properties() -> dict[str, Any] :classmethod: :abstractmethod: Returns the type mapping of this model. Each property in the mapping will be read from the model instance. .. py:method:: fts_id() -> str :classmethod: :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. .. py:method:: fts_type_title() -> str | collections.abc.Callable[[Any], str] :classmethod: Returns the display name for this type of document or a callable which accepts the current request as a single positional argument and returns the display name. .. py:property:: fts_language :type: str 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 expected one. This property can be used to manually set the language. .. py:property:: fts_access :type: str Returns access level of the model. Defaults to `public`. .. py:property:: fts_public :type: bool :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. .. py:property:: fts_skip :type: bool Returns True if the indexing of this specific model instance should be skipped. .. py:property:: fts_suggestion :type: collections.abc.Sequence[str] | str 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) .. py:property:: fts_publication_start :type: datetime.datetime | None Returns the date when the document should become public. .. py:property:: fts_publication_end :type: datetime.datetime | None Returns the date when the document should stop being public. .. py:property:: fts_last_change :type: datetime.datetime | None Returns the date the document was created/last modified. Returning `None` indicates that the document's age/recency must not influence search ranking: the item should be treated as equally relevant regardless of how old it is. .. py:property:: fts_tags :type: list[str] | None Returns a list of tags associated with this content. .. py:class:: ORMSearchable Bases: :py:obj:`Searchable` Extends the default :class:`Searchable` class with sensible defaults for SQLAlchemy orm models. .. py:attribute:: fts_id :type: ClassVar[str] 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. .. py:property:: fts_last_change :type: datetime.datetime | None Returns the date the document was created/last modified. Returning `None` indicates that the document's age/recency must not influence search ranking: the item should be treated as equally relevant regardless of how old it is. .. py:class:: SearchableContent Bases: :py:obj:`ORMSearchable` Adds search to all classes using the core's content mixin: :class:`onegov.core.orm.mixins.content.ContentMixin` .. py:attribute:: fts_title_property :value: 'title' .. py:attribute:: fts_properties Returns the type mapping of this model. Each property in the mapping will be read from the model instance. .. py:property:: fts_public :type: bool 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. .. py:property:: fts_tags :type: list[str] | None Returns a list of tags associated with this content.