Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, query="", query_parameters=None, start=0, includes=None, show_timings=False,
skip_duplicate_checking=False, **kwargs):
super(IndexQuery, self).__init__(query=query, query_parameters=query_parameters, start=start, **kwargs)
self.allow_multiple_index_entries_for_same_document_to_result_transformer = kwargs.get(
"allow_multiple_index_entries_for_same_document_to_result_transformer", False)
self.includes = includes if includes is not None else []
self.show_timings = show_timings
self.skip_duplicate_checking = skip_duplicate_checking
def _execute_query(self):
conventions = self.session.conventions
end_time = time.time() + self.timeout.seconds
query = self._build_query()
while True:
index_query = IndexQuery(query=query, query_parameters=self.query_parameters, start=self.start,
page_size=self.page_size, cutoff_etag=self.cutoff_etag,
wait_for_non_stale_results=self.wait_for_non_stale_results,
wait_for_non_stale_results_timeout=self.timeout)
query_command = QueryOperation(session=self.session, index_name=self.index_name,
index_query=index_query,
metadata_only=self.metadata_only).create_request()
response = self.session.requests_executor.execute(query_command)
if response is None:
return []
if response["IsStale"] and self.wait_for_non_stale_results:
if time.time() > end_time:
raise ErrorResponseException("The index is still stale after reached the timeout")
continue
break
def __init__(self, query_to_delete, options=None):
"""
@param query_to_delete: query that will be performed
:type IndexQuery or str
@param options: various Operation options e.g. AllowStale or MaxOpsPerSec
:type QueryOperationOptions
:rtype: dict of operation_id
"""
if not query_to_delete:
raise ValueError("Invalid query")
super(DeleteByQueryOperation, self).__init__()
if isinstance(query_to_delete, str):
query_to_delete = IndexQuery(query=query_to_delete)
self._query_to_delete = query_to_delete
self._options = options if options is not None else QueryOperationOptions()
def get_index_query(self):
return IndexQuery(query=self.__str__(), query_parameters=self.query_parameters, start=self.start,
page_size=self.page_size, cutoff_etag=self.cutoff_etag,
wait_for_non_stale_results=self.wait_for_non_stale_results,
wait_for_non_stale_results_timeout=self.timeout)
def create_request(self, server_node):
if not isinstance(self._query_to_update, IndexQuery):
raise ValueError("query must be IndexQuery Type")
self.url = server_node.url + "/databases/" + server_node.database + "/queries"
path = "?allowStale={0}&maxOpsPerSec={1}&details={2}".format(self._options.allow_stale,
"" if self._options.max_ops_per_sec is None
else self._options.max_ops_per_sec,
self._options.retrieve_details)
if self._options.stale_timeout is not None:
path += "&staleTimeout=" + str(self._options.stale_timeout)
self.url += path
self.data = {"Query": self._query_to_update.to_json()}
def __init__(self, query_to_update, options=None):
"""
@param query_to_update: query that will be performed
:type IndexQuery or str
@param options: various Operation options e.g. AllowStale or MaxOpsPerSec
:type QueryOperationOptions
@return: json
:rtype: dict of operation_id
"""
if query_to_update is None:
raise ValueError("Invalid query")
super(PatchByQueryOperation, self).__init__()
if isinstance(query_to_update, str):
query_to_update = IndexQuery(query=query_to_update)
self._query_to_update = query_to_update
if options is None:
options = QueryOperationOptions()
self._options = options