Add api_origin_metadata_search.
Migrated from D751 (view on Phabricator)
Merge request reports
Activity
Build has FAILED
Link to build: https://jenkins.softwareheritage.org/job/DWAPPS/job/tox/33/ See console output for more information: https://jenkins.softwareheritage.org/job/DWAPPS/job/tox/33/console
176 177 178 @api_route(r'/origin/metadata-search/', 179 'api-origin-metadata-search') 180 @api_doc('/origin/metadata-search/', noargs=True) 181 def api_origin_metadata_search(request): 182 """ 183 .. http:get:: /api/1/origin/metadata-search/ 184 185 Search for software origins whose metadata (expressed as a 186 JSON-LD/CodeMeta dictionary) match the provided criteria. 187 For now, only full-text search on this dictionary is supported. 188 189 :query str fulltext: a string that will be matched against origin metadata; 190 results are ranked and ordered starting with the best ones. 191 :query int limit: the maximum number of found origins to return 192 (bounded to 100) Build is green See https://jenkins.softwareheritage.org/job/DWAPPS/job/tox/34/ for more details.
204 **Allowed HTTP Methods:** :http:method:`get`, :http:method:`head`, :http:method:`options` 205 206 :statuscode 200: no error 207 208 **Example:** 209 210 .. parsed-literal:: 211 212 :swh_web_api:`origin/metadata-search/?limit=2&fulltext=Jane%20Doe` 213 """ # noqa 214 fulltext = request.query_params.get('fulltext', None) 215 limit = min(int(request.query_params.get('limit', '70')), 100) 216 217 if not fulltext: 218 content = '"fulltext" must be provided and non-empty.' 219 raise BadInputExc(content) You must raise a
swh.web.common.exc.BadInputExc
here.An exception filter is set by the
api_doc
decorator that will translate it to a response with status code 400.
By default the api endpoints must return list or dict that will get wrapped to a drf response (seeswh.web.api.apiresponse
module). If you want to handle the response directly, you must passhandle_response=True
to theapi_doc
decorator.
Build has FAILED
Link to build: https://jenkins.softwareheritage.org/job/DWAPPS/job/tox/35/ See console output for more information: https://jenkins.softwareheritage.org/job/DWAPPS/job/tox/35/console
281 'context': ['NpmMapping', 'CodemetaMapping'], 282 'type': 'local' 283 }, 284 'id': 3, 285 'name': 'swh-metadata-detector', 286 'version': '0.0.1', 287 } 288 }] 289 self.assertEqual(rv.data, expected_data) 290 mock_idx_storage.origin_intrinsic_metadata_search_fulltext \ 291 .assert_called_with(conjunction=['Jane Doe'], limit=70) 292 293 @patch('swh.web.common.service.idx_storage') 294 def test_api_origin_metadata_search_limit(self, mock_idx_storage): 295 # given 296 mock_idx_storage.origin_intrinsic_metadata_search_fulltext \ Build is green See https://jenkins.softwareheritage.org/job/DWAPPS/job/tox/36/ for more details.
mentioned in commit 2ed36c90
Build is green See https://jenkins.softwareheritage.org/job/DWAPPS/job/tox/37/ for more details.