search.utils

Attributes

T

T_co

HASHTAG

LANGUAGE_MAP

SPECIAL_CHARACTER_TRANS

Classes

classproperty

Abstract base class for generic types.

LanguageDetector

Detects languages with the help of lingua-language-detector.

Functions

language_from_locale(→ str)

normalize_text(→ str)

This does the same thing as unidecode, except it special-cases

searchable_sqlalchemy_models(...)

Searches through the given SQLAlchemy base and returns the classes

get_polymorphic_base(...)

Filter out models that are polymorphic subclasses of other

apply_searchable_polymorphic_filter(...)

Given a query and the corresponding model add a filter

extract_hashtags(→ list[str])

Module Contents

search.utils.T[source]
search.utils.T_co[source]
search.utils.HASHTAG[source]
search.utils.LANGUAGE_MAP[source]
search.utils.SPECIAL_CHARACTER_TRANS[source]
search.utils.language_from_locale(locale: str | None) str[source]
search.utils.normalize_text(text: str) str[source]

This does the same thing as unidecode, except it special-cases umlaut translation for German text.

search.utils.searchable_sqlalchemy_models(base: type[T]) collections.abc.Iterator[type[onegov.search.Searchable]][source]

Searches through the given SQLAlchemy base and returns the classes of all SQLAlchemy models found which inherit from the onegov.search.mixins.Searchable interface.

search.utils.get_polymorphic_base(model: type[onegov.search.mixins.Searchable]) type[onegov.core.orm.Base | onegov.search.mixins.Searchable][source]

Filter out models that are polymorphic subclasses of other models in order to save on queries.

search.utils.apply_searchable_polymorphic_filter(query: sqlalchemy.orm.Query[T], model: Any) sqlalchemy.orm.Query[T][source]

Given a query and the corresponding model add a filter that excludes any polymorphic variants, that are not searchable.

search.utils.extract_hashtags(text: str) list[str][source]
class search.utils.classproperty(f: collections.abc.Callable[[type[Any]], T_co])[source]

Bases: Generic[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
f[source]
__get__(obj: object | None, owner: type[object]) T_co[source]
class search.utils.LanguageDetector(supported_languages: collections.abc.Sequence[str])[source]

Detects languages with the help of lingua-language-detector.

supported_languages[source]
detector[source]
detect(text: str) str[source]
probabilities(text: str) list[lingua.ConfidenceValue][source]