def query(self, query): headers = {'Content-Type': 'application/json', 'Accept': 'text/plain'} parsedQuery = '' for key, value in query.items(): parsedQuery = '{1}:{2}&{0}'.format(parsedQuery, key, value) request = requests.get( '{0}/databases/{1}/indexes/{2}?query={3}'.format( self._client.url, self._client.database, self._indexId, parsedQuery ), headers=headers ) if request.status_code == 200: response = request.json() if 'TotalResults' in response: results = b.buncher({ "IsStale": response["IsStale"], "documents": []} ).bunch() for value in response["Results"]: results.documents.append( b.buncher(value).bunch() ) return results else: raise Exception( 'Query response unexpected Http: {0}'.format( request.status_code ) ) else: raise Exception( 'Error querying index Http :{0}'.format( request.status_code ) )
def load(self, documentIds): headers = {"Content-Type": "application/json", "Accept": "text/plain"} request = requests.post( '{0}/databases/{1}/queries'.format( self._client.url, self._client.database ), data=json.dumps(documentIds), headers=headers ) if request.status_code == 200: results = [] for value in request.json()["Results"]: results.append(b.buncher(value).bunch()) return results else: raise Exception( 'Error getting document Http :{0}'.format( request.status_code ) )