search.utils

Attributes

HASHTAG

LANGUAGE_MAP

Classes

classproperty

LanguageDetector

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

Functions

language_from_locale(→ str)

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.HASHTAG[source]
search.utils.LANGUAGE_MAP[source]
search.utils.language_from_locale(locale: str | None) str[source]
search.utils.searchable_sqlalchemy_models[T](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[sqlalchemy.orm.DeclarativeBase | onegov.search.mixins.Searchable]) type[sqlalchemy.orm.DeclarativeBase | 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[T](query: sqlalchemy.orm.Query[T], model: Any, order_by_polymorphic_identity: bool = False) 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[T_co](f: collections.abc.Callable[[type[Any]], T_co])[source]
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]