Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0a7e114
Embargo Revision
ivis-shiokawa Mar 9, 2026
468df28
fix format
ivis-shiokawa Mar 9, 2026
795d7cc
fix create_aggregations
ivis-shiokawa Mar 10, 2026
cd36044
fix Embargo revison
ivis-shiokawa Mar 11, 2026
7e8bd03
Embargo Unit Test
ivis-shiokawa Mar 17, 2026
e72444d
fix update_embargo_rights
ivis-shiokawa Mar 17, 2026
6c87719
refix update_embargo_rights
ivis-shiokawa Mar 19, 2026
006254f
Merge pull request #1098 from ivis-shiokawa/feature/ams_w2025_66b_2_e…
ivis-futagami Mar 23, 2026
3fd1f6c
fix accessrights query
ivis-shiokawa Mar 25, 2026
cfe0f75
fix embargoed access query
ivis-shiokawa Mar 25, 2026
38b24ae
Merge pull request #1115 from ivis-shiokawa/feature/ams_w2025_66b_2_e…
ivis-futagami Mar 25, 2026
dff2c7f
refix accessRights query
ivis-shiokawa Mar 26, 2026
8464de8
fix __get_accessrights_query
ivis-shiokawa Mar 26, 2026
25c960e
Merge pull request #1120 from ivis-shiokawa/feature/ams_w2025_66b_2_e…
ivis-futagami Mar 26, 2026
33661e9
fix json_loader
ivis-shiokawa Mar 26, 2026
afd25cd
fix access_rights_type_uri
ivis-shiokawa Mar 27, 2026
cc75b99
fix update_embargo_rights
ivis-shiokawa Mar 27, 2026
aeeb4e2
Merge pull request #1122 from ivis-shiokawa/feature/ams_w2025_66b_2_e…
ivis-futagami Mar 27, 2026
dc261af
fix embargo unit test
ivis-shiokawa Mar 31, 2026
a5c0f46
fix Embargo Updated
ivis-shiokawa Apr 7, 2026
9005267
Fixes for issues identified in unit tests
ivis-shiokawa Apr 9, 2026
3a8f5a5
fix updated date: Correction of Issues Pointed Out
ivis-shiokawa Apr 9, 2026
9bdcb2f
enbargoed fix updated unit test
ivis-shiokawa Apr 13, 2026
427f6b8
fix invenio_record test_api
ivis-shiokawa Apr 15, 2026
7c85261
fix invenio_resourcesyncserver query.py
ivis-shiokawa Apr 15, 2026
150521a
fix invenio-records updated
ivis-shiokawa Apr 15, 2026
7d3a68d
fix updated & range_query
ivis-shiokawa Apr 17, 2026
07c755a
fix range_query & _get_index_search_query
ivis-shiokawa Apr 17, 2026
10a3189
fix unit test: embargo updated
ivis-shiokawa Apr 20, 2026
c37145c
fix test_item_changes_search_factory
ivis-shiokawa Apr 21, 2026
43ab98a
fix test_item_changes_search_factory
ivis-shiokawa Apr 21, 2026
ca2909d
fix invenio-oaiserver test_query.py
ivis-shiokawa Apr 21, 2026
c3b8f4f
Merge pull request #1128 from ivis-shiokawa/feature/ams_w2025_66b_2_e…
ivis-futagami May 11, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
196 changes: 187 additions & 9 deletions modules/invenio-oaiserver/invenio_oaiserver/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def get_descendant_ids(index_id):
descendant_ids = db.session.query(cte.c.descendant_id).all()

return [descendant_id[0] for descendant_id in descendant_ids]


page_ = kwargs.get('resumptionToken', {}).get('page', 1)
size_ = current_app.config['OAISERVER_PAGE_SIZE']
Expand Down Expand Up @@ -187,20 +187,26 @@ def get_descendant_ids(index_id):
#search = search.query('match', **{'path': kwargs['set']})
#search = search.query('match', **{'_oai.sets': sets})
#search = search.query('terms', **{'_oai.sets': sets})

if not sets:
search = search.query('match_none')
else:
index_ids = [sets] + get_descendant_ids(sets)
search = search.query('terms', **{'_oai.sets': index_ids})

time_range = {}
if 'from_' in kwargs:
time_range['gte'] = kwargs['from_']
if 'until' in kwargs:
time_range['lte'] = kwargs['until']
if time_range:
search = search.filter('range', **{'_updated': time_range})
if current_app.config.get('WEKO_SEARCH_FIX_ACCESSRIGHTS', False):
if 'from_' in kwargs or 'until' in kwargs:
rq = range_query(kwargs.get('from_'), kwargs.get('until'))
if rq is not None:
search = search.filter(rq)
else:
time_range = {}
if 'from_' in kwargs:
time_range['gte'] = kwargs['from_']
if 'until' in kwargs:
time_range['lte'] = kwargs['until']
if time_range:
search = search.filter('range', **{'_updated': time_range})

search = search.query('match', **{'relation_version_is_last': 'true'})
search = search.query('terms', **{'publish_status': [
Expand Down Expand Up @@ -288,3 +294,175 @@ def items(self):
}

return Pagination(response)

def range_query(_from=None, _until=None):
"""Generate a search query considering update date changes.

Args:
_from (datetime or str or None):
Lower bound of update date.
_until (datetime or str or None):
Upper bound of update date.

Returns:
elasticsearch_dsl.query.Q or None:
The generated query object, or None if no range is specified.
"""

if isinstance(_from, datetime):
from_date = _from.strftime('%Y-%m-%d')
_from = _from.isoformat()
elif isinstance(_from, str) and len(_from) >= 10:
from_date = _from[:10]
else:
_from = None

if isinstance(_until, datetime):
until_date = _until.strftime('%Y-%m-%d')
_until = _until.isoformat()
elif isinstance(_until, str) and len(_until) >= 10:
until_date = _until[:10]
else:
_until = None

if _from is None and _until is None:
return None

now = datetime.now().strftime('%Y-%m-%d')

# First should condition

must_not_embargoed = Q(
'bool', must_not=[Q('term', accessRights='embargoed access')]
)
must_not_content_accessrole = Q(
'bool', must_not=[
Q(
'nested',
path='content',
query=Q('exists', field='content.accessrole.raw')
)
]
)
must_not_open_access = Q(
'nested',
path='content',
query=Q(
'bool',
must_not=[
Q('term', **{'content.accessrole.raw': 'open_access'}),
Q(
'bool',
must=[
Q('term', **{'content.accessrole.raw': 'open_date'}),
Q('range', **{'content.date.dateValue.raw': {'lte': now}})
]
)
]
)
)
should1 = Q(
'bool',
must=[
Q(
'bool',
should=[
must_not_embargoed,
must_not_content_accessrole,
must_not_open_access
]
),
Q(
'range',
**{
'_updated': {
**({'gte': _from} if _from else {}),
**({'lte': _until} if _until else {})
}
}
)
]
)

# Second should condition
must_not_open_access2 = Q(
'nested',
path='content',
query=Q(
'bool',
must_not=[
Q('term', **{'content.accessrole.raw': 'open_access'}),
Q(
'bool',
must=[
Q('term', **{'content.accessrole.raw': 'open_date'}),
Q('range', **{'content.date.dateValue.raw': {'lte': now}})
]
)
]
)
)

# from condition
from_should = []
if _from:
from_should.append(
Q(
'nested',
path='content',
query=Q(
'bool',
must=[
Q('term', **{'content.accessrole.raw': 'open_date'}),
Q('range', **{'content.date.dateValue.raw': {'gte': from_date}})
]
)
)
)
from_should.append(Q('range', **{'_updated': {'gte': _from}}))

# until condition
until_must = []
if _until:
until_must.append(
Q(
'bool',
must_not=[
Q(
'nested',
path='content',
query=Q(
'bool',
must=[
Q('term', **{'content.accessrole.raw': 'open_date'}),
Q('range', **{'content.date.dateValue.raw': {'gt': until_date}})
]
)
)
]
)
)
until_must.append(Q('range', **{'_updated': {'lte': _until}}))

must2 = [
Q('term', accessRights='embargoed access'),
Q(
'nested',
path='content',
query=Q('exists', field='content.accessrole.raw')
),
Q('bool', must_not=[must_not_open_access2])
]
if from_should:
must2.append(Q('bool', should=from_should))
if until_must:
must2.extend(until_must)

should2 = Q('bool', must=must2)

# Overall should
return Q(
'bool',
should=[should1, should2],
minimum_should_match=1
)
Loading
Loading