search.indexer
Classes
dict() -> new empty dictionary |
|
Detects languages with the help of lingua-language-detector. |
|
Handles the onegov.core orm events, translates them into indexing |
Module Contents
- class search.indexer.IndexTask[source]
Bases:
TypedDictdict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s
(key, value) pairs
- dict(iterable) -> new dictionary initialized as if via:
d = {} for k, v in iterable:
d[k] = v
- dict(**kwargs) -> new dictionary initialized with the name=value pairs
in the keyword argument list. For example: dict(one=1, two=2)
- class search.indexer.Indexer(mappings: TypeMappingRegistry, languages: set[str] | None = None)[source]
-
- index(tasks: list[IndexTask] | IndexTask, session: sqlalchemy.orm.Session) bool[source]
Update the ‘search_index’ table (full text search index) of the given object(s)/task(s).
In case of a bunch of tasks we are assuming they are all from the same schema and table in order to optimize the indexing process.
The upsert is executed directly on the given session’s transaction, without a savepoint of its own, so the caller is responsible for committing or rolling back.
- Parameters:
tasks – A list of tasks to index
session – Supply an active session
- Returns:
True if the indexing was successful, False otherwise
- class search.indexer.TypeMapping(name: str, mapping: dict[str, Any], title_property: str | None = None, model: type[onegov.search.Searchable] | None = None)[source]
- class search.indexer.TypeMappingRegistry[source]
- mappings: dict[str, TypeMapping][source]
- __getitem__(key: str) TypeMapping[source]
- __iter__() collections.abc.Iterator[TypeMapping][source]
- register_orm_base(base: type[object]) None[source]
Takes the given SQLAlchemy base and registers all
Searchableobjects.
- register_type(type_name: str, mapping: dict[str, Any], title_property: str | None = None, model: type[onegov.search.Searchable] | None = None) None[source]
Registers the given type with the given mapping. The mapping is as dictionary representing the part below the
mappings/type_name.See:
https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html#mappings
When the mapping changes, a new index is created internally and the alias to this index (the external name of the index) is pointed to this new index.
As a consequence, a change in the mapping requires a reindex.
- class search.indexer.ORMLanguageDetector(supported_languages: collections.abc.Sequence[str])[source]
Bases:
onegov.search.utils.LanguageDetectorDetects languages with the help of lingua-language-detector.
- class search.indexer.ORMEventTranslator(indexer: Indexer, max_queue_size: int = 0, languages: collections.abc.Sequence[str] = ('de', 'fr', 'en'))[source]
Handles the onegov.core orm events, translates them into indexing actions and puts the result into a queue for the indexer to consume.
The queue may be limited. Once the limit is reached, new events are no longer processed and an error is logged.