def suggest_terms(self, fields, prefix, handler='terms', **kwargs):
        """
        Accepts a list of field names and a prefix

        Returns a dictionary keyed on field name containing a list of
        ``(term, count)`` pairs

        Requires Solr 1.4+.
        """
        params = {
            'terms.fl': fields,
            'terms.prefix': prefix,
        }
        params.update(kwargs)
        response = self._suggest_terms(params, handler=handler)
        result = self.decoder.decode(response)
        terms = result.get("terms", {})
        res = {}

        # in Solr 1.x the value of terms is a flat list:
        #   ["field_name", ["dance",23,"dancers",10,"dancing",8,"dancer",6]]
        #
        # in Solr 3.x the value of terms is a dict:
        #   {"field_name": ["dance",23,"dancers",10,"dancing",8,"dancer",6]}
        if isinstance(terms, (list, tuple)):
            terms = dict(zip(terms[0::2], terms[1::2]))

        for field, values in terms.items():
            tmp = []

            while values:
                tmp.append((values.pop(0), values.pop(0)))

            res[field] = tmp

        self.log.debug("Found '%d' Term suggestions results.", sum(len(j) for i, j in res.items()))
        return res
def suggest_terms ( self , fields , prefix , handler = 'terms' , ** kwargs ) : params = { 'terms.fl' : fields , 'terms.prefix' : prefix , } params . update ( kwargs ) response = self . _suggest_terms ( params , handler = handler ) result = self . decoder . decode ( response ) terms = result . get ( "terms" , { } ) res = { } if isinstance ( terms , ( list , tuple ) ) : terms = dict ( zip ( terms [ 0 : : 2 ] , terms [ 1 : : 2 ] ) ) for field , values in terms . items ( ) : tmp = [ ] while values : tmp . append ( ( values . pop ( 0 ) , values . pop ( 0 ) ) ) res [ field ] = tmp self . log . debug ( "Found '%d' Term suggestions results." , sum ( len ( j ) for i , j in res . items ( ) ) ) return res
Accepts a list of field names and a prefix

        Returns a dictionary keyed on field name containing a list of
        ``(term, count)`` pairs

        Requires Solr 1.4+.