Changeset View
Changeset View
Standalone View
Standalone View
swh/search/interface.py
Show All 13 Lines | |||||
PagedResult = CorePagedResult[TResult, str] | PagedResult = CorePagedResult[TResult, str] | ||||
SORT_BY_OPTIONS = [ | 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", | ||||
"date_created", | |||||
"date_modified", | |||||
"date_published", | |||||
] | ] | ||||
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`.""" | ||||
visit_types: List[str] | visit_types: List[str] | ||||
has_visits: bool | has_visits: bool | ||||
class SearchInterface: | class SearchInterface: | ||||
@remote_api_endpoint("check") | @remote_api_endpoint("check") | ||||
def check(self): | def check(self): | ||||
"""Dedicated method to execute some specific check per implementation. | """Dedicated method to execute some specific check per implementation. | ||||
""" | """ | ||||
... | ... | ||||
@remote_api_endpoint("flush") | @remote_api_endpoint("flush") | ||||
def flush(self) -> None: | def flush(self) -> None: | ||||
"""Blocks until all previous calls to _update() are completely | """Blocks until all previous calls to _update() are completely | ||||
applied. | applied. | ||||
""" | """ | ||||
... | ... | ||||
vlorentz: Can you move this to a new module, instead of the "interface"? | |||||
Done Inline ActionsMoved to utils.py ? KShivendu: Moved to `utils.py` ? | |||||
@remote_api_endpoint("origin/update") | @remote_api_endpoint("origin/update") | ||||
def origin_update(self, documents: Iterable[OriginDict]) -> None: | def origin_update(self, documents: Iterable[OriginDict]) -> None: | ||||
"""Persist documents to the search backend. | """Persist documents to the search backend. | ||||
""" | """ | ||||
... | ... | ||||
@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, | ||||
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 = "", | ||||
min_date_created: str = "", | |||||
min_date_modified: str = "", | |||||
min_date_published: str = "", | |||||
programming_languages: Optional[List[str]] = None, | programming_languages: Optional[List[str]] = None, | ||||
Not Done Inline Actionser, sorry for not noticing sooner, but these should be datetime.datetime, not str. Can you change this in the next diff? vlorentz: er, sorry for not noticing sooner, but these should be `datetime.datetime`, not `str`. Can you… | |||||
Done Inline ActionsSure. KShivendu: Sure. | |||||
licenses: Optional[List[str]] = None, | licenses: Optional[List[str]] = None, | ||||
keywords: Optional[List[str]] = None, | keywords: Optional[List[str]] = None, | ||||
sort_by: Optional[List[str]] = None, | sort_by: Optional[List[str]] = None, | ||||
page_token: Optional[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`. | ||||
Show All 11 Lines | ) -> PagedResult[MinimalOriginDict]: | ||||
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) | ||||
min_date_created: Filter origins that have date_created | |||||
from intrinsic_metadata on or after the provided date | |||||
min_date_modified: Filter origins that have date_modified | |||||
from intrinsic_metadata on or after the provided date | |||||
min_date_published: Filter origins that have date_published | |||||
from intrinsic_metadata on or after the provided date | |||||
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 | licenses: Filter origins with licenses present in the given list | ||||
(based on instrinsic_metadata) | (based on instrinsic_metadata) | ||||
keywords: Filter origins having description/keywords | keywords: Filter origins having description/keywords | ||||
(extracted from instrinsic_metadata) that match given values | (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, | ||||
Show All 12 Lines |
Can you move this to a new module, instead of the "interface"?