Пример #1
0
 def __str__(self):
     """A string representation of these hits showing the number of results,
     time taken and the hits retrieved.
     """
     s = 'matches: (%(total)i/%(total_found)i documents in %(time)s sec.)\n' % self
     for i, match in enumerate(self['matches']):
         s += '%s. ' % (i + 1)
         s += 'document=%(id)s, weight=%(weight)s\n' % match
         s += ', '.join('%s=%s' % (k, utils._unicode(v))
             for k, v in match['attrs'].items()) + '\n'
         for k, v in match['@hit'].items():
             if isinstance(v, list):
                 v = ', '.join(v)
             s += '\t%s=%s\n' % (k, utils._unicode(v))
     s += '\nwords:\n'
     for i, word in enumerate(self['words']):
         s += '%s. ' % (i + 1)
         s += '"%(word)s": %(docs)s documents, %(hits)s hits\n' % word
     return s.encode('utf-8')
Пример #2
0
 def __str__(self):
     """A string representation of these hits showing the number of results,
     time taken and the hits retrieved.
     """
     s = 'matches: (%(total)i/%(total_found)i documents in %(time)s sec.)\n' % self
     for i, match in enumerate(self['matches']):
         s += '%s. ' % (i + 1)
         s += 'document=%(id)s, weight=%(weight)s\n' % match
         s += ', '.join('%s=%s' % (k, utils._unicode(v))
                        for k, v in match['attrs'].items()) + '\n'
         for k, v in match['@hit'].items():
             if isinstance(v, list):
                 v = ', '.join(v)
             s += '\t%s=%s\n' % (k, utils._unicode(v))
     s += '\nwords:\n'
     for i, word in enumerate(self['words']):
         s += '%s. ' % (i + 1)
         s += '"%(word)s": %(docs)s documents, %(hits)s hits\n' % word
     return s.encode('utf-8')
Пример #3
0
 def __iter__(self):
     for sql in self.sql_features:
         c = self.db.cursor()
         logger.info('SQL: %s', sql)
         c.execute(sql)
         for id, feat in c:
             if isinstance(feat, int) or isinstance(feat, long):
                 feat = utils._unicode(feat)
             yield id, feat
         c.close()
     self.db.close()
Пример #4
0
 def __iter__(self):
     for sql in self.sql_features:
         c = self.db.cursor()
         logger.info('SQL: %s', sql)
         c.execute(sql)
         for id, feat in c:
             if isinstance(feat, int) or isinstance(feat, long):
                 feat = utils._unicode(feat)
             yield id, feat
         c.close()
     self.db.close()
Пример #5
0
    def __call__(self, hits):
        words = getattr(self._cl.query, 'sphinx', self._cl.query)

        docs = []
        for match in hits.matches:
            docs.extend([utils._unicode(match['@hit'][f]) for f in self._on_fields])

        all_excerpts = self._cl.BuildExcerpts(docs, self._index, words, self._opts)
        print all_excerpts
        for match, excerpts in zip(hits.matches, utils.group(all_excerpts, len(self._on_fields))):
            for f, excerpt in zip(self._on_fields, excerpts):
                match['@hit'][f + self._suffix] = excerpt or match['@hit'][f]
Пример #6
0
    def __call__(self, hits):
        words = getattr(self._cl.query, 'sphinx', self._cl.query)

        docs = []
        for match in hits.matches:
            docs.extend(
                [utils._unicode(match['@hit'][f]) for f in self._on_fields])

        all_excerpts = self._cl.BuildExcerpts(docs, self._index, words,
                                              self._opts)
        print all_excerpts
        for match, excerpts in zip(
                hits.matches, utils.group(all_excerpts, len(self._on_fields))):
            for f, excerpt in zip(self._on_fields, excerpts):
                match['@hit'][f + self._suffix] = excerpt or match['@hit'][f]
Пример #7
0
 def add(self, id, feat):
     """ Adds the given (id, feature) to the index.
     
     The id must an int and the feature must be a unique string representation
     of the feature. The feature is expected to be unicode or utf8 encoded.
     
     This method does not check whether (id, feature) has already been inserted
     to the index.
     """
     if not self._check_input(id, feat):
         return
     feat = utils._unicode(feat)
     if id not in self.ids:
         x = len(self.ids)
         self.ids[id] = x
         self.fids.write('%s\n' % id)
     if feat not in self.fts:
         y = len(self.fts)
         self.fts[feat] = y
         self.ffts.write('%s\n' % feat)
     (x, y) = (self.ids[id], self.fts[feat])
     if not self._in_coo(x, y):
         self.fxco.write('%s\n' % x)
         self.fyco.write('%s\n' % y)
Пример #8
0
 def add(self, id, feat):
     """ Adds the given (id, feature) to the index.
     
     The id must an int and the feature must be a unique string representation
     of the feature. The feature is expected to be unicode or utf8 encoded.
     
     This method does not check whether (id, feature) has already been inserted
     to the index.
     """
     if not self._check_input(id, feat):
         return
     feat = utils._unicode(feat)
     if id not in self.ids:
         x = len(self.ids)
         self.ids[id] = x
         self.fids.write('%s\n' % id)
     if feat not in self.fts:
         y = len(self.fts)
         self.fts[feat] = y
         self.ffts.write('%s\n' % feat)
     (x, y) = (self.ids[id], self.fts[feat])
     if not self._in_coo(x, y):
         self.fxco.write('%s\n' % x)
         self.fyco.write('%s\n' % y)