Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/archive.py
Show First 20 Lines • Show All 353 Lines • ▼ Show 20 Lines | ) -> Iterable[OriginMetadataInfo]: | ||||
Args: | Args: | ||||
fulltext: the string pattern to search for in origin metadata | fulltext: the string pattern to search for in origin metadata | ||||
limit: the maximum number of found origins to return | limit: the maximum number of found origins to return | ||||
Returns: | Returns: | ||||
Iterable of origin metadata information for existing origins | Iterable of origin metadata information for existing origins | ||||
""" | """ | ||||
results = [] | |||||
if search and config.get_config()["metadata_search_backend"] == "swh-search": | |||||
page_result = search.origin_search(metadata_pattern=fulltext, limit=limit,) | |||||
matches = idx_storage.origin_intrinsic_metadata_get( | |||||
[r["url"] for r in page_result.results] | |||||
) | |||||
else: | |||||
matches = idx_storage.origin_intrinsic_metadata_search_fulltext( | matches = idx_storage.origin_intrinsic_metadata_search_fulltext( | ||||
conjunction=[fulltext], limit=limit | conjunction=[fulltext], limit=limit | ||||
) | ) | ||||
matches = [match.to_dict() for match in matches] | matches = [match.to_dict() for match in matches] | ||||
results = [] | |||||
origins = storage.origin_get([match["id"] for match in matches]) | origins = storage.origin_get([match["id"] for match in matches]) | ||||
for origin, match in zip(origins, matches): | for origin, match in zip(origins, matches): | ||||
if not origin: | if not origin: | ||||
continue | continue | ||||
match["from_revision"] = hashutil.hash_to_hex(match["from_revision"]) | match["from_revision"] = hashutil.hash_to_hex(match["from_revision"]) | ||||
del match["id"] | del match["id"] | ||||
results.append(OriginMetadataInfo(url=origin.url, metadata=match)) | results.append(OriginMetadataInfo(url=origin.url, metadata=match)) | ||||
return results | return results | ||||
def lookup_origin_intrinsic_metadata(origin_url: str) -> Dict[str, Any]: | def lookup_origin_intrinsic_metadata(origin_url: str) -> Dict[str, Any]: | ||||
"""Return intrinsic metadata for origin whose origin matches given | """Return intrinsic metadata for origin whose origin matches given | ||||
origin. | origin. | ||||
Args: | Args: | ||||
▲ Show 20 Lines • Show All 999 Lines • Show Last 20 Lines |