[docs]defquery(url:str,text:Optional[str]=None,user:Optional[str]=None,path:Optional[str]=None,after:Optional[int]=None,before:Optional[int]=None,number:int=100,on_truncation:Literal["message","warning","none"]="message")->List[Dict]:""" Query the metadata in the SewerRat backend based on free text, the owner, creation time, etc. This function does not require filesystem access. Args: url: String containing the URL to the SewerRat REST API. text: String containing a free-text query, following the syntax described `here <https://github.com/ArtifactDB/SewerRat#Using-a-human-readable-text-query-syntax>`_. If None, no filtering is applied based on the metadata text. user: String containing the name of the user who generated the metadata. If None, no filtering is applied based on the user. path: String containing any component of the path to the metadata file. If None, no filtering is applied based on the path. after: Integer containing a Unix time in seconds, where only files newer than ``after`` will be retained. If None, no filtering is applied to remove old files. before: Integer containing a Unix time in seconds, where only files older than ``before`` will be retained. If None, no filtering is applied to remove new files. number: Integer specifying the maximum number of results to return. on_truncation: String specifying the action to take when the number of search results is capped by ``number``. Returns: List of dictionaries where each inner dictionary corresponds to a metadata file and contains: - ``path``, a string containing the path to the file. - ``user``, the identity of the file owner. - ``time``, the Unix time of most recent file modification. - ``metadata``, a list representing the JSON contents of the file. """conditions=[]iftextisnotNone:conditions.append({"type":"text","text":text})ifuserisnotNone:conditions.append({"type":"user","user":user})ifpathisnotNone:conditions.append({"type":"path","path":path})ifafterisnotNone:conditions.append({"type":"time","time":int(after),"after":True})ifbeforeisnotNone:conditions.append({"type":"time","time":int(before)})iflen(conditions)>1:query={"type":"and","children":conditions}eliflen(conditions)==1:query=conditions[0]else:raiseValueError("at least one search filter must be present")ifon_truncation!="none":original_number=numbernumber+=1stub="/query?translate=true"collected=[]whilelen(collected)<number:res=requests.post(url+stub+"&limit="+str(number-len(collected)),json=query)ifres.status_code>=300:raiseut.format_error(res)payload=res.json()collected+=payload["results"]if"next"notinpayload:breakstub=payload["next"]ifon_truncation!="none":iflen(collected)>original_number:msg="truncated query results to the first "+str(original_number)+" matches"ifon_truncation=="warning":warnings.warn(msg)else:print(msg)collected=collected[:original_number]returncollected