(self, query)
Return all the results for a query
Return all the results for a query
Return all the results for a query
def search_all(self, query):
        """
        Return all the results for a query
        """
        sign = hmac.new(
            self.key.encode("utf-8"),
            query.encode("utf-8"),
            hashlib.sha256
        ).hexdigest()
        start = 0
        end = False
        results = {}
        while not end:
            res = self._query("/search/%s&id=%s&sign=%s&start=%i" % (query, self.user, sign, start))
            if res.status_code != 200:
                raise TotalHashError()
            else:
                root = ET.fromstring(res.text)
                if start == 0:
                    result = root.find('result')
                    results = {
                        'total': int(result.attrib['numFound']),
                        'results': [a.text for a in root.findall('.//result/doc/')]
                    }
                    start += len(results['results'])
                    if start >= results['total']:
                        return results
                else:
                    docs = root.findall('.//result/doc/')
                    for a in docs:
                        results['results'].append(a.text)
                    start += len(docs)
                    if start >= results['total']:
                        return results
def search_all ( self , query ) : sign = hmac . new ( self . key . encode ( "utf-8" ) , query . encode ( "utf-8" ) , hashlib . sha256 ) . hexdigest ( ) start = 0 end = False results = { } while not end : res = self . _query ( "/search/%s&id=%s&sign=%s&start=%i" % ( query , self . user , sign , start ) ) if res . status_code != 200 : raise TotalHashError ( ) else : root = ET . fromstring ( res . text ) if start == 0 : result = root . find ( 'result' ) results = { 'total' : int ( result . attrib [ 'numFound' ] ) , 'results' : [ a . text for a in root . findall ( './/result/doc/' ) ] } start += len ( results [ 'results' ] ) if start >= results [ 'total' ] : return results else : docs = root . findall ( './/result/doc/' ) for a in docs : results [ 'results' ] . append ( a . text ) start += len ( docs ) if start >= results [ 'total' ] : return results