diff --git a/swh/web/api/views/origin.py b/swh/web/api/views/origin.py --- a/swh/web/api/views/origin.py +++ b/swh/web/api/views/origin.py @@ -194,11 +194,9 @@ and only the Link header should be used for paginating through results. - :param string url_pattern: a string pattern or a regular expression + :param string url_pattern: a string pattern :query int limit: the maximum number of found origins to return (bounded to 1000) - :query boolean regexp: if true, consider provided pattern as a regular - expression and search origins whose urls match it :query boolean with_visit: if true, only return origins with at least one visit by Software heritage @@ -221,11 +219,10 @@ result = {} offset = int(request.query_params.get('offset', '0')) limit = min(int(request.query_params.get('limit', '70')), 1000) - regexp = request.query_params.get('regexp', 'false') with_visit = request.query_params.get('with_visit', 'false') results = api_lookup(service.search_origin, url_pattern, offset, limit, - bool(strtobool(regexp)), bool(strtobool(with_visit)), + bool(strtobool(with_visit)), enrich_fn=_enrich_origin) nb_results = len(results) @@ -233,7 +230,6 @@ query_params = {} query_params['offset'] = offset + limit query_params['limit'] = limit - query_params['regexp'] = regexp result['headers'] = { 'link-next': reverse('api-1-origin-search', diff --git a/swh/web/common/service.py b/swh/web/common/service.py --- a/swh/web/common/service.py +++ b/swh/web/common/service.py @@ -247,8 +247,7 @@ return map(converters.from_origin, origins) -def search_origin(url_pattern, offset=0, limit=50, regexp=False, - with_visit=False): +def search_origin(url_pattern, offset=0, limit=50, with_visit=False): """Search for origins whose urls contain a provided string pattern or match a provided regular expression. @@ -261,17 +260,15 @@ list of origin information as dict. """ - if not regexp: - # If the query is not a regexp, rewrite it as a regexp. - regexp = True - search_words = [re.escape(word) for word in url_pattern.split()] - if len(search_words) >= 7: - url_pattern = '.*'.join(search_words) - else: - pattern_parts = [] - for permut in itertools.permutations(search_words): - pattern_parts.append('.*'.join(permut)) - url_pattern = '|'.join(pattern_parts) + regexp = True + search_words = [re.escape(word) for word in url_pattern.split()] + if len(search_words) >= 7: + url_pattern = '.*'.join(search_words) + else: + pattern_parts = [] + for permut in itertools.permutations(search_words): + pattern_parts.append('.*'.join(permut)) + url_pattern = '|'.join(pattern_parts) origins = storage.origin_search(url_pattern, offset, limit, regexp, with_visit) diff --git a/swh/web/tests/api/views/test_origin.py b/swh/web/tests/api/views/test_origin.py --- a/swh/web/tests/api/views/test_origin.py +++ b/swh/web/tests/api/views/test_origin.py @@ -497,22 +497,6 @@ == {'https://github.com/memononen/libtess2'} -def test_api_origin_search_regexp(api_client): - expected_origins = { - 'https://github.com/memononen/libtess2', - 'repo_with_submodules' - } - - url = reverse('api-1-origin-search', - url_args={'url_pattern': '(repo|libtess)'}, - query_params={'limit': 10, - 'regexp': True}) - rv = api_client.get(url) - assert rv.status_code == 200, rv.data - assert rv['Content-Type'] == 'application/json' - assert {origin['url'] for origin in rv.data} == expected_origins - - @pytest.mark.parametrize('limit', [1, 2, 3, 10]) def test_api_origin_search_scroll(api_client, archive_data, limit): expected_origins = {