Пример #1
0
    def _SetValues(self, query, sphinx_results, db):
        """Used internally to set the facet terms and additional values in this facet.
        """
        # reset the facet values and stats
        self.results = utils.storage(time=0, total_found=0, error='', warning='', matches=[])
        
        # fetch the facet terms from the db
        db_fetch = DBFetch(db, self._sql_query, getter=lambda x: x['attrs']['@groupby'])
        hits = db_fetch.Fetch(sphinx_results)
        
        # let's get the stats from the results
        for k in self.results.keys():
            if k != 'matches':
                self.results[k] = hits[k]

        # finally let's setup the facet values
        for match in hits.matches:
            # get all virtual attributes
            value = dict((k, v) for k, v in match['attrs'].items() if k.startswith('@'))
            # get the facet term
	    if '@hit' in match: value['@term'] = match['@hit'][match['@hit'].keys()[-1]]
            # get the value of the grouping func
            value['@groupfunc'] = value.get('@groupfunc', value['@count'])
            # and whether the facet has been selected
            if '@term' in value: value['@selected'] = '@%s %s' % (self._sph_field, value['@term']) in query
            # append each value
            self.results.matches.append(value)
Пример #2
0
 def _InitResults(self):
     # the returning values
     self.results = utils.storage(time=0, total_found=0, error='', warning='', matches=[])
     self.query = ''