Skip to content

Commit 51f9e47

Browse files
authored
Merge pull request the-library-code#32 from kshepherd/search_with_configuration
Extend search_objects to allow configuration parameter
2 parents 6dd06f6 + 7fcb83d commit 51f9e47

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

dspace_rest_client/client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ def search_objects(
487487
size=20,
488488
sort=None,
489489
dso_type=None,
490+
configuration='default',
490491
embeds=None,
491492
):
492493
"""
@@ -498,6 +499,7 @@ def search_objects(
498499
@param size: size of page (aka. 'rows'), affects the page parameter above
499500
@param sort: sort eg. 'title,asc'
500501
@param dso_type: DSO type to further filter results
502+
@param configuration: Search (discovery) configuration to apply to the query
501503
@param embeds: Optional list of embeds to apply to each search object result
502504
@return: list of DspaceObject objects constructed from API resources
503505
"""
@@ -518,6 +520,8 @@ def search_objects(
518520
params["page"] = page
519521
if sort is not None:
520522
params["sort"] = sort
523+
if configuration is not None:
524+
params['configuration'] = configuration
521525

522526
r_json = self.fetch_resource(url=url, params={**params, **filters})
523527

@@ -548,6 +552,7 @@ def search_objects_iter(
548552
filters=None,
549553
dso_type=None,
550554
sort=None,
555+
configuration='default',
551556
embeds=None,
552557
):
553558
"""
@@ -557,6 +562,7 @@ def search_objects_iter(
557562
@param filters: discovery filters as dict eg. {'f.entityType': 'Publication,equals', ... }
558563
@param sort: sort eg. 'title,asc'
559564
@param dso_type: DSO type to further filter results
565+
@param configuration: Search (discovery) configuration to apply to the query
560566
@param embeds: Optional list of embeds to apply to each search object result
561567
@return: Iterator of SimpleDSpaceObject
562568
"""
@@ -572,6 +578,8 @@ def search_objects_iter(
572578
params["dsoType"] = dso_type
573579
if sort is not None:
574580
params["sort"] = sort
581+
if configuration is not None:
582+
params['configuration'] = configuration
575583

576584
return do_paginate(url, {**params, **filters})
577585

example.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@
4040
print('Error logging in! Giving up.')
4141
sys.exit(1)
4242

43+
# An example of searching for workflow items (any search configuration from discovery.xml can be used)
44+
# note that the results here depend on the workflow role / access of the logged in user
45+
search_results = d.search_objects(query='*:*', dso_type='item', configuration='workflow')
46+
for result in search_results:
47+
print(f'{result.name} ({result.uuid})')
48+
4349
# Put together some basic Community data.
4450
# See https://github.com/DSpace/RestContract/blob/main/communities.md
4551
community_data = {
@@ -214,7 +220,7 @@
214220
# scoped to this collection
215221
# (there is no collection/items endpoint, though there is a /mappedItems endpoint,
216222
# not yet implemented here)
217-
items = d.search_objects(query='*:*', scope=collection.uuid, dso_type='item')
223+
items = d.search_objects(query='*:*', scope=collection.uuid, dso_type='item', configuration='default')
218224
for item in items:
219225
print(f'{item.name} ({item.uuid})')
220226
# Get all bundles in this item

0 commit comments

Comments
 (0)