Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/service.py
Show All 11 Lines | |||||
from swh.storage.algos import diff, revisions_walker | from swh.storage.algos import diff, revisions_walker | ||||
from swh.web.common import converters | from swh.web.common import converters | ||||
from swh.web.common import query | from swh.web.common import query | ||||
from swh.web.common.exc import NotFoundExc | from swh.web.common.exc import NotFoundExc | ||||
from swh.web.common.origin_visits import get_origin_visit | from swh.web.common.origin_visits import get_origin_visit | ||||
from swh.web import config | from swh.web import config | ||||
search = config.search() | |||||
storage = config.storage() | storage = config.storage() | ||||
vault = config.vault() | vault = config.vault() | ||||
idx_storage = config.indexer_storage() | idx_storage = config.indexer_storage() | ||||
MAX_LIMIT = 50 # Top limit the users can ask for | MAX_LIMIT = 50 # Top limit the users can ask for | ||||
▲ Show 20 Lines • Show All 208 Lines • ▼ Show 20 Lines | def lookup_origins(origin_from=1, origin_count=100): | ||||
Yields: | Yields: | ||||
origins information as dicts | origins information as dicts | ||||
""" | """ | ||||
origins = storage.origin_get_range(origin_from, origin_count) | origins = storage.origin_get_range(origin_from, origin_count) | ||||
return map(converters.from_origin, origins) | return map(converters.from_origin, origins) | ||||
def search_origin(url_pattern, offset=0, limit=50, regexp=False, | def search_origin(url_pattern, limit=50, scroll_token=None, with_visit=False): | ||||
with_visit=False): | |||||
"""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. | ||||
Args: | Args: | ||||
url_pattern: the string pattern to search for in origin urls | url_pattern: the string pattern to search for in origin urls | ||||
offset: number of found origins to skip before returning results | offset: number of found origins to skip before returning results | ||||
limit: the maximum number of found origins to return | limit: the maximum number of found origins to return | ||||
Returns: | Returns: | ||||
list of origin information as dict. | list of origin information as dict. | ||||
""" | """ | ||||
origins = storage.origin_search(url_pattern, offset, limit, regexp, | results = search.origin_search(url_pattern=url_pattern, count=limit, | ||||
with_visit) | scroll_token=scroll_token, | ||||
return map(converters.from_origin, origins) | with_visit=with_visit) | ||||
origins = map(converters.from_origin, results['results']) | |||||
return (origins, results['scroll_token']) | |||||
def search_origin_metadata(fulltext, limit=50): | def search_origin_metadata(fulltext, limit=50): | ||||
"""Search for origins whose metadata match a provided string pattern. | """Search for origins whose metadata match a provided string pattern. | ||||
Args: | Args: | ||||
fulltext: the string pattern to search for in origin metadata | fulltext: the string pattern to search for in origin metadata | ||||
offset: number of found origins to skip before returning results | offset: number of found origins to skip before returning results | ||||
▲ Show 20 Lines • Show All 847 Lines • Show Last 20 Lines |