Skip to content
Snippets Groups Projects

Add api_origin_metadata_search.

3 unresolved threads

Migrated from D751 (view on Phabricator)

Merge request reports

Closed by Phabricator Migration userPhabricator Migration user 6 years ago (Dec 3, 2018 10:48am UTC)

Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
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)
  • We should've an hardcoded max for limit: uses can specify a larger value than that, but in that case the hardcoded value would win, restricting the result set size.

  • Please register or sign in to reply
  • Author Maintainer
    • Fix api_origin_metadata_search.
  • 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 (see swh.web.api.apiresponse module). If you want to handle the response directly, you must pass handle_response=True to the api_doc decorator.

    • Author Maintainer

      Fixed, thanks.

      I also added a test for that, which fails because Django infinite-loops while handling the exception -_-

    • Please register or sign in to reply
  • Merge request was returned for changes

  • Author Maintainer
    • Fix error handling + add test.
  • 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 \
  • Author Maintainer
    • Fix test.
  • Merge request was accepted

  • Antoine Lambert approved this merge request

    approved this merge request

  • mentioned in commit 2ed36c90

  • Author Maintainer
    • Fix limit handling.
    • Bound the limit to 100.
  • Author Maintainer

    Merge request was merged

  • closed

  • Please register or sign in to reply
    Loading