Skip to content

Commit

Permalink
implement search function
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanmi151 committed Jan 31, 2025
1 parent 7647e1e commit 82e3b49
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions geonetwork/gn_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,5 +184,26 @@ def delete_thesaurus_dict(self, name):
response.raise_for_status()
return response.json()

def search(self, query):
"""
Use geonetwork API to search metadata
:param query: query generated by frontend app like datahub of geonetwork
looks like that :
{"query":{"bool":{"must":[{"terms":{"isTemplate":["n"]}},{"multi_match":{"query":"test","type":"bool_prefix","fields":["resourceTitleObject.*^4","resourceAbstractObject.*^3","tag^2","resourceIdentifier"]}}],"must_not":{"terms":{"resourceType":["service","map","map/static","mapDigital"]}}}},"_source":["resourceTitleObject","uuid"],"from":0,"size":20}
"""
headers = {
'Accept': 'application/json',
'Content-Type' : 'application/json'
}
url = self.api_url + "/search/records/_search?bucket=bucket"
print(query)
resp = self.session.post(
url,
headers=headers,
data=query
)
resp.raise_for_status()
return resp.content

def close_session(self):
self.session.close()

0 comments on commit 82e3b49

Please sign in to comment.