Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/db.py
Show First 20 Lines • Show All 1,017 Lines • ▼ Show 20 Lines | ): | ||||
) | ) | ||||
AND """ | AND """ | ||||
query += "url %s %%s " | query += "url %s %%s " | ||||
if not count: | if not count: | ||||
query += "ORDER BY id OFFSET %%s LIMIT %%s" | query += "ORDER BY id OFFSET %%s LIMIT %%s" | ||||
if not regexp: | if not regexp: | ||||
query = query % (origin_cols, "ILIKE") | query = query % (origin_cols, "ILIKE") | ||||
query_params = ("%" + url_pattern + "%", offset, limit) | query_params = (f"%{url_pattern}%", offset, limit) | ||||
else: | else: | ||||
query = query % (origin_cols, "~*") | query = query % (origin_cols, "~*") | ||||
query_params = (url_pattern, offset, limit) | query_params = (url_pattern, offset, limit) | ||||
if count: | if count: | ||||
query_params = (query_params[0],) | query_params = (query_params[0],) | ||||
cur.execute(query, query_params) | cur.execute(query, query_params) | ||||
def origin_search( | def origin_search( | ||||
self, url_pattern, offset=0, limit=50, regexp=False, with_visit=False, cur=None | self, | ||||
url_pattern: str, | |||||
offset: int = 0, | |||||
limit: int = 50, | |||||
regexp: bool = False, | |||||
with_visit: bool = False, | |||||
cur=None, | |||||
): | ): | ||||
"""Search for origins whose urls contain a provided string pattern | """Search for origins whose urls contain a provided string pattern | ||||
or match a provided regular expression. | or match a provided regular expression. | ||||
The search is performed in a case insensitive way. | The search is performed in a case insensitive way. | ||||
Args: | Args: | ||||
url_pattern (str): the string pattern to search for in origin urls | url_pattern: the string pattern to search for in origin urls | ||||
offset (int): number of found origins to skip before returning | offset: number of found origins to skip before returning | ||||
results | results | ||||
limit (int): the maximum number of found origins to return | limit: the maximum number of found origins to return | ||||
regexp (bool): if True, consider the provided pattern as a regular | regexp: if True, consider the provided pattern as a regular | ||||
expression and returns origins whose urls match it | expression and returns origins whose urls match it | ||||
with_visit (bool): if True, filter out origins with no visit | with_visit: if True, filter out origins with no visit | ||||
""" | """ | ||||
self._origin_query( | self._origin_query( | ||||
url_pattern, | url_pattern, | ||||
offset=offset, | offset=offset, | ||||
limit=limit, | limit=limit, | ||||
regexp=regexp, | regexp=regexp, | ||||
with_visit=with_visit, | with_visit=with_visit, | ||||
▲ Show 20 Lines • Show All 272 Lines • Show Last 20 Lines |