search.utils ============ .. py:module:: search.utils Attributes ---------- .. autoapisummary:: search.utils.T search.utils.T_co search.utils.HASHTAG search.utils.LANGUAGE_MAP search.utils.SPECIAL_CHARACTER_TRANS Classes ------- .. autoapisummary:: search.utils.classproperty search.utils.LanguageDetector Functions --------- .. autoapisummary:: search.utils.language_from_locale search.utils.normalize_text search.utils.searchable_sqlalchemy_models search.utils.get_polymorphic_base search.utils.apply_searchable_polymorphic_filter search.utils.extract_hashtags Module Contents --------------- .. py:data:: T .. py:data:: T_co .. py:data:: HASHTAG .. py:data:: LANGUAGE_MAP .. py:data:: SPECIAL_CHARACTER_TRANS .. py:function:: language_from_locale(locale: str | None) -> str .. py:function:: normalize_text(text: str) -> str This does the same thing as unidecode, except it special-cases umlaut translation for German text. .. py:function:: searchable_sqlalchemy_models(base: type[T]) -> collections.abc.Iterator[type[onegov.search.Searchable]] Searches through the given SQLAlchemy base and returns the classes of all SQLAlchemy models found which inherit from the :class:`onegov.search.mixins.Searchable` interface. .. py:function:: get_polymorphic_base(model: type[onegov.search.mixins.Searchable]) -> type[onegov.core.orm.Base | onegov.search.mixins.Searchable] Filter out models that are polymorphic subclasses of other models in order to save on queries. .. py:function:: apply_searchable_polymorphic_filter(query: sqlalchemy.orm.Query[T], model: Any, order_by_polymorphic_identity: bool = False) -> sqlalchemy.orm.Query[T] Given a query and the corresponding model add a filter that excludes any polymorphic variants, that are not searchable. .. py:function:: extract_hashtags(text: str) -> list[str] .. py:class:: classproperty(f: collections.abc.Callable[[type[Any]], T_co]) Bases: :py:obj:`Generic`\ [\ :py:obj:`T_co`\ ] Abstract base class for generic types. A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as:: class Mapping(Generic[KT, VT]): def __getitem__(self, key: KT) -> VT: ... # Etc. This class can then be used as follows:: def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT: try: return mapping[key] except KeyError: return default .. py:attribute:: f .. py:method:: __get__(obj: object | None, owner: type[object]) -> T_co .. py:class:: LanguageDetector(supported_languages: collections.abc.Sequence[str]) Detects languages with the help of lingua-language-detector. .. py:attribute:: supported_languages .. py:attribute:: detector .. py:method:: detect(text: str) -> str .. py:method:: probabilities(text: str) -> list[lingua.ConfidenceValue]