search.utils

Attributes

T

T_co

HASHTAG

_invalid_index_characters

Classes

classproperty

Abstract base class for generic types.

LanguageDetector

Detects languages with the help of langdetect.

Functions

searchable_sqlalchemy_models(→ Iterator[type[Searchable]])

Searches through the given SQLAlchemy base and returns the classes

is_valid_index_name(→ bool)

Checks if the given name is a valid elasticsearch index name.

is_valid_type_name(→ bool)

normalize_index_segment(→ str)

hash_mapping(→ str)

extract_hashtags(→ list[str])

iter_subclasses(→ Iterator[type[T]])

related_types(→ set[str])

Gathers all related es type names from the given model. A type is

Module Contents

search.utils.T[source]
search.utils.T_co[source]
search.utils.HASHTAG[source]
search.utils.searchable_sqlalchemy_models(base: type[T]) Iterator[type[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._invalid_index_characters[source]
search.utils.is_valid_index_name(name: str) bool[source]

Checks if the given name is a valid elasticsearch index name. Elasticsearch does it’s own checks, but we can do it earlier and we are a bit stricter.

search.utils.is_valid_type_name(name: str) bool[source]
search.utils.normalize_index_segment(segment: str, allow_wildcards: bool) str[source]
search.utils.hash_mapping(mapping: dict[str, Any]) str[source]
search.utils.extract_hashtags(text: str) list[str][source]
class search.utils.classproperty(f: 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]
search.utils.iter_subclasses(baseclass: type[T]) Iterator[type[T]][source]
search.utils.related_types(model: type[object]) set[str][source]

Gathers all related es type names from the given model. A type is counted as related a model is part of a polymorphic setup.

If no polymorphic identity is found, the result is simply a set with the model’s type itself.

class search.utils.LanguageDetector(supported_languages: Sequence[str])[source]

Detects languages with the help of langdetect.

Unlike langdetect this detector may be limited to a subset of all supported languages, which may improve accuracy if the subset is known and saves some memory.

supported_languages[source]
factory[source]
spawn_detector(text: str) langdetect.detector.Detector[source]
detect(text: str) str[source]
probabilities(text: str) list[langdetect.language.Language][source]