Skip to content

Commit

Permalink
add group search context (as argument in ythe main search method) (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts committed Aug 29, 2019
1 parent 02b3c0a commit 8230572
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions isogeo_pysdk/api/routes_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def __init__(self, api_client=None):
@ApiDecorators._check_bearer_validity
def search(
self,
# application or group
group: str = None,
# semantic and objects filters
query: str = "",
share: str = None,
Expand All @@ -85,6 +87,7 @@ def search(
) -> MetadataSearch:
"""Search within the resources shared to the application. It's the mainly used method to retrieve metadata.
:param str group: context to search. Pass a workgroup UUID to search within a group or pass None (default) to search in a global context.
:param str query: search terms and semantic filters. Equivalent of
**q** parameter in Isogeo API. It could be a simple
string like *oil* or a tag like *keyword:isogeo:formations*
Expand Down Expand Up @@ -181,7 +184,16 @@ def search(
pass

# URL
url_resources_search = utils.get_request_base_url(route="resources/search")
if group is None:
logger.debug("Searching as application")
url_resources_search = utils.get_request_base_url(route="resources/search")
elif checker.check_is_uuid(group):
logger.debug("Searching as group")
url_resources_search = utils.get_request_base_url(
route="groups/{}/resources/search".format(group)
)
else:
raise ValueError

# SEARCH CASES

Expand All @@ -192,6 +204,8 @@ def search(
if expected_total is None:
# make an empty request with same filters
total_results = self.search(
# search context: application or group
group=group,
# filters
query=query,
share=share,
Expand All @@ -217,6 +231,8 @@ def search(
)
)
return self.search(
# search context: application or group
group=group,
# filters
query=query,
share=share,
Expand All @@ -238,6 +254,8 @@ def search(
else:
# store search args as dict
search_params = {
# search context: application or group
"group": group,
# filters
"query": query,
"include": include,
Expand All @@ -264,7 +282,7 @@ def search(
asyncio.set_event_loop(loop)

future_searches_concatenated = asyncio.ensure_future(
self._search_metadata_asynchronous(
self.search_metadata_asynchronous(
total_results=total_results, **search_params
)
)
Expand Down Expand Up @@ -329,17 +347,14 @@ def search(
return req_metadata_search

# -- SEARCH SUBMETHODS
async def _search_metadata_asynchronous(
async def search_metadata_asynchronous(
self, total_results: int, max_workers: int = 10, **kwargs
) -> MetadataSearch:
"""Meta async method used to request big searches (> 100 results), using asyncio.
It's a private method launched by the main search method.
Arguments:
total_results {int} -- total of results to retrieve
Keyword Arguments:
max_workers {int} -- maximum of workers to use as threads (default: {10})
:param int total_results: total of results to retrieve
:param int max_workers: maximum number of thread to use :class:`python.concurrent.futures`
:rtype: MetadataSearch
"""
Expand All @@ -358,6 +373,8 @@ async def _search_metadata_asynchronous(
executor,
partial(
self.search,
# search context: application or group
group=kwargs.get("group"),
# filters
query=kwargs.get("query"),
include=kwargs.get("include"),
Expand Down

0 comments on commit 8230572

Please sign in to comment.