Skip to content

Commit

Permalink
factories: add "search_alias" for index field
Browse files Browse the repository at this point in the history
* Allow passing a `search_alias` for the record class index, or default
  to the record class' plural name.
  • Loading branch information
slint committed Nov 25, 2024
1 parent 96ff9ea commit e7535bf
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion invenio_records_resources/factories/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# details.

"""Record type factory."""

from invenio_db import db
from invenio_pidstore.providers.recordid_v2 import RecordIdProviderV2
from invenio_records.dumpers import SearchDumper
Expand Down Expand Up @@ -51,6 +52,7 @@ def __init__(
record_relations=None,
schema_path=None,
index_name=None,
search_alias=None,
search_options=None,
service_components=None,
permission_policy_cls=None,
Expand Down Expand Up @@ -81,6 +83,7 @@ def __init__(
self.record_relations = record_relations
self.schema_path = self._build_schema_path(schema_path)
self.index_name = self._build_index_name(index_name)
self.search_alias = search_alias or self.name_plural
self.model_cls_attrs = model_cls_attrs or {}
self.record_cls_attrs = record_cls_attrs or {}
self.resource_cls_attrs = resource_cls_attrs or {}
Expand Down Expand Up @@ -152,7 +155,7 @@ def create_record_class(self):
record_class_attributes = {
"model_cls": self.model_cls,
"schema": ConstantField("$schema", self.schema_path),
"index": IndexField(self.index_name),
"index": IndexField(self.index_name, search_alias=self.search_alias),
"pid": pid_field,
"dumper": self.record_dumper or SearchDumper(),
}
Expand Down

0 comments on commit e7535bf

Please sign in to comment.