Changeset View
Changeset View
Standalone View
Standalone View
swh/search/interface.py
Show All 16 Lines | SORT_BY_OPTIONS = [ | ||||
"nb_visits", | "nb_visits", | ||||
"last_visit_date", | "last_visit_date", | ||||
"last_eventful_visit_date", | "last_eventful_visit_date", | ||||
"last_revision_date", | "last_revision_date", | ||||
"last_release_date", | "last_release_date", | ||||
] | ] | ||||
def get_expansion(field, sep=None): | |||||
METADATA_FIELDS = { | |||||
"licenses": ["intrinsic_metadata", "http://schema.org/license", "@id"], | |||||
"programming_languages": [ | |||||
"intrinsic_metadata", | |||||
"http://schema.org/programmingLanguage", | |||||
"@value", | |||||
], | |||||
"keywords": ["intrinsic_metadata", "http://schema.org/keywords", "@value",], | |||||
"descriptions": [ | |||||
"intrinsic_metadata", | |||||
"http://schema.org/description", | |||||
"@value", | |||||
], | |||||
} | |||||
if sep: | |||||
return sep.join(METADATA_FIELDS[field]) | |||||
return METADATA_FIELDS[field] | |||||
class MinimalOriginDict(TypedDict): | class MinimalOriginDict(TypedDict): | ||||
"""Mandatory keys of an :class:`OriginDict`""" | """Mandatory keys of an :class:`OriginDict`""" | ||||
url: str | url: str | ||||
class OriginDict(MinimalOriginDict, total=False): | class OriginDict(MinimalOriginDict, total=False): | ||||
"""Argument passed to :meth:`SearchInterface.origin_update`.""" | """Argument passed to :meth:`SearchInterface.origin_update`.""" | ||||
Show All 28 Lines | class SearchInterface: | ||||
@remote_api_endpoint("origin/search") | @remote_api_endpoint("origin/search") | ||||
def origin_search( | def origin_search( | ||||
self, | self, | ||||
*, | *, | ||||
url_pattern: Optional[str] = None, | url_pattern: Optional[str] = None, | ||||
metadata_pattern: Optional[str] = None, | metadata_pattern: Optional[str] = None, | ||||
with_visit: bool = False, | with_visit: bool = False, | ||||
visit_types: Optional[List[str]] = None, | visit_types: Optional[List[str]] = None, | ||||
page_token: Optional[str] = None, | |||||
min_nb_visits: int = 0, | min_nb_visits: int = 0, | ||||
min_last_visit_date: str = "", | min_last_visit_date: str = "", | ||||
min_last_eventful_visit_date: str = "", | min_last_eventful_visit_date: str = "", | ||||
min_last_revision_date: str = "", | min_last_revision_date: str = "", | ||||
min_last_release_date: str = "", | min_last_release_date: str = "", | ||||
programming_languages: List[str] = [], | programming_languages: Optional[List[str]] = None, | ||||
licenses: List[str] = [], | licenses: Optional[List[str]] = None, | ||||
sort_by: List[str] = [], | keywords: Optional[List[str]] = None, | ||||
sort_by: Optional[List[str]] = None, | |||||
page_token: Optional[str] = None, | |||||
limit: int = 50, | limit: int = 50, | ||||
) -> PagedResult[MinimalOriginDict]: | ) -> PagedResult[MinimalOriginDict]: | ||||
"""Searches for origins matching the `url_pattern`. | """Searches for origins matching the `url_pattern`. | ||||
Args: | Args: | ||||
url_pattern: Part of the URL to search for | url_pattern: Part of the URL to search for | ||||
metadata_pattern: Keywords to look for | |||||
(across all the fields of intrinsic_metadata) | |||||
with_visit: Whether origins with no visit are to be | with_visit: Whether origins with no visit are to be | ||||
filtered out | filtered out | ||||
visit_types: Only origins having any of the provided visit types | visit_types: Only origins having any of the provided visit types | ||||
(e.g. git, svn, pypi) will be returned | (e.g. git, svn, pypi) will be returned | ||||
page_token: Opaque value used for pagination | |||||
min_nb_visits: Filter origins that have number of visits >= | min_nb_visits: Filter origins that have number of visits >= | ||||
the provided value | the provided value | ||||
min_last_visit_date: Filter origins that have | min_last_visit_date: Filter origins that have | ||||
last_visit_date on or after the provided date(ISO format) | last_visit_date on or after the provided date(ISO format) | ||||
min_last_eventful_visit_date: Filter origins that have | min_last_eventful_visit_date: Filter origins that have | ||||
last_eventful_visit_date (eventful = snapshot_id changed) | last_eventful_visit_date (eventful = snapshot_id changed) | ||||
on or after the provided date(ISO format) | on or after the provided date(ISO format) | ||||
min_last_revision_date: Filter origins that have | min_last_revision_date: Filter origins that have | ||||
last_revision_date on or after the provided date(ISO format) | last_revision_date on or after the provided date(ISO format) | ||||
min_last_release_date: Filter origins that have | min_last_release_date: Filter origins that have | ||||
last_release_date on or after the provided date(ISO format) | last_release_date on or after the provided date(ISO format) | ||||
licenses: Filter origins with licenses present in the given list | |||||
(based on instrinsic_metadata) | |||||
programming_languages: Filter origins with programming languages | programming_languages: Filter origins with programming languages | ||||
present in the given list (based on instrinsic_metadata) | present in the given list (based on instrinsic_metadata) | ||||
licenses: Filter origins with licenses present in the given list | |||||
(based on instrinsic_metadata) | |||||
keywords: Filter origins having description/keywords | |||||
(extracted from instrinsic_metadata) that match given values | |||||
sort_by: Sort results based on a list of fields mentioned in SORT_BY_OPTIONS | sort_by: Sort results based on a list of fields mentioned in SORT_BY_OPTIONS | ||||
(nb_visits,last_visit_date, last_eventful_visit_date, | (nb_visits,last_visit_date, last_eventful_visit_date, | ||||
last_revision_date, last_release_date). | last_revision_date, last_release_date). | ||||
Return results in descending order if "-" is present at the beginning | Return results in descending order if "-" is present at the beginning | ||||
otherwise in ascending order. | otherwise in ascending order. | ||||
page_token: Opaque value used for pagination | |||||
limit: number of results to return | limit: number of results to return | ||||
Returns: | Returns: | ||||
PagedResult of origin dicts matching the search criteria. If next_page_token | PagedResult of origin dicts matching the search criteria. If next_page_token | ||||
is None, there is no longer data to retrieve. | is None, there is no longer data to retrieve. | ||||
""" | """ | ||||
... | ... |