Skip to content

Commit

Permalink
entities: improve search link generation
Browse files Browse the repository at this point in the history
Co-Authored-by: Bertrand Zuchuat <[email protected]>
  • Loading branch information
Garfield-fr committed Nov 22, 2023
1 parent 9154312 commit 360b923
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
31 changes: 31 additions & 0 deletions rero_ils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
from rero_ils.modules.entities.local_entities.api import LocalEntity
from rero_ils.modules.entities.local_entities.permissions import \
LocalEntityPermissionPolicy
from rero_ils.modules.entities.models import EntityFieldWithRef, EntityType
from rero_ils.modules.entities.remote_entities.api import RemoteEntity
from rero_ils.modules.entities.remote_entities.permissions import \
RemoteEntityPermissionPolicy
Expand Down Expand Up @@ -3075,6 +3076,36 @@ def _(x):
}
RERO_ILS_DEFAULT_SUGGESTION_LIMIT = 10

ENTITIES_FIELDS_REF = [
EntityFieldWithRef.CONTRIBUTION,
EntityFieldWithRef.GENRE_FORM,
EntityFieldWithRef.SUBJECTS
]

ENTITIES_TYPES_FIELDS = {
EntityType.ORGANISATION: [
EntityFieldWithRef.CONTRIBUTION,
EntityFieldWithRef.SUBJECTS
],
EntityType.PERSON: [
EntityFieldWithRef.CONTRIBUTION,
EntityFieldWithRef.SUBJECTS
],
EntityType.PLACE: [
EntityFieldWithRef.SUBJECTS
],
EntityType.TEMPORAL: [
EntityFieldWithRef.SUBJECTS
],
EntityType.TOPIC: [
EntityFieldWithRef.SUBJECTS,
EntityFieldWithRef.GENRE_FORM
],
EntityType.WORK: [
EntityFieldWithRef.SUBJECTS
]
}

# =============================================================================
# RERO_ILS PATRON ROLES MANAGEMENT
# =============================================================================
Expand Down
8 changes: 8 additions & 0 deletions rero_ils/modules/entities/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,11 @@ class EntityResourceType:

REMOTE = 'remote'
LOCAL = 'local'


class EntityFieldWithRef:
"""Class to define field with $ref."""

CONTRIBUTION = 'contribution'
GENRE_FORM = 'genreForm'
SUBJECTS = 'subjects'
7 changes: 6 additions & 1 deletion rero_ils/modules/entities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,13 @@ def search_link(metadata):
:param metadata: the record metadata.
:returns: the search link.
"""
fields_config = current_app.config.get('ENTITIES_TYPES_FIELDS', {})
fields_ref = current_app.config.get('ENTITIES_FIELDS_REF', [])
entity_type = metadata['type']
fields = fields_config[entity_type] if (entity_type in fields_config) \
else fields_ref
queries = []
for field in ['contribution', 'subjects', 'genreForm']:
for field in fields:
if 'sources' in metadata:
# Remote entities
source, data = extract_data_from_remote_entity(metadata)
Expand Down
13 changes: 8 additions & 5 deletions tests/ui/entities/test_entities_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,21 @@ def test_sources_link(app):
assert {} == sources_link({})


def test_search_link(app, entity_organisation, local_entity_org):
def test_search_link(app, entity_organisation, local_entity_org, entity_topic):
"""Search link test."""

# test remote link
link = search_link(entity_organisation)
assert link == 'contribution.entity.pids.rero:A027711299 ' \
'OR subjects.entity.pids.rero:A027711299 ' \
'OR genreForm.entity.pids.rero:A027711299' \
'OR subjects.entity.pids.rero:A027711299' \
'&simple=0'
# test local link
link = search_link(local_entity_org)
assert link == 'contribution.entity.pids.local:locent_org ' \
'OR subjects.entity.pids.local:locent_org ' \
'OR genreForm.entity.pids.local:locent_org' \
'OR subjects.entity.pids.local:locent_org' \
'&simple=0'
# test Topic
link = search_link(entity_topic)
assert link == 'subjects.entity.pids.idref:030752787 ' \
'OR genreForm.entity.pids.idref:030752787' \
'&simple=0'

0 comments on commit 360b923

Please sign in to comment.