Changeset View
Changeset View
Standalone View
Standalone View
swh/search/elasticsearch.py
Show First 20 Lines • Show All 239 Lines • ▼ Show 20 Lines | class ElasticSearch: | ||||
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, | ||||
nb_visit: int = None, | nb_visit: int = None, | ||||
last_visit_date: str = None, | |||||
page_token: Optional[str] = None, | page_token: Optional[str] = None, | ||||
limit: int = 50, | limit: int = 50, | ||||
) -> PagedResult[MinimalOriginDict]: | ) -> PagedResult[MinimalOriginDict]: | ||||
query_clauses: List[Dict[str, Any]] = [] | query_clauses: List[Dict[str, Any]] = [] | ||||
if url_pattern: | if url_pattern: | ||||
query_clauses.append( | query_clauses.append( | ||||
{ | { | ||||
Show All 39 Lines | ) -> PagedResult[MinimalOriginDict]: | ||||
raise ValueError( | raise ValueError( | ||||
"At least one of url_pattern and metadata_pattern must be provided." | "At least one of url_pattern and metadata_pattern must be provided." | ||||
) | ) | ||||
if with_visit: | if with_visit: | ||||
query_clauses.append({"term": {"has_visits": True,}}) | query_clauses.append({"term": {"has_visits": True,}}) | ||||
if nb_visit: | if nb_visit: | ||||
query_clauses.append({"term": {"nb_visit": nb_visit,}}) | query_clauses.append({"term": {"nb_visit": nb_visit,}}) | ||||
if last_visit_date: | |||||
query_clauses.append({"term": {"last_visit_date": last_visit_date,}}) | |||||
if visit_types is not None: | if visit_types is not None: | ||||
query_clauses.append({"terms": {"visit_types": visit_types}}) | query_clauses.append({"terms": {"visit_types": visit_types}}) | ||||
body = { | body = { | ||||
"query": { | "query": { | ||||
"bool": { | "bool": { | ||||
"must": query_clauses, | "must": query_clauses, | ||||
Show All 37 Lines |